diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index a553583c34e..4700e09db42 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -5781,6 +5781,9 @@ getTriggers(Archive *fout, TableInfo tblinfo[], int numTables) tginfo = (TriggerInfo *) pg_malloc(ntups * sizeof(TriggerInfo)); + tbinfo->numTriggers = ntups; + tbinfo->triggers = tginfo; + for (j = 0; j < ntups; j++) { tginfo[j].dobj.objType = DO_TRIGGER; diff --git a/src/bin/pg_dump/pg_dump.h b/src/bin/pg_dump/pg_dump.h index 1e2a00d7a2c..7d589e6cc56 100644 --- a/src/bin/pg_dump/pg_dump.h +++ b/src/bin/pg_dump/pg_dump.h @@ -287,6 +287,8 @@ typedef struct _tableInfo int numParents; /* number of (immediate) parent tables */ struct _tableInfo **parents; /* TableInfos of immediate parents */ struct _tableDataInfo *dataObj; /* TableDataInfo, if dumping its data */ + int numTriggers; /* number of triggers for table */ + struct _triggerInfo *triggers; /* array of TriggerInfo structs */ } TableInfo; typedef struct _attrDefInfo diff --git a/src/bin/pg_dump/pg_dump_sort.c b/src/bin/pg_dump/pg_dump_sort.c index b56a8b347e3..52b89cea283 100644 --- a/src/bin/pg_dump/pg_dump_sort.c +++ b/src/bin/pg_dump/pg_dump_sort.c @@ -878,6 +878,7 @@ repairViewRuleMultiLoop(DumpableObject *viewobj, { TableInfo *viewinfo = (TableInfo *) viewobj; RuleInfo *ruleinfo = (RuleInfo *) ruleobj; + int i; /* remove view's dependency on rule */ removeObjectDependency(viewobj, ruleobj->dumpId); @@ -895,6 +896,9 @@ repairViewRuleMultiLoop(DumpableObject *viewobj, addObjectDependency(ruleobj, viewobj->dumpId); /* now that rule is separate, it must be post-data */ addObjectDependency(ruleobj, postDataBoundId); + /* also, any triggers on the view must be dumped after the rule */ + for (i = 0; i < viewinfo->numTriggers; i++) + addObjectDependency(&(viewinfo->triggers[i].dobj), ruleobj->dumpId); } /*