Index: src/backend/commands/tablecmds.c =================================================================== RCS file: /projects/cvsroot/pgsql-server/src/backend/commands/tablecmds.c,v retrieving revision 1.48 diff -c -r1.48 tablecmds.c *** src/backend/commands/tablecmds.c 2002/10/19 03:01:09 1.48 --- src/backend/commands/tablecmds.c 2002/10/19 05:40:39 *************** *** 1584,1590 **** void AlterTableAddColumn(Oid myrelid, bool recurse, - bool recursing, ColumnDef *colDef) { Relation rel, --- 1584,1589 ---- *************** *** 1643,1664 **** colDefChild->inhcount = 1; colDefChild->is_local = false; ! /* 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); if (childrelid == myrelid) continue; ! AlterTableAddColumn(childrelid, false, true, colDefChild); } } else --- 1642,1691 ---- colDefChild->inhcount = 1; colDefChild->is_local = false; ! /* We only want direct inheritors */ ! children = find_inheritance_children(myrelid); foreach(child, children) { Oid childrelid = lfirsti(child); + HeapTuple tuple; + Form_pg_attribute childatt; + Relation childrel; if (childrelid == myrelid) continue; + + attrdesc = heap_openr(AttributeRelationName, RowExclusiveLock); + tuple = SearchSysCacheCopyAttName(childrelid, colDef->colname); + if (!HeapTupleIsValid(tuple)) + { + heap_close(attrdesc, RowExclusiveLock); + AlterTableAddColumn(childrelid, true, colDefChild); + continue; + } + childatt = (Form_pg_attribute) GETSTRUCT(tuple); + + typeTuple = typenameType(colDef->typename); ! if (HeapTupleGetOid(typeTuple) != childatt->atttypid || ! colDef->typename->typmod != childatt->atttypmod) ! elog(ERROR, "ALTER TABLE: child table %u has different " ! "type for column \"%s\"", ! childrelid, colDef->colname); ! ! childatt->attinhcount++; ! simple_heap_update(attrdesc, &tuple->t_self, tuple); ! CatalogUpdateIndexes(attrdesc, tuple); ! ! childrel = RelationIdGetRelation(childrelid); ! elog(NOTICE, "ALTER TABLE: merging definition of column " ! "\"%s\" for child %s", colDef->colname, ! RelationGetRelationName(childrel)); ! RelationClose(childrel); ! ! heap_close(attrdesc, RowExclusiveLock); ! heap_freetuple(tuple); ! ReleaseSysCache(typeTuple); } } else *************** *** 1667,1674 **** * If we are told not to recurse, there had better not be any * child tables; else the addition would put them out of step. */ ! if (!recursing && ! find_inheritance_children(myrelid) != NIL) elog(ERROR, "Attribute must be added to child tables too"); } --- 1694,1700 ---- * If we are told not to recurse, there had better not be any * child tables; else the addition would put them out of step. */ ! if (find_inheritance_children(myrelid) != NIL) elog(ERROR, "Attribute must be added to child tables too"); } Index: src/backend/tcop/utility.c =================================================================== RCS file: /projects/cvsroot/pgsql-server/src/backend/tcop/utility.c,v retrieving revision 1.179 diff -c -r1.179 utility.c *** src/backend/tcop/utility.c 2002/10/08 17:17:19 1.179 --- src/backend/tcop/utility.c 2002/10/19 05:40:44 *************** *** 475,481 **** */ AlterTableAddColumn(relid, interpretInhOption(stmt->relation->inhOpt), - false, (ColumnDef *) stmt->def); break; case 'T': /* ALTER COLUMN DEFAULT */ --- 475,480 ---- Index: src/include/commands/tablecmds.h =================================================================== RCS file: /projects/cvsroot/pgsql-server/src/include/commands/tablecmds.h,v retrieving revision 1.7 diff -c -r1.7 tablecmds.h *** src/include/commands/tablecmds.h 2002/09/04 20:31:42 1.7 --- src/include/commands/tablecmds.h 2002/10/19 05:40:50 *************** *** 16,23 **** #include "nodes/parsenodes.h" ! extern void AlterTableAddColumn(Oid myrelid, bool recurse, bool recursing, ! ColumnDef *colDef); extern void AlterTableAlterColumnDropNotNull(Oid myrelid, bool recurse, const char *colName); --- 16,22 ---- #include "nodes/parsenodes.h" ! extern void AlterTableAddColumn(Oid myrelid, bool recurse, ColumnDef *colDef); extern void AlterTableAlterColumnDropNotNull(Oid myrelid, bool recurse, const char *colName); Index: src/test/regress/output/misc.source =================================================================== RCS file: /projects/cvsroot/pgsql-server/src/test/regress/output/misc.source,v retrieving revision 1.33 diff -c -r1.33 misc.source *** src/test/regress/output/misc.source 2002/03/21 16:02:16 1.33 --- src/test/regress/output/misc.source 2002/10/19 05:40:55 *************** *** 373,378 **** --- 373,379 ---- (23 rows) ALTER TABLE a_star* ADD COLUMN a text; + NOTICE: ALTER TABLE: merging definition of column "a" for child d_star --UPDATE b_star* -- SET a = text 'gazpacho' -- WHERE aa > 4;