Don't permit transition tables with TRUNCATE triggers.
authorRobert Haas <rhaas@postgresql.org>
Wed, 10 May 2017 03:22:39 +0000 (23:22 -0400)
committerRobert Haas <rhaas@postgresql.org>
Wed, 10 May 2017 03:24:23 +0000 (23:24 -0400)
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
src/test/regress/expected/plpgsql.out
src/test/regress/sql/plpgsql.sql

index d05e51c8208861cb19aa9d0f3a294943f0669601..c0511639db027e3be00520fd7f5e839d9ff5f590 100644 (file)
@@ -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) ||
index 2beb658e96fabbcb60622934fee2e03639c940c8..7ebbde60d3034998abc217928ea860b56cf64e24 100644 (file)
@@ -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
index edda04774f6f8cf0125fe9ffe15f56885216d483..60d1d38e346023a8e30cb6fcefe890588d4a955e 100644 (file)
@@ -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