I'm trying to find which of the jsonb keys are the most popular ones in my data field. I was able to get names of all keys with this query:
select jsonb_object_keys(data) as key
from client
group by key;
When I try to add a count like I normally do:
select jsonb_object_keys(data) as key, count(jsonb_object_keys(data))
from client
group by key;
I receive this error:
ERROR: aggregate function calls cannot contain set-returning function calls
Is there a way to count distinct keys of jsonb object?
Sample data:
data
{"a": "xyz"}
{"b": "assa", "c": "134323"}
{"c": "123"}
{"c": "12324", "a": "xysaz"}
Desired output:
key count(key)
a 2
b 1
c 3