title: Postgres GROUP BY on jsonb inner field
body: <p>I am using Postgresql 9.4 and have a table <code>test</code>, with <code>id::int</code> and <code>content::jsonb</code>, as follows:</p>
  
  
  
  <pre class="lang-sql prettyprint-override"><code> id |     content
  ----+-----------------
    1 | {"a": {"b": 1}}
    2 | {"a": {"b": 1}}
    3 | {"a": {"b": 2}}
    4 | {"a": {"c": 1}}
  </code></pre>
  
  <p>How do I <code>GROUP BY</code> on an inner field in the <code>content</code> column and return each group as an array? Specifically, the results I am looking for are:</p>
  
  <pre class="lang-sql prettyprint-override"><code>             content
  ---------------------------------
  [{"a": {"b": 1}},{"a": {"b": 1}}]
  [{"a": {"b": 2}}]
  (2 rows)
  </code></pre>
  
  <p>Trying:</p>
  
  <pre class="lang-sql prettyprint-override"><code>SELECT json_agg(content) as content FROM test GROUP BY content -&gt;&gt; '{a,b}';
  </code></pre>
  
  <p>Yields:</p>
  
  <pre class="lang-sql prettyprint-override"><code>                               content
  ----------------------------------------------------------------------
  [{"a": {"b": 1}}, {"a": {"b": 1}}, {"a": {"b": 2}}, {"a": {"c": 1}}]
  (1 row)
  </code></pre>