From 2c84ea6cf994f5853de0f03600aa5df8156cf9f4 Mon Sep 17 00:00:00 2001 From: Alvaro Herrera Date: Tue, 9 Jul 2019 17:16:36 -0400 Subject: Propagate trigger arguments to partitions We were creating the cloned triggers with an empty list of arguments, losing the ones that had been specified by the user when creating the trigger in the partitioned table. Repair. This was forgotten in commit 86f575948c77. Author: Patrick McHardy Reviewed-by: Tomas Vondra Discussion: https://postgr.es/m/20190709130027.amr2cavjvo7rdvac@access1.trash.net Discussion: https://postgr.es/m/15752-123bc90287986de4@postgresql.org --- src/backend/commands/tablecmds.c | 23 ++++++++++++++++++++++- src/backend/commands/trigger.c | 1 - 2 files changed, 22 insertions(+), 2 deletions(-) (limited to 'src/backend/commands') diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 3aee2d82ce5..0f1a9f0e548 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -15915,6 +15915,7 @@ CloneRowTriggersToPartition(Relation parent, Relation partition) Datum value; bool isnull; List *cols = NIL; + List *trigargs = NIL; MemoryContext oldcxt; /* @@ -15979,11 +15980,31 @@ CloneRowTriggersToPartition(Relation parent, Relation partition) } } + /* Reconstruct trigger arguments list. */ + if (trigForm->tgnargs > 0) + { + char *p; + + value = heap_getattr(tuple, Anum_pg_trigger_tgargs, + RelationGetDescr(pg_trigger), &isnull); + if (isnull) + elog(ERROR, "tgargs is null for trigger \"%s\" in partition \"%s\"", + NameStr(trigForm->tgname), RelationGetRelationName(partition)); + + p = (char *) VARDATA_ANY(DatumGetByteaPP(value)); + + for (int i = 0; i < trigForm->tgnargs; i++) + { + trigargs = lappend(trigargs, makeString(pstrdup(p))); + p += strlen(p) + 1; + } + } + trigStmt = makeNode(CreateTrigStmt); trigStmt->trigname = NameStr(trigForm->tgname); trigStmt->relation = NULL; trigStmt->funcname = NULL; /* passed separately */ - trigStmt->args = NULL; /* passed separately */ + trigStmt->args = trigargs; trigStmt->row = true; trigStmt->timing = trigForm->tgtype & TRIGGER_TYPE_TIMING_MASK; trigStmt->events = trigForm->tgtype & TRIGGER_TYPE_EVENT_MASK; diff --git a/src/backend/commands/trigger.c b/src/backend/commands/trigger.c index 316692b7c27..ee878d70a91 100644 --- a/src/backend/commands/trigger.c +++ b/src/backend/commands/trigger.c @@ -1172,7 +1172,6 @@ CreateTrigger(CreateTrigStmt *stmt, const char *queryString, */ childStmt = (CreateTrigStmt *) copyObject(stmt); childStmt->funcname = NIL; - childStmt->args = NIL; childStmt->whenClause = NULL; /* If there is a WHEN clause, create a modified copy of it */ -- cgit v1.2.3