I have a column with json/jsonb data. Database is postgresql.
column data sample
x
{"postId": "p522", "groupId": "g11", }
{"postId": "p5ds", "groupId": "g234", }
{"postId": "p5cz", "groupId": "g597", }
I am trying to search as an array of data from json/jsonb column.
What’s best or right way to do it?
SELECT * FROM column_name
WHERE
-- How i can do, similar to this?
data #> '{groupId}' IN ('g11', 'g597')
-- this works but only for single. I am trying to find by array.
meta @> '{"groupId": "g597"}'
Advertisement
Answer
Solved:
SELECT * FROM column_name
WHERE meta ->> 'groupId' IN ('g11', 'g597')