quiet
[rtl433-sensors] / tele.sql
1 drop table tele;
2 create table tele (
3         _id serial,
4         time timestamp without time zone default now(),
5         topic text not null,
6         json jsonb
7 );
8
9 CREATE OR REPLACE FUNCTION json_tele_fn()
10   RETURNS TRIGGER AS
11 $func$
12 BEGIN
13    NEW := jsonb_populate_record(NEW, NEW.json); -- or hstore alternative
14    NEW.time = NEW.json->'Time';
15    RETURN NEW;
16 END
17 $func$ LANGUAGE plpgsql;
18
19 CREATE TRIGGER json_tele_trigger
20 BEFORE INSERT OR UPDATE ON tele FOR EACH ROW
21 EXECUTE PROCEDURE json_tele_fn();
22
23