title: Linear regression with postgres
body: <p>I use <strong>Postgres</strong> and i have a large number of rows with values and date per station.
  (Dates can be separated by several days.)</p>
  
  <pre><code>id      | value | idstation | udate
  --------+-------+-----------+-----
  1       |  5    | 12        | 1984-02-11 00:00:00
  2       |  7    | 12        | 1984-02-17 00:00:00
  3       |  8    | 12        | 1984-02-21 00:00:00
  4       |  9    | 12        | 1984-02-23 00:00:00
  5       |  4    | 12        | 1984-02-24 00:00:00
  6       |  8    | 12        | 1984-02-28 00:00:00
  7       |  9    | 14        | 1984-02-21 00:00:00
  8       |  15   | 15        | 1984-02-21 00:00:00
  9       |  14   | 18        | 1984-02-21 00:00:00
  10      |  200  | 19        | 1984-02-21 00:00:00
  </code></pre>
  
  <p>Forgive what may be a silly question, but I'm not much of a database guru.</p>
  
  <p>Is it possible to directly enter a SQL query that will calculate <strong>linear regression</strong>  per station for each date, knowing that the regression must be calculate only with actual id date, previous id date and next id date ? </p>
  
  <p><em>For example linear regression for id <strong>2</strong> must be calculate with value 7(actual),5(previous),8(next) for dates 1984-02-17 , 1984-02-11 and 1984-02-21</em></p>
  
  <p><strong>Edit</strong> : I have to use <strong>regr_intercept(value,udate)</strong> but i really don't know how to do this if i have to use only actual, previous and next value/date for each lines. </p>
  
  <p><strong>Edit2</strong> : 3 rows added to idstation(12); id and dates numbers are changed</p>
  
  <p>Hope you can help me, thank you ! </p>