title: Ignoring null values in in a postgresql rank() window function
body: <p>I am writing a SQL query using PostgreSQL that needs to rank people that "arrive" at some location. Not everyone arrives however. I am using a <code>rank()</code> window function to generate arrival ranks, but in the places where the arrival time is null, rather than returning a null rank, the <code>rank()</code> aggregate function just treats them as if they arrived after everyone else. What I want to happen is that these no-shows get a rank of <code>NULL</code> instead of this imputed rank.  </p>
  
  <p>Here is an example. Suppose I have a table <code>dinner_show_up</code> that looks like this: </p>
  
  <pre><code> | Person | arrival_time | Restaurant |
   +--------+--------------+------------+
   | Dave   |     7        | in_and_out |
   | Mike   |     2        | in_and_out | 
   | Bob    |   NULL       | in_and_out | 
  </code></pre>
  
  <p>Bob never shows up. The query I'm writing would be: </p>
  
  <pre><code>select Person, 
         rank() over (partition by Restaurant order by arrival_time asc) 
                 as arrival_rank
  from dinner_show_up; 
  </code></pre>
  
  <p>And the result will be</p>
  
  <pre><code> | Person | arrival_rank | 
   +--------+--------------+
   | Dave   |     2        | 
   | Mike   |     1        | 
   | Bob    |     3        |  
  </code></pre>
  
  <p>What I want to happen instead is this: </p>
  
  <pre><code> | Person | arrival_rank | 
   +--------+--------------+
   | Dave   |     2        | 
   | Mike   |     1        | 
   | Bob    |     NULL     |  
  </code></pre>