diff options
Diffstat (limited to 'src/backend/commands')
-rw-r--r-- | src/backend/commands/alter.c | 6 | ||||
-rw-r--r-- | src/backend/commands/tablecmds.c | 73 |
2 files changed, 75 insertions, 4 deletions
diff --git a/src/backend/commands/alter.c b/src/backend/commands/alter.c index 63acefa527d..fce328bcc40 100644 --- a/src/backend/commands/alter.c +++ b/src/backend/commands/alter.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/commands/alter.c,v 1.28 2008/03/19 18:38:30 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/commands/alter.c,v 1.29 2008/06/15 01:25:53 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -185,8 +185,10 @@ ExecAlterObjectSchemaStmt(AlterObjectSchemaStmt *stmt) case OBJECT_SEQUENCE: case OBJECT_TABLE: + case OBJECT_VIEW: CheckRelationOwnership(stmt->relation, true); - AlterTableNamespace(stmt->relation, stmt->newschema); + AlterTableNamespace(stmt->relation, stmt->newschema, + stmt->objectType); break; case OBJECT_TYPE: diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 7f7102858b1..b3d21875b25 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.256 2008/06/14 18:04:33 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.257 2008/06/15 01:25:53 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -2175,6 +2175,44 @@ AlterTable(AlterTableStmt *stmt) CheckTableNotInUse(rel, "ALTER TABLE"); + /* Check relation type against type specified in the ALTER command */ + switch (stmt->relkind) + { + case OBJECT_TABLE: + /* + * For mostly-historical reasons, we allow ALTER TABLE to apply + * to all relation types. + */ + break; + + case OBJECT_INDEX: + if (rel->rd_rel->relkind != RELKIND_INDEX) + ereport(ERROR, + (errcode(ERRCODE_WRONG_OBJECT_TYPE), + errmsg("\"%s\" is not an index", + RelationGetRelationName(rel)))); + break; + + case OBJECT_SEQUENCE: + if (rel->rd_rel->relkind != RELKIND_SEQUENCE) + ereport(ERROR, + (errcode(ERRCODE_WRONG_OBJECT_TYPE), + errmsg("\"%s\" is not a sequence", + RelationGetRelationName(rel)))); + break; + + case OBJECT_VIEW: + if (rel->rd_rel->relkind != RELKIND_VIEW) + ereport(ERROR, + (errcode(ERRCODE_WRONG_OBJECT_TYPE), + errmsg("\"%s\" is not a view", + RelationGetRelationName(rel)))); + break; + + default: + elog(ERROR, "unrecognized object type: %d", (int) stmt->relkind); + } + ATController(rel, stmt->cmds, interpretInhOption(stmt->relation->inhOpt)); } @@ -7191,7 +7229,8 @@ ATExecDropInherit(Relation rel, RangeVar *parent) * Note: caller must have checked ownership of the relation already */ void -AlterTableNamespace(RangeVar *relation, const char *newschema) +AlterTableNamespace(RangeVar *relation, const char *newschema, + ObjectType stmttype) { Relation rel; Oid relid; @@ -7204,6 +7243,36 @@ AlterTableNamespace(RangeVar *relation, const char *newschema) relid = RelationGetRelid(rel); oldNspOid = RelationGetNamespace(rel); + /* Check relation type against type specified in the ALTER command */ + switch (stmttype) + { + case OBJECT_TABLE: + /* + * For mostly-historical reasons, we allow ALTER TABLE to apply + * to all relation types. + */ + break; + + case OBJECT_SEQUENCE: + if (rel->rd_rel->relkind != RELKIND_SEQUENCE) + ereport(ERROR, + (errcode(ERRCODE_WRONG_OBJECT_TYPE), + errmsg("\"%s\" is not a sequence", + RelationGetRelationName(rel)))); + break; + + case OBJECT_VIEW: + if (rel->rd_rel->relkind != RELKIND_VIEW) + ereport(ERROR, + (errcode(ERRCODE_WRONG_OBJECT_TYPE), + errmsg("\"%s\" is not a view", + RelationGetRelationName(rel)))); + break; + + default: + elog(ERROR, "unrecognized object type: %d", (int) stmttype); + } + /* Can we change the schema of this tuple? */ switch (rel->rd_rel->relkind) { |