How can I select the rows in a table having a jsonb array that has elements with a specific property ?
Eg: If the jsonb is the following
{ "list" : [
{"name": "John", "money": 100},
{"name": "Dan", "money": 900}
]
}
How can I select the rows having at least one element with name 'Dan' in the array ? I tried with:
select jsonb_pretty(data) from table where data -> 'list' @> '{"name": "Dan"}';
but id does not return any rows.
SELECT jsonb_pretty(data) FROM table WHERE data -> 'list' @> '[{"name": "Dan"}]'?