title: Average over hard to define partition
body: <p>I have this table:</p>
  
  <pre><code>create table t (value int, dt date);
  
   value |     dt     
  -------+------------
      10 | 2012-10-30
      15 | 2012-10-29
    null | 2012-10-28
    null | 2012-10-27
       7 | 2012-10-26
  </code></pre>
  
  <p>And I want this output:</p>
  
  <pre><code> value |     dt     
  -------+------------
      10 | 2012-10-30
       5 | 2012-10-29
       5 | 2012-10-28
       5 | 2012-10-27
       7 | 2012-10-26
  </code></pre>
  
  <p>I want the null values, as well as the one previous non null value, to be replaced by the average of the previous not null value when the table is ordered by date descending. In this example the value 15 is the previous not null value of the next two nulls. So 15 / 3 = 5.</p>
  
  <p><a href="http://www.sqlfiddle.com/#!12/6a0c7/1" rel="nofollow">SQL Fiddle</a></p>