I want to plot my_values
with some lower resolution on the time axis than I have in the database. I use something like the following SQL to get the average values per time interval (e.g., an hour):
SELECT DATE_TRUNC('hour', my_timestamps) AS my_time_lowres
, AVG(my_values)
FROM my_table
GROUP BY my_time_lowres
Using date_trunc()
it is possible to reduce the resolution of the timestamp to a certain degree (according to the docs):
select date_trunc('hour', timestamp '2001-02-16 20:38:40')
-- the output is: 2001-02-16 20:00:00
This way, I can do this for the following interval sizes (and some larger/smaller sizes):
...
second
minute
hour
day
week
...
Is there a way to achieve this for other time intervals as well, e.g., 3 hours, 6 hours?