use json from mqtt and store it in postgresql
[eg5120] / create.sql
1 drop table eg5120;
2 create table eg5120 (
3         time timestamp without time zone default now(),
4         mac text,
5         addr text,
6         "nodeId" int,
7         json jsonb,
8         _id serial
9 );
10
11 CREATE OR REPLACE FUNCTION json_fn()
12   RETURNS TRIGGER AS
13 $func$
14 BEGIN
15    NEW := jsonb_populate_record(NEW, NEW.json); -- or hstore alternative
16    RETURN NEW;
17 END
18 $func$ LANGUAGE plpgsql;
19
20 CREATE TRIGGER json_trigger
21 BEFORE INSERT OR UPDATE ON eg5120 FOR EACH ROW
22 EXECUTE PROCEDURE json_fn();
23
24