aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands/tablecmds.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2007-05-12 00:55:00 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2007-05-12 00:55:00 +0000
commit9aa3c782c939f29bd562a22030fb3a64e6f18365 (patch)
treec02802067d14db9573f6c4e0350ec91b5d503283 /src/backend/commands/tablecmds.c
parentd8326119c8885e938eff79e22fce6c1cb19379f4 (diff)
downloadpostgresql-9aa3c782c939f29bd562a22030fb3a64e6f18365.tar.gz
postgresql-9aa3c782c939f29bd562a22030fb3a64e6f18365.zip
Fix the problem that creating a user-defined type named _foo, followed by one
named foo, would work but the other ordering would not. If a user-specified type or table name collides with an existing auto-generated array name, just rename the array type out of the way by prepending more underscores. This should not create any backward-compatibility issues, since the cases in which this will happen would have failed outright in prior releases. Also fix an oversight in the arrays-of-composites patch: ALTER TABLE RENAME renamed the table's rowtype but not its array type.
Diffstat (limited to 'src/backend/commands/tablecmds.c')
-rw-r--r--src/backend/commands/tablecmds.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index eecd4943ae6..ee658056ec5 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.221 2007/05/11 20:16:36 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.222 2007/05/12 00:54:59 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -1626,6 +1626,7 @@ renamerel(Oid myrelid, const char *newrelname)
Relation targetrelation;
Relation relrelation; /* for RELATION relation */
HeapTuple reltup;
+ Form_pg_class relform;
Oid namespaceId;
char *oldrelname;
char relkind;
@@ -1655,10 +1656,11 @@ renamerel(Oid myrelid, const char *newrelname)
relrelation = heap_open(RelationRelationId, RowExclusiveLock);
reltup = SearchSysCacheCopy(RELOID,
- PointerGetDatum(myrelid),
+ ObjectIdGetDatum(myrelid),
0, 0, 0);
if (!HeapTupleIsValid(reltup)) /* shouldn't happen */
elog(ERROR, "cache lookup failed for relation %u", myrelid);
+ relform = (Form_pg_class) GETSTRUCT(reltup);
if (get_relname_relid(newrelname, namespaceId) != InvalidOid)
ereport(ERROR,
@@ -1670,7 +1672,7 @@ renamerel(Oid myrelid, const char *newrelname)
* Update pg_class tuple with new relname. (Scribbling on reltup is OK
* because it's a copy...)
*/
- namestrcpy(&(((Form_pg_class) GETSTRUCT(reltup))->relname), newrelname);
+ namestrcpy(&(relform->relname), newrelname);
simple_heap_update(relrelation, &reltup->t_self, reltup);
@@ -1683,8 +1685,8 @@ renamerel(Oid myrelid, const char *newrelname)
/*
* Also rename the associated type, if any.
*/
- if (relkind != RELKIND_INDEX)
- TypeRename(oldrelname, namespaceId, newrelname);
+ if (OidIsValid(targetrelation->rd_rel->reltype))
+ TypeRename(targetrelation->rd_rel->reltype, newrelname, namespaceId);
/*
* Close rel, but keep exclusive lock!