title: Querying a Postgres array of integers in Rails
body: <p>my model has a pg array which I use to store integers</p>
  
  <p>Querying using the methods I found from other questions yields errors or gives empty results</p>
  
  <pre><code>MyModel.where("? = ANY (myarray)", 42)
  </code></pre>
  
  <p>gives</p>
  
  <pre><code>PG::UndefinedFunction: ERROR:  operator does not exist: integer = text
  </code></pre>
  
  <p>and</p>
  
  <pre><code> MyModel.where("myarray @&gt; '{?}'", 42)
  </code></pre>
  
  <p>gives an empty results, yet I do have a model with 42 as one of the ints in the array</p>
  
  <pre><code>#&lt;MyModel:0x007f9a77dd5608&gt; {
                  :id =&gt; 170,
        :myarray =&gt; [
      [0] 42,
      [1] 43,
      [2] 58,
      [3] 61,
      [4] 63
    ]
  </code></pre>
  
  <p>Is there a special way to query integers(or floats) within a postgres array in Rails?</p>
  
  <p>the migration</p>
  
  <pre><code>class AddMyarrayToMyModel &lt; ActiveRecord::Migration
    def change
      add_column :my_models, :myarray, :integer, array: true, default: []
      add_index  :my_models, :myarray, using: 'gin'
    end
  end
  </code></pre>
  
  <p>and schema</p>
  
  <pre><code>t.integer  "myarray",                 default: [],              array: true
  </code></pre>