title: how to group by a number of ids in a postgres array
body: <p>I am trying to select a row based upon a count of the nubmer of items in a Postgres array (represented as a text field in Postgres 9.4) and be able to select / group in Rails 4.2</p>
  
  <p>I have the following tables:</p>
  
  <pre><code> queryable_id | liked_count | users_who_like_ids 
  --------------+-------------+--------------------
           2376 |           3 | {1,80,78,101, 188}
          18771 |           1 | {78,101, 123,125}
           1790 |           1 | {78}
           2257 |           1 | {78}
  </code></pre>
  
  <p>For example, I'd like to say select the and order by user_who_like_ids like </p>
  
  <pre><code>select * from items group by count(users_who_like_ids) where users_who_like_ids include (78,123,125)
  </code></pre>
  
  <p>How would I make this query? Would this type of query be supported in rails?</p>
  
  <h3>edit 1</h3>
  
  <p>here is the users_who_like_ids </p>
  
  <pre><code> users_who_like_ids      | text[]                      | default '{}'::text[]
  </code></pre>
  
  <h3>edit 2</h3>
  
  <p>It looks like this kinda works:</p>
  
  <pre><code>select queryable_id, liked_count, users_who_like_ids  from  queryables where users_who_like_ids  @&gt; ARRAY['1','80'];
  </code></pre>
  
  <p>but this requires both 1 and 80</p>