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