timescaledb/sql/main/hypertable_replica_triggers.sql
Erik Nordström 7b94c573ba Refactor directory structure and tests
- Directory structure now matches common practices
- Regression tests now run with pg_regress via the PGXS infrastructure.
- Unit tests do not integrate well with pg_regress and have to be run
  separately.
- Docker functionality is separate from main Makefile. Run with
  `make -f docker.mk` to build and `make -f docker.mk run` to run
  the database in a container.
2017-01-31 20:14:19 +01:00

21 lines
700 B
PL/PgSQL

CREATE OR REPLACE FUNCTION _iobeamdb_internal.on_change_hypertable_replica()
RETURNS TRIGGER LANGUAGE PLPGSQL AS
$BODY$
DECLARE
hypertable_row _iobeamdb_catalog.hypertable;
BEGIN
IF TG_OP = 'INSERT' THEN
SELECT *
INTO STRICT hypertable_row
FROM _iobeamdb_catalog.hypertable AS h
WHERE h.id = NEW.hypertable_id;
PERFORM _iobeamdb_internal.create_replica_table(NEW.schema_name, NEW.table_name, hypertable_row.root_schema_name,
hypertable_row.root_table_name);
RETURN NEW;
END IF;
PERFORM _iobeamdb_internal.on_trigger_error(TG_OP, TG_TABLE_SCHEMA, TG_TABLE_NAME);
END
$BODY$;