title: Rails: Cast string field to integer in where clause
body: <p>In a <code>postgres</code> database I have a string field <code>code</code> in <code>orders</code> table. The field contains values like 'COA-38-A', 'EFILLDIRT' and 'HE60LS-A'. There is a form on UI to filter orders based on <code>code</code> and only integer values are allowed in the field.</p>
  
  <p>The query should filter the orders by integer values in the <code>code</code> field i.e if 30 is entered, the query should return orders with code 'COA-38-A' and 'HE60LS-A' because the query contains <code>&gt;=</code></p>
  
  <p>I tried adding <code>::integer</code> in the query:</p>
  
  <pre><code>Order.where('code::integer &gt;= ?', params[:code])
  </code></pre>
  
  <p>but got the following error:</p>
  
  <pre><code>PG::InvalidTextRepresentation: ERROR:  invalid input syntax for integer
  </code></pre>
  
  <p>Is there any way to filter by only integer values?</p>