*** postgresql-8.1.2-org/src/backend/commands/tablecmds.c 2005-11-23 03:23:07.000000000 +0900 --- postgresql-8.1.2/src/backend/commands/tablecmds.c 2006-01-30 09:43:13.000000000 +0900 *************** *** 4970,4979 **** Assert(foundObject.objectSubId == 0); if (!list_member_oid(tab->changedConstraintOids, foundObject.objectId)) { ! tab->changedConstraintOids = lappend_oid(tab->changedConstraintOids, ! foundObject.objectId); ! tab->changedConstraintDefs = lappend(tab->changedConstraintDefs, ! pg_get_constraintdef_string(foundObject.objectId)); } break; --- 4970,4996 ---- Assert(foundObject.objectSubId == 0); if (!list_member_oid(tab->changedConstraintOids, foundObject.objectId)) { ! char *defstring = pg_get_constraintdef_string(foundObject.objectId); ! ! /* FOREIGN KEY constraints depend on the indexes which depend on ! * PRIMARY KEY constraints, so we need to append FOREIGN KEY ! * constraints ahead of PRIMARY KEY constraints. We decide this ! * by the dependency type. ! */ ! if (foundDep->deptype == DEPENDENCY_NORMAL) ! { ! tab->changedConstraintOids = lcons_oid(foundObject.objectId, ! tab->changedConstraintOids); ! tab->changedConstraintDefs = lcons(defstring, ! tab->changedConstraintDefs); ! } ! else ! { ! tab->changedConstraintOids = lappend_oid(tab->changedConstraintOids, ! foundObject.objectId); ! tab->changedConstraintDefs = lappend(tab->changedConstraintDefs, ! defstring); ! } } break; *************** *** 5141,5149 **** /* * Now we can drop the existing constraints and indexes --- constraints ! * first, since some of them might depend on the indexes. It should be ! * okay to use DROP_RESTRICT here, since nothing else should be depending ! * on these objects. */ foreach(l, tab->changedConstraintOids) { --- 5158,5168 ---- /* * Now we can drop the existing constraints and indexes --- constraints ! * first, since some of them might depend on the indexes. (FOREIGN KEY ! * constraints depend on the indexes of PRIMARY KEY constraints, but ! * these will have DEPENDENCY_NORMAL type and will be deleted before ! * PRIMARY KEY constraints.) It should be okay to use DROP_RESTRICT here, ! * since nothing else should be depending on these objects. */ foreach(l, tab->changedConstraintOids) {