title: Convert VARCHAR to INT/NUMBER in WHERE clause
body: <p>I have a table <code>ACTIVITIES_T</code> in a PostgreSQL DB. <code>ACTIVITY_CODE</code> is a <code>VARCHAR</code> column:</p>
  
  <pre><code>ID (INT)  |  ACTIVITY_CODE (VARCHAR) | ACTIVITY_TEXT (VARCHAR)
  -------------------------------------------------------------
  ..            ..                      ..
  7             10012                   ..
  8             10013                   ..
  9             10014                   ..
  10            10015                   ..
  11            SPECIAL                 ..
  </code></pre>
  
  <p>I have a contiguous block of pseudo-numbers, <code>10012..10015</code>, that I need to select with the <code>BETWEEN a AND b</code> operator, or <code>&gt;= n1 and &lt;= n2</code>.</p>
  
  <p>But not all entries in <code>ACTIVITY_CODE</code> are numeric values.<br>
  I tried this:</p>
  
  <pre><code>select * from activities_t  where activity_code::int &gt;= 10012 and 
                                    activity_code::int &lt;= 10015;
  </code></pre>
  
  <p>but got the error</p>
  
  <blockquote>
  <pre><code>ERROR:  invalid input syntax for integer: SPECIAL
  </code></pre>
  </blockquote>