1
0
mirror of https://github.com/timescale/timescaledb.git synced 2025-05-17 11:03:36 +08:00

Disallow triggers on CAggs

We don't support triggers on CAggs yet. Disallow that explicitly
till we support them later.

Fixes 
This commit is contained in:
Nikhil Sontakke 2024-01-15 13:59:03 +05:30 committed by Nikhil
parent 095504938d
commit 7ae7cc5713
4 changed files with 27 additions and 1 deletions

2
.unreleased/fix_6522 Normal file

@ -0,0 +1,2 @@
Fixes: #6522 Disallow triggers on CAggs
Thanks: @HollowMan6 Thanks for reporting this issue

@ -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;
}

@ -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');

@ -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;