· 7 years ago · Oct 29, 2018, 05:50 PM
1CREATE TABLE readings (
2 id BIGSERIAL PRIMARY KEY,
3 time TIMESTAMPTZ NOT NULL,
4 value DOUBLE PRECISION NOT NULL,
5 device VARCHAR(255) NOT NULL,
6 sensor VARCHAR(255) NOT NULL,
7 resolution VARCHAR(255) NOT NULL,
8 UNIQUE(time, device, sensor, resolution)
9);
10
11select MAX(time), device, sensor from readings group by device, sensor
12
13create index if not exists readings_idx on readings (time, device, sensor, resolution);