X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=tele.sql;fp=tele.sql;h=30a7a1d012df5a90e7dc79da3840ee18794165b7;hb=833113950c84a096286ddb2eb663190e3a317a32;hp=0000000000000000000000000000000000000000;hpb=947ca9986ae9293cd872b4e4c4c3c4c0f574c00f;p=rtl433-sensors diff --git a/tele.sql b/tele.sql new file mode 100644 index 0000000..30a7a1d --- /dev/null +++ b/tele.sql @@ -0,0 +1,23 @@ +drop table tele; +create table tele ( + _id serial, + time timestamp without time zone default now(), + topic text not null, + json jsonb +); + +CREATE OR REPLACE FUNCTION json_tele_fn() + RETURNS TRIGGER AS +$func$ +BEGIN + NEW := jsonb_populate_record(NEW, NEW.json); -- or hstore alternative + NEW.time = NEW.json->'Time'; + RETURN NEW; +END +$func$ LANGUAGE plpgsql; + +CREATE TRIGGER json_tele_trigger +BEFORE INSERT OR UPDATE ON tele FOR EACH ROW +EXECUTE PROCEDURE json_tele_fn(); + +