modified src/bin/pg_dump/pg_dump_sort.c @@ -300,6 +300,23 @@ DOTypeNameCompare(const void *p1, const void *p2) if (cmpval != 0) return cmpval; } + else if (obj1->objType == DO_FK_CONSTRAINT) + { + ConstraintInfo *cobj1 = *(ConstraintInfo *const *)p1; + ConstraintInfo *cobj2 = *(ConstraintInfo *const *)p2; + + if (cobj1->contable != NULL && cobj2->contable != NULL) { + /* Sort two FK constraints with the same name by their + * corresponding relationname: + */ + cmpval = strcmp( + cobj1->contable->dobj.name, + cobj2->contable->dobj.name); + if (cmpval != 0) + return cmpval; + } + } /* Usually shouldn't get here, but if we do, sort by OID */ return oidcmp(obj1->catId.oid, obj2->catId.oid);