title: How to have a field in Postgresql depending on the previous rows found?
body: <p>To make it simple, I have a table with stock in/out like this :</p>
  
  <pre><code>date,in_out
  2013-08-05,+5
  2013-08-07,-2
  2013-08-12,-1
  </code></pre>
  
  <p>What I would like to do is to have the number of items in stock for each date :</p>
  
  <pre><code>date,in_out,quantity
  2013-08-05,+5,5
  2013-08-07,-2,3
  2013-08-12,-1,2
  </code></pre>
  
  <p>But even if I normally know Postgresql quite well I really don't see how to write a SELECT request that could take into account previous rows.</p>
  
  <p>What I would have done is something like that :</p>
  
  <pre><code>SELECT date,in_out, (stock_quant := stock_quant + in_out) AS quantity FROM table_stock;
  </code></pre>
  
  <p>Any suggestion would be greatly appreciated !</p>