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 ?