title: PostgreSQL aggregate or window function to return just the last value
body: <p>I'm using an aggregate function with the OVER clause in PostgreSQL 9.1 and I want to return just the last row for each window. The <code>last_value()</code> window function sounds like it might do what I want - but it doesn't. It returns a row for each row in the window, whereas I want just one row per window</p>
  
  <p>A simplified example:</p>
  
  <pre><code>SELECT a, some_func_like_last_value(b) OVER (PARTITION BY a ORDER BY b)
  FROM
  (
      SELECT 1 AS a, 'do not want this' AS b
      UNION SELECT 1, 'just want this'
  ) sub
  </code></pre>
  
  <p>I want this to return one row:</p>
  
  <pre><code>1, 'just want this'
  </code></pre>