I have a JSONB column in a Postgres database. I'm storing an array of JSON objects, each with a single key-value pair. I'm sure I could have designed this better, but for now I'm stuck with this.
id | reviews
------------------
1 | [{"apple": "delicious"}, {"kiwi": "not-delicious"}]
2 | [{"orange": "not-delicious"}, {"pair": "not-delicious"}]
3 | [{"grapes": "delicious"}, {"strawberry": "not-delicious"}, {"carrot": "delicious"}]
Suppose this table is called tasks. While the keys in each of these objects are not predictable, the values are. For each row, I'd like to know the number of "delicious" and number of "not-delicious" values in the reviews array.
Edit for clarification:
I'm looking for the delicious/not-delicious counts for each id/row in the above table. Sample desired output:
id | delicious | not_delicious
-------------------------------
1 | 1 | 1
2 | 0 | 2
3 | 2 | 1