title: Copy value from one row to another row in PostgreSQL
body: <p>I have a table like this:</p>
  
  <pre><code>id   product   amount
  1    A         6
  1    A         8
  1    A         
  1    B         1
  1    B         
  2    C         2
  2    C       
  2    C         4
  2    C    
  2    C 
  </code></pre>
  
  <p>and I need to make it like this:</p>
  
  <pre><code>id   product   amount
  1    A         6
  1    A         8
  1    A         8
  1    B         1
  1    B         1
  2    C         2
  2    C         2
  2    C         4
  2    C         4
  2    C         4
  </code></pre>
  
  <p>Copy amount by previous non-missing value.</p>
  
  <p>I tried to use <code>lag()</code> function. however, aggregation function <code>lag()</code> is not allowed in UPDATE.</p>
  
  <pre><code>update tableA set amount = lag(amount); 
  </code></pre>
  
  <p>What can I do using PostgreSQL?</p>