diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2002-12-16 18:39:57 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2002-12-16 18:39:57 +0000 |
commit | f599d56f5196f25cc128c7fabe9f087773b9c390 (patch) | |
tree | 2374c475c517e9b4b322e8474cba8b9326c98343 /src/backend/commands/tablecmds.c | |
parent | 750b3f38255d3e9c5e6021a74224659d18533e1c (diff) | |
download | postgresql-f599d56f5196f25cc128c7fabe9f087773b9c390.tar.gz postgresql-f599d56f5196f25cc128c7fabe9f087773b9c390.zip |
Fix ALTER TABLE ADD COLUMN to disallow the same column types that are
disallowed by CREATE TABLE (eg, pseudo-types); also disallow these types
from being introduced by the range-function syntax. While at it, allow
CREATE TABLE to create zero-column tables, per recent pghackers discussion.
I am back-patching this into 7.3 since failure to disallow pseudo-types
is arguably a security hole.
Diffstat (limited to 'src/backend/commands/tablecmds.c')
-rw-r--r-- | src/backend/commands/tablecmds.c | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 62d61b315c6..46d9b709398 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.51 2002/11/02 22:02:08 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/commands/tablecmds.c,v 1.51.2.1 2002/12/16 18:39:56 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -104,7 +104,6 @@ DefineRelation(CreateStmt *stmt, char relkind) char relname[NAMEDATALEN]; Oid namespaceId; List *schema = stmt->tableElts; - int numberOfAttributes; Oid relationId; Relation rel; TupleDesc descriptor; @@ -147,10 +146,6 @@ DefineRelation(CreateStmt *stmt, char relkind) stmt->relation->istemp, &inheritOids, &old_constraints, &parentHasOids); - numberOfAttributes = length(schema); - if (numberOfAttributes <= 0) - elog(ERROR, "DefineRelation: please inherit from a relation or define an attribute"); - /* * Create a relation descriptor from the relation schema and create * the relation. Note that in this stage only inherited (pre-cooked) @@ -1784,6 +1779,9 @@ AlterTableAddColumn(Oid myrelid, typeTuple = typenameType(colDef->typename); tform = (Form_pg_type) GETSTRUCT(typeTuple); + /* make sure datatype is legal for a column */ + CheckAttributeType(colDef->colname, HeapTupleGetOid(typeTuple)); + attributeTuple = heap_addheader(Natts_pg_attribute, false, ATTRIBUTE_TUPLE_SIZE, |