8
8
*
9
9
*
10
10
* 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 $
12
12
*
13
13
*-------------------------------------------------------------------------
14
14
*/
41
41
#include "executor/executor.h"
42
42
#include "miscadmin.h"
43
43
#include "nodes/makefuncs.h"
44
+ #include "nodes/parsenodes.h"
44
45
#include "optimizer/clauses.h"
45
46
#include "optimizer/plancat.h"
46
47
#include "optimizer/prep.h"
@@ -1621,7 +1622,7 @@ renameatt(Oid myrelid,
1621
1622
* sequence, AFAIK there's no need for it to be there.
1622
1623
*/
1623
1624
void
1624
- renamerel (Oid myrelid , const char * newrelname )
1625
+ renamerel (Oid myrelid , const char * newrelname , ObjectType reltype )
1625
1626
{
1626
1627
Relation targetrelation ;
1627
1628
Relation relrelation ; /* for RELATION relation */
@@ -1633,8 +1634,8 @@ renamerel(Oid myrelid, const char *newrelname)
1633
1634
bool relhastriggers ;
1634
1635
1635
1636
/*
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.
1638
1639
*/
1639
1640
targetrelation = relation_open (myrelid , AccessExclusiveLock );
1640
1641
@@ -1647,7 +1648,24 @@ renamerel(Oid myrelid, const char *newrelname)
1647
1648
errmsg ("permission denied: \"%s\" is a system catalog" ,
1648
1649
RelationGetRelationName (targetrelation ))));
1649
1650
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
+ */
1650
1656
relkind = 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
+
1651
1669
relhastriggers = (targetrelation -> rd_rel -> reltriggers > 0 );
1652
1670
1653
1671
/*
0 commit comments