Is possible to look for a given value at any key in a JSONB column in Postgres? In the documentation I can't see any example.
Example value at a JSONB
column:
{
a: 1,
b: 2,
c: 3
}
I want to find all records that have 1
as a value anywhere. NOTE: there may be other keys than a, b, c
unknown at the moment.
use value of jsonb_each_text
, sample based on previous sample of McNets,:
t=# select * from json_test join jsonb_each_text(json_test.data) e on true
where e.value = '1';
id | data | key | value
----+--------------------------------------+-----+-------
1 | {"a": 1} | a | 1
3 | {"a": 1, "b": {"c": "d", "e": true}} | a | 1
(2 rows)
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