diff --git a/src/backend/commands/trigger.c b/src/backend/commands/trigger.c index 57519fe8d6..9542856d6a 100644 --- a/src/backend/commands/trigger.c +++ b/src/backend/commands/trigger.c @@ -815,11 +815,6 @@ CreateTrigger(CreateTrigStmt *stmt, const char *queryString, /* * Build the new pg_trigger tuple. - * - * When we're creating a trigger in a partition, we mark it as internal, - * even though we don't do the isInternal magic in this function. This - * makes the triggers in partitions identical to the ones in the - * partitioned tables, except that they are marked internal. */ memset(nulls, false, sizeof(nulls)); @@ -829,7 +824,8 @@ CreateTrigger(CreateTrigStmt *stmt, const char *queryString, values[Anum_pg_trigger_tgfoid - 1] = ObjectIdGetDatum(funcoid); values[Anum_pg_trigger_tgtype - 1] = Int16GetDatum(tgtype); values[Anum_pg_trigger_tgenabled - 1] = CharGetDatum(TRIGGER_FIRES_ON_ORIGIN); - values[Anum_pg_trigger_tgisinternal - 1] = BoolGetDatum(isInternal || in_partition); + values[Anum_pg_trigger_tgisinternal - 1] = BoolGetDatum(isInternal); + values[Anum_pg_trigger_tginpartition - 1] = BoolGetDatum(in_partition); values[Anum_pg_trigger_tgconstrrelid - 1] = ObjectIdGetDatum(constrrelid); values[Anum_pg_trigger_tgconstrindid - 1] = ObjectIdGetDatum(indexOid); values[Anum_pg_trigger_tgconstraint - 1] = ObjectIdGetDatum(constraintOid); diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 463639208d..04850bd8b4 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -7444,7 +7444,7 @@ getTriggers(Archive *fout, TableInfo tblinfo[], int numTables) tbinfo->dobj.name); resetPQExpBuffer(query); - if (fout->remoteVersion >= 90000) + if (fout->remoteVersion >= 110000) { /* * NB: think not to use pretty=true in pg_get_triggerdef. It @@ -7458,6 +7458,18 @@ getTriggers(Archive *fout, TableInfo tblinfo[], int numTables) "tgenabled, tableoid, oid " "FROM pg_catalog.pg_trigger t " "WHERE tgrelid = '%u'::pg_catalog.oid " + "AND NOT tgisinternal AND NOT tginpartition", + tbinfo->dobj.catId.oid); + } + else if (fout->remoteVersion >= 90000) + { + appendPQExpBuffer(query, + "SELECT tgname, " + "tgfoid::pg_catalog.regproc AS tgfname, " + "pg_catalog.pg_get_triggerdef(oid, false) AS tgdef, " + "tgenabled, tableoid, oid " + "FROM pg_catalog.pg_trigger t " + "WHERE tgrelid = '%u'::pg_catalog.oid " "AND NOT tgisinternal", tbinfo->dobj.catId.oid); } diff --git a/src/include/catalog/pg_trigger.h b/src/include/catalog/pg_trigger.h index 951d7d86e7..02b8718a8f 100644 --- a/src/include/catalog/pg_trigger.h +++ b/src/include/catalog/pg_trigger.h @@ -41,6 +41,7 @@ CATALOG(pg_trigger,2620,TriggerRelationId) char tgenabled; /* trigger's firing configuration WRT * session_replication_role */ bool tgisinternal; /* trigger is system-generated */ + bool tginpartition; /* trigger is a clone in a partition */ Oid tgconstrrelid; /* constraint's FROM table, if any */ Oid tgconstrindid; /* constraint's supporting index, if any */ Oid tgconstraint; /* associated pg_constraint entry, if any */