title: Referring to dynamic columns in a postgres query?
body: <p>Let's say I have something like this:</p>
  
  <pre><code>select sum(points) as total_points
  from sometable
  where total_points &gt; 25
  group by username
  </code></pre>
  
  <p>I am unable to refer to <code>total_points</code> in the where clause because I get the following error: <code>ERROR:  column "total_points" does not exist</code>. In this case I'd have no problem rewriting <code>sum(points)</code> in the where clause, but I'd like some way of doing what I have above. </p>
  
  <ul>
  <li>Is there any way to store the result in a variable <em>without</em> using a stored procedure?</li>
  <li>If I <em>do</em> rewrite <code>sum(points)</code> in the where clause, is postgres smart enough to not recalculate it?</li>
  </ul>