Prototype 1

This commit is contained in:
2014-12-28 17:53:28 +02:00
parent c33f70eff7
commit c71f871e31
4 changed files with 237 additions and 0 deletions

10
build1/sql/sensordata.sql Executable file
View 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)
)

View 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;