title: dense_rank() order by and nulls - how to make it treat them as bottom of the ranking?
body: <p>I am using Postgresql version 9.1.9:</p>
  
  <pre><code>select version();
  "PostgreSQL 9.1.9 on armv7l-unknown-linux-gnueabihf,
   compiled by gcc (Debian 4.6.3-14+rpi1) 4.6.3, 32-bit"
  </code></pre>
  
  <p>and I have a simple table (called Test) that has a single nullable <code>bigint</code> column (called A).  The table has the following data:</p>
  
  <pre><code>NULL
  1
  2
  </code></pre>
  
  <p>Now I want to create a dense ranking (therefore using the <a href="http://www.postgresql.org/docs/8.4/static/functions-window.html" rel="nofollow">dense_rank()</a> function) so I do the following query:</p>
  
  <pre><code>select "A", dense_rank() over (order by "A" desc) from public."Test"
  </code></pre>
  
  <p>This returns:</p>
  
  <pre><code>NULL,1
  2,2
  1,3
  </code></pre>
  
  <p>Interestingly if I set up exactly the same thing in SQL Server 2008 R2 and run the same query it returns:</p>
  
  <pre><code>2,1
  1,2
  NULL,3
  </code></pre>
  
  <p>So, I am interested in who is correct but, more practically, what I want is the SQL Server behavior so, <strong>how can I make PostgreSQL treat the null as bottom of the ranking</strong>?</p>
  
  <p>(i.e. sort NULLS as smaller than any value)</p>
  
  <p>I noticed this on the dense_rank page, but it is not talking specifically about this function, but perhaps it is a clue?</p>
  
  <blockquote>
    <p>Note: The SQL standard defines a RESPECT NULLS or IGNORE NULLS option
    for lead, lag, first_value, last_value, and nth_value. This is not
    implemented in PostgreSQL: the behavior is always the same as the
    standard's default, namely RESPECT NULLS. Likewise, the standard's
    FROM FIRST or FROM LAST option for nth_value is not implemented: only
    the default FROM FIRST behavior is supported. (You can achieve the
    result of FROM LAST by reversing the ORDER BY ordering.)</p>
  </blockquote>