diff options
author | Bruce Momjian <bruce@momjian.us> | 2001-05-30 13:00:03 +0000 |
---|---|---|
committer | Bruce Momjian <bruce@momjian.us> | 2001-05-30 13:00:03 +0000 |
commit | 7160c86ec22229ff9dac145640d13f82d93fe059 (patch) | |
tree | b3fcde4b027a8f06126cd755cdf535234841d066 /src/backend/commands/command.c | |
parent | 3f5563d131b7cad95acd2df3f13b92afa4f3897e (diff) | |
download | postgresql-7160c86ec22229ff9dac145640d13f82d93fe059.tar.gz postgresql-7160c86ec22229ff9dac145640d13f82d93fe059.zip |
These patches should fix check constraints not inheriting
when added by alter table add constraint. The first file
patches backend/commands/command.c and the latter is a patch
to the alter table regression test.
Stephan Szabo
Diffstat (limited to 'src/backend/commands/command.c')
-rw-r--r-- | src/backend/commands/command.c | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/src/backend/commands/command.c b/src/backend/commands/command.c index 5f799199ed7..b6e745c4656 100644 --- a/src/backend/commands/command.c +++ b/src/backend/commands/command.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/commands/Attic/command.c,v 1.130 2001/05/30 12:57:36 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/commands/Attic/command.c,v 1.131 2001/05/30 13:00:03 momjian Exp $ * * NOTES * The PerformAddAttribute() code, like most of the relation @@ -1215,6 +1215,7 @@ AlterTableAddConstraint(char *relationName, Relation rel; Node *expr; char *name; + Oid myrelid; if (constr->name) name = constr->name; @@ -1224,6 +1225,7 @@ AlterTableAddConstraint(char *relationName, constlist = makeList1(constr); rel = heap_openr(relationName, AccessExclusiveLock); + myrelid = RelationGetRelid(rel); /* make sure it is not a view */ if (rel->rd_rel->relkind == RELKIND_VIEW) @@ -1318,6 +1320,35 @@ AlterTableAddConstraint(char *relationName, */ AddRelationRawConstraints(rel, NIL, constlist); heap_close(rel, NoLock); + + if (inh) { + List *child, + *children; + + /* this routine is actually in the planner */ + children = find_all_inheritors(myrelid); + + /* + * find_all_inheritors does the recursive search of the + * inheritance hierarchy, so all we have to do is process all + * of the relids in the list that it returns. + */ + foreach(child, children) + { + Oid childrelid = lfirsti(child); + char *childrelname; + + if (childrelid == myrelid) + continue; + rel = heap_open(childrelid, AccessExclusiveLock); + childrelname = pstrdup(RelationGetRelationName(rel)); + heap_close(rel, AccessExclusiveLock); + + AlterTableAddConstraint(childrelname, false, newConstraint); + + pfree(childrelname); + } + } pfree(constlist); break; |