diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 54a7327ad4972..868c3dd3073a2 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -10091,7 +10091,7 @@ CloneFkReferenced(Relation parentRel, Relation partitionRel) * parent OIDs for similar triggers that will be created on the * partition in addFkRecurseReferenced(). */ - GetForeignKeyActionTriggers(trigrel, constrForm->oid, + GetForeignKeyActionTriggers(trigrel, constrOid, constrForm->confrelid, constrForm->conrelid, &deleteTriggerOid, &updateTriggerOid); @@ -10559,9 +10559,15 @@ GetForeignKeyActionTriggers(Relation trigrel, if (trgform->tgrelid != confrelid) continue; if (TRIGGER_FOR_DELETE(trgform->tgtype)) + { + Assert(*deleteTriggerOid == InvalidOid); *deleteTriggerOid = trgform->oid; + } else if (TRIGGER_FOR_UPDATE(trgform->tgtype)) + { + Assert(*updateTriggerOid == InvalidOid); *updateTriggerOid = trgform->oid; + } if (OidIsValid(*deleteTriggerOid) && OidIsValid(*updateTriggerOid)) break; } @@ -10608,9 +10614,15 @@ GetForeignKeyCheckTriggers(Relation trigrel, if (trgform->tgrelid != conrelid) continue; if (TRIGGER_FOR_INSERT(trgform->tgtype)) + { + Assert(*insertTriggerOid == InvalidOid); *insertTriggerOid = trgform->oid; + } else if (TRIGGER_FOR_UPDATE(trgform->tgtype)) + { + Assert(*updateTriggerOid == InvalidOid); *updateTriggerOid = trgform->oid; + } if (OidIsValid(*insertTriggerOid) && OidIsValid(*updateTriggerOid)) break; } @@ -11670,10 +11682,10 @@ createForeignKeyActionTriggers(Relation rel, Oid refRelOid, Constraint *fkconstr break; } - trigAddress= CreateTrigger(fk_trigger, NULL, refRelOid, - RelationGetRelid(rel), - constraintOid, indexOid, InvalidOid, - parentDelTrigger, NULL, true, false); + trigAddress = CreateTrigger(fk_trigger, NULL, refRelOid, + RelationGetRelid(rel), + constraintOid, indexOid, InvalidOid, + parentDelTrigger, NULL, true, false); if (deleteTrigOid) *deleteTrigOid = trigAddress.objectId; @@ -18722,8 +18734,8 @@ DropClonedTriggersFromPartition(Oid partitionId) /* * Ignore internal triggers that are implementation objects of foreign - * keys, because they will be when the foreign keys are themselves - * detached. + * keys, because these will be detached when the foreign keys + * themselves are. */ if (OidIsValid(pg_trigger->tgconstrrelid)) continue; diff --git a/src/backend/commands/trigger.c b/src/backend/commands/trigger.c index 52b17294bf47e..452b743f21add 100644 --- a/src/backend/commands/trigger.c +++ b/src/backend/commands/trigger.c @@ -776,8 +776,8 @@ CreateTriggerFiringOn(CreateTrigStmt *stmt, const char *queryString, * in_partition, because then we're recursing from a partitioned table * and the check was made at the parent level. */ - if ((existing_isInternal || existing_isClone) && !isInternal && - !in_partition) + if ((existing_isInternal || existing_isClone) && + !isInternal && !in_partition) ereport(ERROR, (errcode(ERRCODE_DUPLICATE_OBJECT), errmsg("trigger \"%s\" for relation \"%s\" is an internal or a child trigger", diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 7713f31408839..8f40a46233b4b 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -7262,7 +7262,7 @@ getTriggers(Archive *fout, TableInfo tblinfo[], int numTables) "SELECT t.tgrelid, t.tgname, " "t.tgfoid::pg_catalog.regproc AS tgfname, " "pg_catalog.pg_get_triggerdef(t.oid, false) AS tgdef, " - "t.tgenabled, t.tableoid, t.oid, t.tgisinternal\n" + "t.tgenabled, t.tableoid, t.oid, t.tgisinternal as tgispartition\n" "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n" "JOIN pg_catalog.pg_trigger t ON (src.tbloid = t.tgrelid) " "LEFT JOIN pg_catalog.pg_trigger u ON (u.oid = t.tgparentid) " @@ -7283,7 +7283,7 @@ getTriggers(Archive *fout, TableInfo tblinfo[], int numTables) "SELECT t.tgrelid, t.tgname, " "t.tgfoid::pg_catalog.regproc AS tgfname, " "pg_catalog.pg_get_triggerdef(t.oid, false) AS tgdef, " - "t.tgenabled, t.tableoid, t.oid, t.tgisinternal " + "t.tgenabled, t.tableoid, t.oid, t.tgisinternal as tgispartition " "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n" "JOIN pg_catalog.pg_trigger t ON (src.tbloid = t.tgrelid) " "LEFT JOIN pg_catalog.pg_depend AS d ON " @@ -7302,7 +7302,7 @@ getTriggers(Archive *fout, TableInfo tblinfo[], int numTables) "SELECT t.tgrelid, t.tgname, " "t.tgfoid::pg_catalog.regproc AS tgfname, " "pg_catalog.pg_get_triggerdef(t.oid, false) AS tgdef, " - "t.tgenabled, false as tgisinternal, " + "t.tgenabled, false as tgispartition, " "t.tableoid, t.oid " "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n" "JOIN pg_catalog.pg_trigger t ON (src.tbloid = t.tgrelid) " diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index 44cc1fa132c9a..0615de53255fe 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -3001,14 +3001,15 @@ describeOneTableDetails(const char *schemaname, " AND u.tgparentid = 0) AS parent" : "NULL AS parent"), oid); + /* - * tgisnternal is set to true for inherited triggers of partitions in - * the servers between v11 and v13, though still must be shown to the - * user. So we use another property that is true for such inherited - * triggers to avoid them being hidden, which is their dependendence - * on another trigger. + * tgisinternal is set true for inherited triggers of partitions in + * servers between v11 and v14, though these must still be shown to + * the user. So we use another property that is true for such + * inherited triggers to avoid them being hidden, which is their + * dependendence on another trigger. */ - if (pset.sversion >= 110000 && pset.sversion < 140000) + if (pset.sversion >= 110000 && pset.sversion < 150000) appendPQExpBufferStr(&buf, "(NOT t.tgisinternal OR (t.tgisinternal AND t.tgenabled = 'D') \n" " OR EXISTS (SELECT 1 FROM pg_catalog.pg_depend WHERE objid = t.oid \n" " AND refclassid = 'pg_catalog.pg_trigger'::pg_catalog.regclass))");