Reputation: 1121
For example if i have
colA
{"a" : 1, "b": 2}
{"b" : 3}
{}
I want my result to be:
key, count
a, 1
b, 2
Upvotes: 0
Views: 45
Reputation:
If you don't need to deal with nested json structures, you can use jsonb_object_keys
to iterate over all keys:
select x.ky, count(*)
from the_table t
cross join jsonb_object_keys(t.col_a) as x(ky)
group by x.ky
order by x.ky;
Upvotes: 1