title: Window function to select the most recent non-null value in Postgresql doesn't work
body: <p>I have a simple dataset like this:</p>
  
  <pre><code>CREATE TABLE test (ts timestamp, email varchar, title varchar, hobby varchar);
  
  insert into test values
  ('2017-01-01', 'me@me.com', 'blah', null),
  ('2017-01-02', 'me@me.com', null, 'expected hobby'),
  ('2017-01-03', 'me@me.com', 'expected title', null),
  ('2017-01-04', 'me@me.com', null, null);
  </code></pre>
  
  <p>And I'd like to select the most recent non-null value of title and hobby per email, using a window function. These are 'expected title' and 'expected hobby'. I'm trying this:</p>
  
  <pre><code>SELECT DISTINCT
      email,
      first_value(title) OVER (partition by email order by ts desc nulls last),
      first_value(hobby) OVER (partition by email order by ts desc nulls last)
  from test
  </code></pre>
  
  <p>But it doesn't seem to work. Here's a sql fiddle: <a href="http://sqlfiddle.com/#!17/6d681/2" rel="nofollow noreferrer">http://sqlfiddle.com/#!17/6d681/2</a></p>
  
  <p>Any idea why?</p>