From 6d0d15c451739396851d3f93f81c63a47535bf1e Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Sat, 28 Sep 2002 20:00:19 +0000 Subject: Make the world at least somewhat safe for zero-column tables, and remove the special case in ALTER DROP COLUMN to prohibit dropping a table's last column. --- src/backend/commands/tablecmds.c | 29 +++-------------------------- 1 file changed, 3 insertions(+), 26 deletions(-) (limited to 'src/backend/commands/tablecmds.c') diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 0934a274c7a..14d82630c8a 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/commands/tablecmds.c,v 1.44 2002/09/23 20:43:40 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/commands/tablecmds.c,v 1.45 2002/09/28 20:00:19 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -2331,9 +2331,7 @@ AlterTableDropColumn(Oid myrelid, bool recurse, bool recursing, { Relation rel; AttrNumber attnum; - AttrNumber n; TupleDesc tupleDesc; - bool success; ObjectAddress object; rel = heap_open(myrelid, AccessExclusiveLock); @@ -2359,34 +2357,13 @@ AlterTableDropColumn(Oid myrelid, bool recurse, bool recursing, RelationGetRelationName(rel), colName); /* Can't drop a system attribute */ + /* XXX perhaps someday allow dropping OID? */ if (attnum < 0) elog(ERROR, "ALTER TABLE: Cannot drop system attribute \"%s\"", colName); - /* - * Make sure there will be at least one user column left in the - * relation after we drop this one. Zero-length tuples tend to - * confuse us. - */ - tupleDesc = RelationGetDescr(rel); - - success = false; - for (n = 1; n <= tupleDesc->natts; n++) - { - Form_pg_attribute attribute = tupleDesc->attrs[n - 1]; - - if (!attribute->attisdropped && n != attnum) - { - success = true; - break; - } - } - - if (!success) - elog(ERROR, "ALTER TABLE: Cannot drop last column from table \"%s\"", - RelationGetRelationName(rel)); - /* Don't drop inherited columns */ + tupleDesc = RelationGetDescr(rel); if (tupleDesc->attrs[attnum - 1]->attinhcount > 0 && !recursing) elog(ERROR, "ALTER TABLE: Cannot drop inherited column \"%s\"", colName); -- cgit v1.2.3