From 29fd3d9da0ff9e230ff051c1423871bd6eac377d Mon Sep 17 00:00:00 2001 From: Robert Haas Date: Tue, 9 May 2017 23:22:39 -0400 Subject: [PATCH] Don't permit transition tables with TRUNCATE triggers. Prior to this prohibition, such a trigger caused a crash. Thomas Munro, per a report from Neha Sharma. I added a regression test. Discussion: http://postgr.es/m/CAEepm=0VR5W-N38eTkO_FqJbGqQ_ykbBRmzmvHyxDhy1p=0Csw@mail.gmail.com --- src/backend/commands/trigger.c | 5 +++++ src/test/regress/expected/plpgsql.out | 8 ++++++++ src/test/regress/sql/plpgsql.sql | 8 ++++++++ 3 files changed, 21 insertions(+) diff --git a/src/backend/commands/trigger.c b/src/backend/commands/trigger.c index d05e51c820..c0511639db 100644 --- a/src/backend/commands/trigger.c +++ b/src/backend/commands/trigger.c @@ -366,6 +366,11 @@ CreateTrigger(CreateTrigStmt *stmt, const char *queryString, (errcode(ERRCODE_INVALID_OBJECT_DEFINITION), errmsg("transition table name can only be specified for an AFTER trigger"))); + if (TRIGGER_FOR_TRUNCATE(tgtype)) + ereport(ERROR, + (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + errmsg("TRUNCATE triggers with transition tables are not supported"))); + if (tt->isNew) { if (!(TRIGGER_FOR_INSERT(tgtype) || diff --git a/src/test/regress/expected/plpgsql.out b/src/test/regress/expected/plpgsql.out index 2beb658e96..7ebbde60d3 100644 --- a/src/test/regress/expected/plpgsql.out +++ b/src/test/regress/expected/plpgsql.out @@ -5943,6 +5943,14 @@ BEGIN RETURN NULL; END; $$; +-- should fail, TRUNCATE is not compatible with transition tables +CREATE TRIGGER alter_table_under_transition_tables_upd_trigger + AFTER TRUNCATE OR UPDATE ON alter_table_under_transition_tables + REFERENCING OLD TABLE AS d NEW TABLE AS i + FOR EACH STATEMENT EXECUTE PROCEDURE + alter_table_under_transition_tables_upd_func(); +ERROR: TRUNCATE triggers with transition tables are not supported +-- should work CREATE TRIGGER alter_table_under_transition_tables_upd_trigger AFTER UPDATE ON alter_table_under_transition_tables REFERENCING OLD TABLE AS d NEW TABLE AS i diff --git a/src/test/regress/sql/plpgsql.sql b/src/test/regress/sql/plpgsql.sql index edda04774f..60d1d38e34 100644 --- a/src/test/regress/sql/plpgsql.sql +++ b/src/test/regress/sql/plpgsql.sql @@ -4736,6 +4736,14 @@ BEGIN END; $$; +-- should fail, TRUNCATE is not compatible with transition tables +CREATE TRIGGER alter_table_under_transition_tables_upd_trigger + AFTER TRUNCATE OR UPDATE ON alter_table_under_transition_tables + REFERENCING OLD TABLE AS d NEW TABLE AS i + FOR EACH STATEMENT EXECUTE PROCEDURE + alter_table_under_transition_tables_upd_func(); + +-- should work CREATE TRIGGER alter_table_under_transition_tables_upd_trigger AFTER UPDATE ON alter_table_under_transition_tables REFERENCING OLD TABLE AS d NEW TABLE AS i -- 2.40.0