I have a table with data for IoT Devices, sending measurements every hour. Have to get reports for Today, Week, Month and Year.
Using timescaleDB i got some "ok" results for Today, Week and Month. For example Monthly:
SELECT
time_bucket('4 weeks', measured_at) AS month,
MAX(CAST(data->>'1_8_0' AS DOUBLE PRECISION)) - MIN(CAST(data->>'1_8_0' AS DOUBLE PRECISION)) as consumption
FROM readings
WHERE device_id = 4
GROUP BY month
ORDER BY month DESC LIMIT 12;
But can not find a good way to fetch values for years? Any one ever tried that?
Year is not supported by timescale, using weeks results in wrong result.
ERROR: interval defined in terms of month, year, century etc. not supported