1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-07 19:06:32 +03:00

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
This commit is contained in:
Bruce Momjian
2001-05-30 13:00:03 +00:00
parent 3f5563d131
commit 7160c86ec2
3 changed files with 180 additions and 1 deletions

View File

@@ -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;