Use jsonb_array_elements to convert jsonb array to set (queriable similar to normal table) then we can use where x::text = 'null' to match the null value.
Examples:
=> select x->'id' as id
from jsonb_array_elements(
'[{"id": 4, "val": [null,1,null]},
{"id": 2, "val": [3]}]'::jsonb
) as x,
jsonb_array_elements(x->'val') as y
where y::text = 'null';
id
----
4
4
(2 rows)
=> select x->'id' as id
from jsonb_array_elements(
'[{"id": 4, "val": [null,1,null]},
{"id": 2, "val": [3]}]'::jsonb
) as x,
jsonb_array_elements(x->'val') as y
group by x->'id'
having count(x) filter (where y::text = 'null') > 1;
id
----------
4
(1 row)
Adapted from: https://dba.stackexchange.com/a/257799
No comments:
Post a Comment