timescaledb/sql/meta/partition_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

27 lines
964 B
PL/PgSQL

CREATE OR REPLACE FUNCTION _iobeamdb_meta.on_change_partition()
RETURNS TRIGGER LANGUAGE PLPGSQL AS
$BODY$
BEGIN
IF TG_OP = 'INSERT' THEN
INSERT INTO _iobeamdb_catalog.partition_replica (partition_id, hypertable_id, replica_id, schema_name, table_name)
(SELECT
NEW.id,
hypertable_id,
replica_id,
h.associated_schema_name,
format('%s_%s_%s_partition', h.associated_table_prefix, NEW.id, replica_id)
FROM _iobeamdb_catalog.hypertable_replica hr
INNER JOIN _iobeamdb_catalog.hypertable h ON (h.id = hr.hypertable_id)
WHERE hypertable_id = (
SELECT hypertable_id
FROM _iobeamdb_catalog.partition_epoch
WHERE id = NEW.epoch_id
));
RETURN NEW;
END IF;
PERFORM _iobeamdb_internal.on_trigger_error(TG_OP, TG_TABLE_SCHEMA, TG_TABLE_NAME);
END
$BODY$;