title: PostgreSQL: fill NULL values in timeserie query with previous value
body: <p>I have a database with time related information. I want a list with values for every minute. Like this:</p>
  
  <pre><code>12:00:00  3
  12:01:00  4
  12:02:00  5
  12:03:00  5
  12:04:00  5
  12:05:00  3
  </code></pre>
  
  <p>But when there is no data for some minutes I got a result like this:</p>
  
  <pre><code>12:00:00  3
  12:01:00  4
  12:02:00  5
  12:03:00  NULL
  12:04:00  NULL
  12:05:00  3
  </code></pre>
  
  <p>I want to fill the NULL value with the previous NOT NULL value.</p>
  
  <p>This query creates a timeserie for every minute. Then it joins this to the data in my database. </p>
  
  <p>I read something about window functions to fill the NULL value with the previous NOT NULL value, but I can't figure out how to implement this in this query. Can someone push me in the good direction?</p>
  
  <p>I tried this solution, but the NULL values are still there:
  <a href="https://stackoverflow.com/questions/15145056/postgresql-use-value-from-previous-row-if-missing">PostgreSQL use value from previous row if missing</a></p>
  
  <p>This is my query:</p>
  
  <pre><code>SELECT
      date,
      close
  FROM generate_series(
    '2017-11-01 09:00'::timestamp,
    '2017-11-01 23:59'::timestamp,
    '1 minute') AS date
  LEFT OUTER JOIN
   (SELECT
      date_trunc('minute', market_summary."timestamp") as day,
      LAST(current, timestamp) AS close
      FROM market_summary
    WHERE created_at &gt;= '2017-11-01 09:00'
      AND created_at &lt; '2017-11-01 23:59'
      GROUP BY day
   ) results
  ON (date = results.day)
  ORDER BY date
  </code></pre>