Created
October 8, 2021 21:13
-
-
Save jonatas/25af7e918d5d0b53ef99032dc5b746cc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 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); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Timing output: