Why does AVG query not work after a month in Postgres?
Solution 1:
When using group by
keywords your column format (with the cast, etc) should same format in group by operation
SELECT
DATE_TRUNC('hour', created_at::timestamp) as datetime,
AVG(temperature_1) as temperature_1
FROM main_data
where created_at BETWEEN '2022-01-22 01:00:00' AND '2022-01-22 3:00:00'
GROUP BY DATE_TRUNC('hour', created_at::timestamp)