title: SQL Error when I use distinct order by upper/lower
body: <p>This does not work in postgres 8.4:</p>
  
  <pre><code>SELECT DISTINCT col1 FROM mytable
    ORDER BY UPPER(col1);
  </code></pre>
  
  <p>but this works:</p>
  
  <pre><code>SELECT DISTINCT col1 FROM mytable
    ORDER BY col1;
  </code></pre>
  
  <p>I know it might be bit confusing for the database whether to apply DISTINCT first and then UPPER or first convert to UPPER and then apply DISTINCT. Based on order how it applies one may get different result. Not sure if SQL standard says anything in this regards.</p>
  
  <p>Any help will be highly appreciated.</p>