mirror of
https://github.com/warkanum/warkanums-pi-device-snippets.git
synced 2026-01-30 14:24:24 +00:00
Prototype 1
This commit is contained in:
10
build1/sql/sensordata.sql
Executable file
10
build1/sql/sensordata.sql
Executable file
@@ -0,0 +1,10 @@
|
||||
CREATE TABLE sensordata
|
||||
(
|
||||
id bigserial NOT NULL,
|
||||
sensor_type text,
|
||||
data_read text,
|
||||
time_read bigint,
|
||||
time_changed bigint,
|
||||
CONSTRAINT pk_id PRIMARY KEY (id),
|
||||
CONSTRAINT k_typeread UNIQUE (sensor_type, time_read)
|
||||
)
|
||||
18
build1/sql/v_sensordata_current.sql
Executable file
18
build1/sql/v_sensordata_current.sql
Executable file
@@ -0,0 +1,18 @@
|
||||
-- View: v_sensordata_current
|
||||
|
||||
-- DROP VIEW v_sensordata_current;
|
||||
|
||||
CREATE OR REPLACE VIEW v_sensordata_current AS
|
||||
SELECT r1.rn,
|
||||
r1.id,
|
||||
r1.sensor_type,
|
||||
r1.data_read,
|
||||
to_timestamp(r1.time_read) AT TIME ZONE 'UTC' as time_read
|
||||
FROM ( SELECT row_number() OVER (PARTITION BY sensordata.sensor_type ORDER BY sensordata.time_read DESC) AS rn,
|
||||
sensordata.id,
|
||||
sensordata.sensor_type,
|
||||
sensordata.data_read,
|
||||
sensordata.time_read,
|
||||
sensordata.time_changed
|
||||
FROM sensordata) r1
|
||||
WHERE r1.rn = 1;
|
||||
Reference in New Issue
Block a user