*** pgsql.orig/src/backend/parser/analyze.c Fri Oct 6 17:58:17 2000 --- pgsql/src/backend/parser/analyze.c Mon Oct 30 21:45:29 2000 *************** *** 965,970 **** --- 965,971 ---- foreach(keys, constraint->keys) { + int found=0; key = (Ident *) lfirst(keys); Assert(IsA(key, Ident)); column = NULL; *************** *** 975,988 **** if (strcmp(column->colname, key->name) == 0) break; } ! if (columns == NIL) /* fell off end of list? */ elog(ERROR, "CREATE TABLE: column '%s' named in key does not exist", key->name); if (constraint->contype == CONSTR_PRIMARY) column->is_not_null = TRUE; iparam = makeNode(IndexElem); ! iparam->name = pstrdup(column->colname); iparam->args = NIL; iparam->class = NULL; index->indexParams = lappend(index->indexParams, iparam); --- 976,1019 ---- if (strcmp(column->colname, key->name) == 0) break; } ! if (columns == NIL) { /* try inherited tables */ ! List *inher; ! List *inhRelnames=stmt->inhRelnames; ! Relation rel; ! foreach (inher, inhRelnames) { ! int count=0; ! Value *inh=lfirst(inher); ! if (inh->type!=T_String) { ! elog(ERROR, "inherited table name list returns a non-string"); ! } ! rel=heap_openr(inh->val.str, AccessShareLock); ! if (rel->rd_rel->relkind != RELKIND_RELATION) ! elog(ERROR, "inherited table \"%s\" is not a relation", ! inh->val.str); ! for (; countrd_att->natts; count++) { ! char *name=NameStr(rel->rd_att->attrs[count]->attname); ! if (strcmp(key->name, name) == 0) { ! found=1; ! break; ! } ! } ! heap_close(rel, NoLock); ! if (found) ! break; ! } ! } ! else { ! found=1; ! } ! ! if (!found) elog(ERROR, "CREATE TABLE: column '%s' named in key does not exist", key->name); if (constraint->contype == CONSTR_PRIMARY) column->is_not_null = TRUE; iparam = makeNode(IndexElem); ! iparam->name = pstrdup(key->name); iparam->args = NIL; iparam->class = NULL; index->indexParams = lappend(index->indexParams, iparam); *************** *** 1112,1119 **** if (!found) break; } if (!found) ! elog(ERROR, "columns referenced in foreign key constraint not found."); } /* --- 1143,1179 ---- if (!found) break; } + if (!found) { /* try inherited tables */ + List *inher; + List *inhRelnames=stmt->inhRelnames; + Relation rel; + foreach (inher, inhRelnames) { + int count=0; + Value *inh=lfirst(inher); + if (inh->type!=T_String) { + elog(ERROR, "inherited table name list returns a non-string"); + } + rel=heap_openr(inh->val.str, AccessShareLock); + if (rel->rd_rel->relkind != RELKIND_RELATION) + elog(ERROR, "inherited table \"%s\" is not a relation", + inh->val.str); + for (; countrd_att->natts; count++) { + char *name=NameStr(rel->rd_att->attrs[count]->attname); + if (strcmp(fkattr->name, name) == 0) { + found=1; + break; + } + } + heap_close(rel, NoLock); + if (found) + break; + } + } + else { + found=1; + } if (!found) ! elog(ERROR, "columns in foreign key table of constraint not found."); } /*