diff --git a/.unreleased/fix_6522 b/.unreleased/fix_6522 new file mode 100644 index 000000000..46b8420ea --- /dev/null +++ b/.unreleased/fix_6522 @@ -0,0 +1,2 @@ +Fixes: #6522 Disallow triggers on CAggs +Thanks: @HollowMan6 Thanks for reporting this issue diff --git a/src/process_utility.c b/src/process_utility.c index 9d503a4aa..c37ba7d4f 100644 --- a/src/process_utility.c +++ b/src/process_utility.c @@ -3851,12 +3851,19 @@ process_create_trigger_start(ProcessUtilityArgs *args) Cache *hcache; Hypertable *ht; ObjectAddress PG_USED_FOR_ASSERTS_ONLY address; + Oid relid = RangeVarGetRelid(stmt->relation, NoLock, true); hcache = ts_hypertable_cache_pin(); - ht = ts_hypertable_cache_get_entry_rv(hcache, stmt->relation); + ht = ts_hypertable_cache_get_entry(hcache, relid, CACHE_FLAG_MISSING_OK); if (ht == NULL) { ts_cache_release(hcache); + /* check if it's a cagg. We don't support triggers on them yet */ + if (ts_continuous_agg_find_by_relid(relid) != NULL) + ereport(ERROR, + (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + errmsg("triggers are not supported on continuous aggregate"))); + return DDL_CONTINUE; } diff --git a/tsl/test/expected/cagg_errors.out b/tsl/test/expected/cagg_errors.out index b1bf950a5..1e1eff89e 100644 --- a/tsl/test/expected/cagg_errors.out +++ b/tsl/test/expected/cagg_errors.out @@ -321,6 +321,14 @@ INNER JOIN _timescaledb_catalog.hypertable h ON(h.id = ca.mat_hypertable_id) WHERE user_view_name = 'mat_with_test' \gset \set ON_ERROR_STOP 0 +-- triggers not allowed on continuous aggregate +CREATE OR REPLACE FUNCTION not_allowed() RETURNS trigger AS $$ +BEGIN + RETURN NEW; +END; $$ LANGUAGE plpgsql; +CREATE TRIGGER not_allowed_trigger INSTEAD OF INSERT ON mat_with_test +FOR EACH ROW EXECUTE FUNCTION not_allowed(); +ERROR: triggers are not supported on continuous aggregate ALTER MATERIALIZED VIEW mat_with_test SET(timescaledb.create_group_indexes = 'false'); ERROR: cannot alter create_group_indexes option for continuous aggregates ALTER MATERIALIZED VIEW mat_with_test SET(timescaledb.create_group_indexes = 'true'); diff --git a/tsl/test/sql/cagg_errors.sql b/tsl/test/sql/cagg_errors.sql index 5068982f3..759bf88ba 100644 --- a/tsl/test/sql/cagg_errors.sql +++ b/tsl/test/sql/cagg_errors.sql @@ -290,6 +290,15 @@ WHERE user_view_name = 'mat_with_test' \gset \set ON_ERROR_STOP 0 +-- triggers not allowed on continuous aggregate +CREATE OR REPLACE FUNCTION not_allowed() RETURNS trigger AS $$ +BEGIN + RETURN NEW; +END; $$ LANGUAGE plpgsql; + +CREATE TRIGGER not_allowed_trigger INSTEAD OF INSERT ON mat_with_test +FOR EACH ROW EXECUTE FUNCTION not_allowed(); + ALTER MATERIALIZED VIEW mat_with_test SET(timescaledb.create_group_indexes = 'false'); ALTER MATERIALIZED VIEW mat_with_test SET(timescaledb.create_group_indexes = 'true'); ALTER MATERIALIZED VIEW mat_with_test ALTER timec DROP default;