2

I've been trying to downsample my data in postgres, to mimic the downsampling that python offers (using 'resample').

so far I've managed to do it for single units of time as:

SELECT t,avg(data)
FROM
(
    SELECT date_trunc('hour',"timestamp") as t,*
    FROM
    (
        SELECT "timestamp",data
        FROM sample_data
    )res1
ORDER BY t
)res
GROUP BY t

which groups for every 1 hour.

what if I wish to downsample for every 2 hours/5 hours etc ?

aswa09
  • 169
  • 1
  • 1
  • 10
  • if you know the lower and upper bonds you can `generate_series(min,max,'2 hours'::interval)` and join against it – Vao Tsun Aug 03 '17 at 08:24

0 Answers0