timescaledb/sql/main/hypertable_triggers.sql
Matvey Arye 42ee7c8586 starting refactor of clustering and naming logic
This fix allows more flexible placement of tables on a node; better
and more flexible logic for remote placement of chunks on nodes.
2016-11-22 16:41:27 -05:00

34 lines
1.0 KiB
PL/PgSQL

CREATE OR REPLACE FUNCTION _sysinternal.on_create_hypertable()
RETURNS TRIGGER LANGUAGE PLPGSQL AS
$BODY$
DECLARE
remote_node node;
BEGIN
IF TG_OP <> 'INSERT' THEN
RAISE EXCEPTION 'Only inserts supported on namespace table'
USING ERRCODE = 'IO101';
END IF;
PERFORM _sysinternal.create_schema(NEW.main_schema_name);
PERFORM _sysinternal.create_schema(NEW.associated_schema_name);
PERFORM _sysinternal.create_schema(NEW.root_schema_name);
PERFORM _sysinternal.create_schema(NEW.distinct_schema_name);
PERFORM _sysinternal.create_root_table(NEW.root_schema_name, NEW.root_table_name);
PERFORM _sysinternal.create_root_distinct_table(NEW.distinct_schema_name, NEW.distinct_table_name);
RETURN NEW;
END
$BODY$
SET SEARCH_PATH = 'public';
BEGIN;
DROP TRIGGER IF EXISTS trigger_on_create_hypertable
ON hypertable;
CREATE TRIGGER trigger_on_create_hypertable AFTER INSERT OR UPDATE OR DELETE ON hypertable
FOR EACH ROW EXECUTE PROCEDURE _sysinternal.on_create_hypertable();
COMMIT;