TimescaleDB turns PostgreSQL into a powerful time-series database.
CREATE EXTENSION timescaledb;
CREATE TABLE metrics (
time TIMESTAMPTZ NOT NULL,
device TEXT,
temp DOUBLE PRECISION
);
SELECT create_hypertable('metrics', 'time');
-- Auto-bucketing
SELECT time_bucket('1 hour', time) AS hour,
AVG(temp)
FROM metrics GROUP BY 1 ORDER BY 1;