-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnotify.sql
More file actions
34 lines (28 loc) · 1.46 KB
/
notify.sql
File metadata and controls
34 lines (28 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
drop table batteries cascade;
CREATE TABLE batteries (t timestamp not null, batt_uid varchar, charge int);
SELECT create_hypertable('batteries', 't');
DROP FUNCTION IF EXISTS watch_charge;
CREATE OR REPLACE FUNCTION watch_charge(INOUT t timestamp, INOUT batt_uid varchar, INOUT charge int) AS
$BODY$
BEGIN
IF charge > 100 then
raise notice 'Battery % charge is too high: %', batt_uid, charge;
END IF;
END;
$BODY$
LANGUAGE plpgsql;
\timing
INSERT into batteries VALUES (now()::timestamp, 'battery-1', 90);
INSERT into batteries VALUES (now()::timestamp, 'battery-1', 91);
INSERT into batteries VALUES (now()::timestamp, 'battery-1', 98);
INSERT into batteries VALUES (now()::timestamp, 'battery-1', 99);
INSERT into batteries VALUES (now()::timestamp, 'battery-1', 100);
INSERT into batteries VALUES (now()::timestamp, 'battery-1', 101);
Insert into batteries VALUES (now()::timestamp, 'battery-2', 90);
INSERT into batteries VALUES (now()::timestamp, 'battery-2', 91);
INSERT into batteries SELECT * FROM watch_charge(now()::timestamp, 'battery-1', 90);
INSERT into batteries SELECT * FROM watch_charge(now()::timestamp, 'battery-1', 91);
INSERT into batteries SELECT * FROM watch_charge(now()::timestamp, 'battery-1', 98);
INSERT into batteries SELECT * FROM watch_charge(now()::timestamp, 'battery-1', 99);
INSERT into batteries SELECT * FROM watch_charge(now()::timestamp, 'battery-1', 100);
INSERT into batteries SELECT * FROM watch_charge(now()::timestamp, 'battery-1', 101);