title: Adding negative Intervals in PostgreSQL
body: <p>I'm using the following code to add intervals. But it doesn't seem to work if the times aren't on the same day.</p>
  <p>For example start = 23:00 and end = 01:00</p>
  <p><strong>Code</strong></p>
  <pre><code>SELECT extract(epoch from SUM(end - start)::interval) FROM table GROUP BY column
  </code></pre>
  <p><strong>Problem</strong></p>
  <p>If I add: end = 01:00 and start = 23:00 then it will add a negative and false number to the sum.
  Because 01:00 - 23:00 is -22:00. However, the correct result should be 2:00 because between 23:01 and 01:00 there are two hours.</p>