title: SQL: get all variation points for a continuous value
body: <p>I have a sensor value which is sampled quite frequently, so that the value stays the same for more than one sample, i.e.:</p>
  
  <pre>
  Date        Value
  2010-01-01  1.345
  2010-01-02  1.345
  2010-01-03  1.555
  2010-01-04  1.555
  2010-01-05  1.555
  2010-01-06  1.345
  2010-01-07  1.752
  2010-01-08  1.752
  </pre>
  
  <p>And would like to get just the lines in which the value varied:</p>
  
  <pre>
  Date        Value
  2010-01-01  1.345
  2010-01-03  1.555
  2010-01-06  1.345
  2010-01-07  1.752
  </pre>
  
  <p>One option would be to use a LAG window function to get the previous row for each row (ordering by date) and comparing current/previous, but I'm wondering if there is a pure SQL solution.
  I solved the problem with a self outer join as</p>
  
  <pre>
  SELECT t1.date, t1.value
  FROM table t1 LEFT OUTER JOIN table t2
  ON t1.value = t2.value
  AND t1.date > t2.date
  WHERE t2.date IS NULL;
  </pre>
  
  <p>but this works only <strong>if there are no duplicate values</strong>, like it's the case here for value 1.345</p>
  
  <p>I must add that unfortunately the Date values are unique, but not equally spaced in general.</p>
  
  <p>I'm currently working with a PostgreSQL database, but I believe the question can be adapted to any system.</p>