88 *
99 *
1010 * IDENTIFICATION
11- * $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.228 2007/06/23 22:12:50 tgl Exp $
11+ * $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.229 2007/07/03 01:30:36 neilc Exp $
1212 *
1313 *-------------------------------------------------------------------------
1414 */
4141#include "executor/executor.h"
4242#include "miscadmin.h"
4343#include "nodes/makefuncs.h"
44+ #include "nodes/parsenodes.h"
4445#include "optimizer/clauses.h"
4546#include "optimizer/plancat.h"
4647#include "optimizer/prep.h"
@@ -1621,7 +1622,7 @@ renameatt(Oid myrelid,
16211622 * sequence, AFAIK there's no need for it to be there.
16221623 */
16231624void
1624- renamerel (Oid myrelid ,const char * newrelname )
1625+ renamerel (Oid myrelid ,const char * newrelname , ObjectType reltype )
16251626{
16261627Relation targetrelation ;
16271628Relation relrelation ;/* for RELATION relation */
@@ -1633,8 +1634,8 @@ renamerel(Oid myrelid, const char *newrelname)
16331634bool relhastriggers ;
16341635
16351636/*
1636- * Grab an exclusive lock on the target table or index,which we will NOT
1637- * release until end of transaction.
1637+ * Grab an exclusive lock on the target table, index,sequence or
1638+ *view, which we will NOT release until end of transaction.
16381639 */
16391640targetrelation = relation_open (myrelid ,AccessExclusiveLock );
16401641
@@ -1647,7 +1648,24 @@ renamerel(Oid myrelid, const char *newrelname)
16471648errmsg ("permission denied: \"%s\" is a system catalog" ,
16481649RelationGetRelationName (targetrelation ))));
16491650
1651+ /*
1652+ * For compatibility with prior releases, we don't complain if
1653+ * ALTER TABLE or ALTER INDEX is used to rename a sequence or
1654+ * view.
1655+ */
16501656relkind = targetrelation -> rd_rel -> relkind ;
1657+ if (reltype == OBJECT_SEQUENCE && relkind != 'S' )
1658+ ereport (ERROR ,
1659+ (errcode (ERRCODE_WRONG_OBJECT_TYPE ),
1660+ errmsg ("\"%s\" is not a sequence" ,
1661+ RelationGetRelationName (targetrelation ))));
1662+
1663+ if (reltype == OBJECT_VIEW && relkind != 'v' )
1664+ ereport (ERROR ,
1665+ (errcode (ERRCODE_WRONG_OBJECT_TYPE ),
1666+ errmsg ("\"%s\" is not a view" ,
1667+ RelationGetRelationName (targetrelation ))));
1668+
16511669relhastriggers = (targetrelation -> rd_rel -> reltriggers > 0 );
16521670
16531671/*