title: Postgresql SQL GROUP BY time interval with arbitrary accuracy (down to milli seconds)
body: <p>I have my measurement data stored into the following structure:</p>
  
  <pre><code>CREATE TABLE measurements(
  measured_at TIMESTAMPTZ,
  val INTEGER
  );
  </code></pre>
  
  <p>I <strong>already</strong> know that using </p>
  
  <p>(a) <code>date_trunc('hour',measured_at)</code> </p>
  
  <p>AND</p>
  
  <p>(b) <code>generate_series</code></p>
  
  <p>I would be able to aggregate my data by: </p>
  
  <pre><code>microseconds,
  milliseconds
  .
  .
  .
  </code></pre>
  
  <p>But is it possible to aggregate the data by 5 minutes or let's say an arbitrary amount of seconds? Is it possible to aggregate measured data by an arbitrary multiple of seconds?</p>
  
  <p>I need the data aggregated by different time resolutions to feed them into a FFT or an AR-Model in order to see possible seasonalities.</p>