drop table eg5120;
create table eg5120 (
	time timestamp without time zone default now(),
	mac text,
	addr text,
	"nodeId" int,
	json jsonb,
	_id serial
);

CREATE OR REPLACE FUNCTION json_fn()
  RETURNS TRIGGER AS
$func$
BEGIN
   NEW := jsonb_populate_record(NEW, NEW.json); -- or hstore alternative
   RETURN NEW;
END
$func$ LANGUAGE plpgsql;

CREATE TRIGGER json_trigger
BEFORE INSERT OR UPDATE ON eg5120 FOR EACH ROW
EXECUTE PROCEDURE json_fn();


