mirror of
https://github.com/postgres/postgres.git
synced 2025-07-17 06:41:09 +03:00
Add ALTER VIEW ... RENAME TO, and a RENAME TO clause to ALTER SEQUENCE.
Sequences and views could previously be renamed using ALTER TABLE, but this was a repeated source of confusion for users. Update the docs, and psql tab completion. Patch from David Fetter; various minor fixes by myself.
This commit is contained in:
@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/commands/alter.c,v 1.23 2007/03/26 16:58:38 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/commands/alter.c,v 1.24 2007/07/03 01:30:36 neilc Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -83,6 +83,8 @@ ExecRenameStmt(RenameStmt *stmt)
|
||||
break;
|
||||
|
||||
case OBJECT_TABLE:
|
||||
case OBJECT_SEQUENCE:
|
||||
case OBJECT_VIEW:
|
||||
case OBJECT_INDEX:
|
||||
case OBJECT_COLUMN:
|
||||
case OBJECT_TRIGGER:
|
||||
@ -96,6 +98,8 @@ ExecRenameStmt(RenameStmt *stmt)
|
||||
switch (stmt->renameType)
|
||||
{
|
||||
case OBJECT_TABLE:
|
||||
case OBJECT_SEQUENCE:
|
||||
case OBJECT_VIEW:
|
||||
case OBJECT_INDEX:
|
||||
{
|
||||
/*
|
||||
@ -113,7 +117,7 @@ ExecRenameStmt(RenameStmt *stmt)
|
||||
aclcheck_error(aclresult, ACL_KIND_NAMESPACE,
|
||||
get_namespace_name(namespaceId));
|
||||
|
||||
renamerel(relid, stmt->newname);
|
||||
renamerel(relid, stmt->newname, stmt->renameType);
|
||||
break;
|
||||
}
|
||||
case OBJECT_COLUMN:
|
||||
|
@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.228 2007/06/23 22:12:50 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.229 2007/07/03 01:30:36 neilc Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -41,6 +41,7 @@
|
||||
#include "executor/executor.h"
|
||||
#include "miscadmin.h"
|
||||
#include "nodes/makefuncs.h"
|
||||
#include "nodes/parsenodes.h"
|
||||
#include "optimizer/clauses.h"
|
||||
#include "optimizer/plancat.h"
|
||||
#include "optimizer/prep.h"
|
||||
@ -1621,7 +1622,7 @@ renameatt(Oid myrelid,
|
||||
* sequence, AFAIK there's no need for it to be there.
|
||||
*/
|
||||
void
|
||||
renamerel(Oid myrelid, const char *newrelname)
|
||||
renamerel(Oid myrelid, const char *newrelname, ObjectType reltype)
|
||||
{
|
||||
Relation targetrelation;
|
||||
Relation relrelation; /* for RELATION relation */
|
||||
@ -1633,8 +1634,8 @@ renamerel(Oid myrelid, const char *newrelname)
|
||||
bool relhastriggers;
|
||||
|
||||
/*
|
||||
* Grab an exclusive lock on the target table or index, which we will NOT
|
||||
* release until end of transaction.
|
||||
* Grab an exclusive lock on the target table, index, sequence or
|
||||
* view, which we will NOT release until end of transaction.
|
||||
*/
|
||||
targetrelation = relation_open(myrelid, AccessExclusiveLock);
|
||||
|
||||
@ -1647,7 +1648,24 @@ renamerel(Oid myrelid, const char *newrelname)
|
||||
errmsg("permission denied: \"%s\" is a system catalog",
|
||||
RelationGetRelationName(targetrelation))));
|
||||
|
||||
/*
|
||||
* For compatibility with prior releases, we don't complain if
|
||||
* ALTER TABLE or ALTER INDEX is used to rename a sequence or
|
||||
* view.
|
||||
*/
|
||||
relkind = targetrelation->rd_rel->relkind;
|
||||
if (reltype == OBJECT_SEQUENCE && relkind != 'S')
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
|
||||
errmsg("\"%s\" is not a sequence",
|
||||
RelationGetRelationName(targetrelation))));
|
||||
|
||||
if (reltype == OBJECT_VIEW && relkind != 'v')
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
|
||||
errmsg("\"%s\" is not a view",
|
||||
RelationGetRelationName(targetrelation))));
|
||||
|
||||
relhastriggers = (targetrelation->rd_rel->reltriggers > 0);
|
||||
|
||||
/*
|
||||
|
Reference in New Issue
Block a user