Skip to content

Commit 29fd3d9

Browse files
committed
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
1 parent 304007d commit 29fd3d9

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

src/backend/commands/trigger.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,11 @@ CreateTrigger(CreateTrigStmt *stmt, const char *queryString,
366366
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
367367
errmsg("transition table name can only be specified for an AFTER trigger")));
368368

369+
if (TRIGGER_FOR_TRUNCATE(tgtype))
370+
ereport(ERROR,
371+
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
372+
errmsg("TRUNCATE triggers with transition tables are not supported")));
373+
369374
if (tt->isNew)
370375
{
371376
if (!(TRIGGER_FOR_INSERT(tgtype) ||

src/test/regress/expected/plpgsql.out

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5943,6 +5943,14 @@ BEGIN
59435943
RETURN NULL;
59445944
END;
59455945
$$;
5946+
-- should fail, TRUNCATE is not compatible with transition tables
5947+
CREATE TRIGGER alter_table_under_transition_tables_upd_trigger
5948+
AFTER TRUNCATE OR UPDATE ON alter_table_under_transition_tables
5949+
REFERENCING OLD TABLE AS d NEW TABLE AS i
5950+
FOR EACH STATEMENT EXECUTE PROCEDURE
5951+
alter_table_under_transition_tables_upd_func();
5952+
ERROR: TRUNCATE triggers with transition tables are not supported
5953+
-- should work
59465954
CREATE TRIGGER alter_table_under_transition_tables_upd_trigger
59475955
AFTER UPDATE ON alter_table_under_transition_tables
59485956
REFERENCING OLD TABLE AS d NEW TABLE AS i

src/test/regress/sql/plpgsql.sql

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4736,6 +4736,14 @@ BEGIN
47364736
END;
47374737
$$;
47384738

4739+
-- should fail, TRUNCATE is not compatible with transition tables
4740+
CREATE TRIGGER alter_table_under_transition_tables_upd_trigger
4741+
AFTER TRUNCATE OR UPDATE ON alter_table_under_transition_tables
4742+
REFERENCING OLD TABLE AS d NEW TABLE AS i
4743+
FOR EACH STATEMENT EXECUTE PROCEDURE
4744+
alter_table_under_transition_tables_upd_func();
4745+
4746+
-- should work
47394747
CREATE TRIGGER alter_table_under_transition_tables_upd_trigger
47404748
AFTER UPDATE ON alter_table_under_transition_tables
47414749
REFERENCING OLD TABLE AS d NEW TABLE AS i

0 commit comments

Comments
 (0)