remove all output without DEBUG=1 for cron use
[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         sensor_type int default null,
8         json jsonb,
9         _id serial
10 );
11
12 CREATE OR REPLACE FUNCTION json_fn()
13   RETURNS TRIGGER AS
14 $func$
15 BEGIN
16    NEW := jsonb_populate_record(NEW, NEW.json); -- or hstore alternative
17    RETURN NEW;
18 END
19 $func$ LANGUAGE plpgsql;
20
21 CREATE TRIGGER json_trigger
22 BEFORE INSERT OR UPDATE ON eg5120 FOR EACH ROW
23 EXECUTE PROCEDURE json_fn();
24
25