I have data shaped like this: arrays of objects in a jsonb column in postgres
| id | data |
|---|---|
| 1 | [{"a":3, "b":"green"} ,{"a":5, "b":"blue"}] |
| 2 | [{"a":3, "b":"red"} ,{"a":5, "b":"yellow"}] |
| 3 | [{"a":3, "b":"orange"} ,{"a":5, "b":"blue"}] |
I am trying to select the rows where b is either "green" or "yellow"
I know I can unroll the data using jsonb_array_elements to get all the b values
select jsonb_array_elements(data) ->> 'b' from table
but I am failing to use that in a where query like this
select * from table where jsonb_array_elements(data) ->> 'b' && ARRAY["green","yellow"]::varchar[]
(not working "set-returning functions are not allowed in WHERE")