title: How to group result by array column in Postgres?
body: <p>I have such a table </p>
  
  <pre><code>id SERIAL,
  user_id INT,
  community_id INT[],
  </code></pre>
  
  <p>The table filled this way:</p>
  
  <pre><code>id | user_id | community_id 
  1  |  1      |   {2, 4}
  2  |  5      |   {2, 5} 
  3  |  10     |   {2, 4}
  </code></pre>
  
  <p>I'd like to get COUNT of users which each community has, community_id is array cuz user can be in several community at the same time.</p>
  
  <p>The query should be simple as:</p>
  
  <pre><code>SELECT community_id, COUNT(user_id) FROM tbl GROUP BY community_id
  </code></pre>
  
  <p>The result should be like this:</p>
  
  <pre><code>community_id  | user_count
  2             |  3
  4             |  2
  5             |  1
  </code></pre>
  
  <p>I do not know how to <code>GROUP BY</code> array column. Can anybody help me ? </p>