title: How to select rows by time interval in PostgreSQL?
body: <p>I have a table with timestamp field and usage field like this</p>
  
  <pre><code>            timestamp  | usage
  '2015-06-13 13:45:58'  | 240
  '2015-06-13 13:45:59'  | 480
  '2015-06-13 13:46:00'  | 240
  '2015-06-13 13:46:01'  | 320
   ...
  </code></pre>
  
  <p>I want to get sum of usage for a period of '1 week' with '30 minutes' interval. 
  I can get data only for intervals in minute, hour, day and ... </p>
  
  <pre><code>SELECT date_trunc('minute', timestamp) as clock, sum(usage)
  FROM my_table
  WHERE timestamp &gt; localtimestamp - INTERVAL '1 week'
  GROUP BY clock
  </code></pre>
  
  <p>how to get data for intervals like '5 minutes', '30 minutes', '2 days' and ... .</p>