title: Fill missing values with first non-null following value in Redshift
body: <p>I am on Redshift. Given the following data:</p>
  
  <pre><code>CREATE TABLE test (
  id INT,
  val1 INT,
  val2 INT
  );
  
  INSERT INTO test VALUES
  (1, 0,  NULL),
  (2, 0,  NULL),
  (3, 13, 1),
  (4, 0,  NULL),
  (5, 0,  NULL),
  (6, 0,  NULL),
  (7, 0,  NULL),
  (8, 21, 2),
  (9, 0,  NULL),
  (10, 143,3)
  ;
  </code></pre>
  
  <p>I'd want to fill the missing val2 values with the first following non-null value, e.g.</p>
  
  <pre><code>   INSERT INTO results VALUES
      (1, 0,  1),
      (2, 0,  1),
      (3, 13, 1),
      (4, 0,  2),
      (5, 0,  2),
      (6, 0,  2),
      (7, 0,  2),
      (8, 21, 2),
      (9, 0,  3),
      (10,143,3)
      ;
  </code></pre>
  
  <p>What is the best way to accomplish this in Redshift/Postgres 8.0.2?</p>