M
M
Maxim Tarabrin2018-02-21 18:04:36
PostgreSQL
Maxim Tarabrin, 2018-02-21 18:04:36

How to pull data by key value in JSONB field?

There is some JSONB field. Here I need to pull out all the records, where is a certain parameter 'product_id' in (1,2,3,4,5,6,7,8,9,10)?
If I needed to pull out on the field that I would make request:
SELECT * FROM billing WHERE product_id IN (1,2,3,4,5,6);
What if the field is jsonb? and there are a lot of parameters

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2018-02-21
@padr1no

SELECT *
FROM table_name
WHERE (column_name->>'product_id')::integer IN (1,2,3,4,5,6,7,8,9,10)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question