I've got a postgres column 'data' which is jsonb in this format:
{
'tags': ['friend','enemy','frenemy']
... // other data
}
Say I want to select all rows that are tagged either 'enemy' or 'frenemy', how can i do that?
I know I can select on a single tag with
SELECT * FROM people WHERE people.data->'tags' ? 'enemy'
I should be using @> ANY
, but can't quite figure out the syntax for the to make it work.
I found the answer tucked away in this SO question.
SELECT * FROM people WHERE people.data->'tags' ?| ARRAY['enemy','frenemy']
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With