Kohei KaiGai escribió:

> The attached patch is a revised version.
> 
> It follows the manner in ExecAlterObjectSchemaStmt(); that tries to check
> name duplication for object classes that support catcache with name-key.
> Elsewhere, it calls individual routines for each object class to solve object
> name and check namespace conflicts.
> For example, RenameFunction() is still called from ExecRenameStmt(),
> however, it looks up the given function name and checks namespace
> conflict only, then it just invokes AlterObjectRename_internal() in spite
> of system catalog updates by itself.
> It allows to use this consolidated routine by object classes with special
> rule for namespace conflicts, such as collation.
> In addition, this design allowed to eliminate get_object_type() to pull
> OBJECT_* enum from class_id/object_id pair.

I checked this patch.  It needed a rebase for the changes to return
OIDs.  Attached patch applies to current HEAD.  In general this looks
good, with one exception: it's using getObjectDescriptionOids() to build
the messages to complain in case the object already exists in the
current schema, which results in diffs like this:

-ERROR:  event trigger "regress_event_trigger2" already exists
+ERROR:  event trigger regress_event_trigger2 already exists

I don't know how tense we are about keeping the quotes, but I fear there
would be complaints because it took us lots of sweat, blood and tears to
get where we are now.

If this is considered a problem, I think the way to fix it is to have a
getObjectDescriptionOids() variant that quotes the object name in the
output.  This would be pretty intrusive: we'd have to change things
so that, for instance,

                appendStringInfo(&buffer, _("collation %s"),
                        NameStr(coll->collname));

would become

                if (quotes)
                        appendStringInfo(&buffer, _("collation \"%s\""),
                                NameStr(coll->collname));
                else
                        appendStringInfo(&buffer, _("collation %s"),
                                NameStr(coll->collname));

Not really thrilled with this idea.  Of course,
getObjectDescription() itself should keep the same API as now, to avoid
useless churn all over the place.

-- 
Álvaro Herrera                http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services
*** a/src/backend/commands/aggregatecmds.c
--- b/src/backend/commands/aggregatecmds.c
***************
*** 29,34 ****
--- 29,35 ----
  #include "catalog/pg_aggregate.h"
  #include "catalog/pg_proc.h"
  #include "catalog/pg_type.h"
+ #include "commands/alter.h"
  #include "commands/defrem.h"
  #include "miscadmin.h"
  #include "parser/parse_func.h"
***************
*** 240,254 **** RenameAggregate(List *name, List *args, const char *newname)
        HeapTuple       tup;
        Form_pg_proc procForm;
        Relation        rel;
-       AclResult       aclresult;
  
        rel = heap_open(ProcedureRelationId, RowExclusiveLock);
  
        /* Look up function and make sure it's an aggregate */
        procOid = LookupAggNameTypeNames(name, args, false);
  
!       tup = SearchSysCacheCopy1(PROCOID, ObjectIdGetDatum(procOid));
!       if (!HeapTupleIsValid(tup)) /* should not happen */
                elog(ERROR, "cache lookup failed for function %u", procOid);
        procForm = (Form_pg_proc) GETSTRUCT(tup);
  
--- 241,254 ----
        HeapTuple       tup;
        Form_pg_proc procForm;
        Relation        rel;
  
        rel = heap_open(ProcedureRelationId, RowExclusiveLock);
  
        /* Look up function and make sure it's an aggregate */
        procOid = LookupAggNameTypeNames(name, args, false);
  
!       tup = SearchSysCache1(PROCOID, ObjectIdGetDatum(procOid));
!       if (!HeapTupleIsValid(tup))     /* should not happen */
                elog(ERROR, "cache lookup failed for function %u", procOid);
        procForm = (Form_pg_proc) GETSTRUCT(tup);
  
***************
*** 268,291 **** RenameAggregate(List *name, List *args, const char *newname)
                                                                                
           procForm->proargtypes.values),
                                                
get_namespace_name(namespaceOid))));
  
!       /* must be owner */
!       if (!pg_proc_ownercheck(procOid, GetUserId()))
!               aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_PROC,
!                                          NameListToString(name));
! 
!       /* must have CREATE privilege on namespace */
!       aclresult = pg_namespace_aclcheck(namespaceOid, GetUserId(), 
ACL_CREATE);
!       if (aclresult != ACLCHECK_OK)
!               aclcheck_error(aclresult, ACL_KIND_NAMESPACE,
!                                          get_namespace_name(namespaceOid));
! 
!       /* rename */
!       namestrcpy(&(((Form_pg_proc) GETSTRUCT(tup))->proname), newname);
!       simple_heap_update(rel, &tup->t_self, tup);
!       CatalogUpdateIndexes(rel, tup);
  
        heap_close(rel, NoLock);
-       heap_freetuple(tup);
  
        return procOid;
  }
--- 268,278 ----
                                                                                
           procForm->proargtypes.values),
                                                
get_namespace_name(namespaceOid))));
  
!       /* OK, do the work */
!       AlterObjectRename_internal(rel, procOid, newname);
  
+       ReleaseSysCache(tup);
        heap_close(rel, NoLock);
  
        return procOid;
  }
*** a/src/backend/commands/alter.c
--- b/src/backend/commands/alter.c
***************
*** 36,41 ****
--- 36,42 ----
  #include "commands/trigger.h"
  #include "commands/typecmds.h"
  #include "commands/user.h"
+ #include "parser/parse_func.h"
  #include "miscadmin.h"
  #include "tcop/utility.h"
  #include "utils/builtins.h"
***************
*** 45,50 ****
--- 46,190 ----
  #include "utils/syscache.h"
  #include "utils/tqual.h"
  
+ /*
+  * AlterObjectRename_internal
+  *
+  * Generic function to rename the given object, for simple cases (won't
+  * work for tables, nor other cases where we need to do more than change
+  * the name column of a single catalog entry).
+  * It checks name duplication only when catalog cache by name as key is
+  * available. Otherwise, the caller should ensure here is no object with
+  * identical name.
+  *
+  * rel: catalog relation containing object (RowExclusiveLock'd by caller)
+  * objectId: OID of object to be renamed
+  * new_name: CString representation of new name
+  */
+ void
+ AlterObjectRename_internal(Relation rel, Oid objectId, const char *new_name)
+ {
+       Oid                     classId = RelationGetRelid(rel);
+       int                     oidCacheId = get_object_catcache_oid(classId);
+       int                     nameCacheId = get_object_catcache_name(classId);
+       AttrNumber      Anum_name = get_object_attnum_name(classId);
+       AttrNumber      Anum_namespace = get_object_attnum_namespace(classId);
+       AttrNumber      Anum_owner = get_object_attnum_owner(classId);
+       AclObjectKind acl_kind = get_object_aclkind(classId);
+       HeapTuple       oldtup;
+       HeapTuple       newtup;
+       Datum           datum;
+       bool            isnull;
+       Oid                     namespaceId;
+       Oid                     ownerId;
+       char       *old_name;
+       AclResult       aclresult;
+       Datum      *values;
+       bool       *nulls;
+       bool       *replaces;
+ 
+       oldtup = SearchSysCache1(oidCacheId, ObjectIdGetDatum(objectId));
+       if (!HeapTupleIsValid(oldtup))
+               elog(ERROR, "cache lookup failed for object %u of catalog 
\"%s\"",
+                        objectId, RelationGetRelationName(rel));
+ 
+       datum = heap_getattr(oldtup, Anum_name,
+                                                RelationGetDescr(rel), 
&isnull);
+       Assert(!isnull);
+       old_name = NameStr(*(DatumGetName(datum)));
+ 
+       /* Get OID of namespace */
+       if (Anum_namespace > 0)
+       {
+               datum = heap_getattr(oldtup, Anum_namespace,
+                                                        RelationGetDescr(rel), 
&isnull);
+               Assert(!isnull);
+               namespaceId = DatumGetObjectId(datum);
+       }
+       else
+               namespaceId = InvalidOid;
+ 
+       /* Permission checks ... superusers can always do it */
+       if (!superuser())
+       {
+               /* Fail if object does not have an explicit owner */
+               if (Anum_owner <= 0)
+                       ereport(ERROR,
+                                       
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
+                                        (errmsg("must be superuser to set 
schema of %s",
+                                                        
getObjectDescriptionOids(classId, objectId)))));
+ 
+               /* Otherwise, must be owner of the existing object */
+               datum = heap_getattr(oldtup, Anum_owner,
+                                                        RelationGetDescr(rel), 
&isnull);
+               Assert(!isnull);
+               ownerId = DatumGetObjectId(datum);
+ 
+               if (!has_privs_of_role(GetUserId(), DatumGetObjectId(ownerId)))
+                       aclcheck_error(ACLCHECK_NOT_OWNER, acl_kind, old_name);
+ 
+               /* User must have CREATE privilege on the namespace */
+               if (OidIsValid(namespaceId))
+               {
+                       aclresult = pg_namespace_aclcheck(namespaceId, 
GetUserId(),
+                                                                               
          ACL_CREATE);
+                       if (aclresult != ACLCHECK_OK)
+                               aclcheck_error(aclresult, ACL_KIND_NAMESPACE,
+                                                          
get_namespace_name(namespaceId));
+               }
+       }
+ 
+       /*
+        * Check for duplicate name (more friendly than unique-index failure).
+        * Since this is just a friendliness check, we can just skip it in cases
+        * where there isn't a suitable syscache available.
+        */
+       if (nameCacheId >= 0)
+       {
+               HeapTuple       tup;
+ 
+               tup = SearchSysCache2(nameCacheId,
+                                                         
CStringGetDatum(new_name),
+                                                         
ObjectIdGetDatum(namespaceId));
+               if (HeapTupleIsValid(tup))
+               {
+                       Oid             exists = HeapTupleGetOid(tup);
+ 
+                       if (OidIsValid(namespaceId))
+                               ereport(ERROR,
+                                               
(errcode(ERRCODE_DUPLICATE_OBJECT),
+                                                errmsg("%s already exists in 
schema \"%s\"",
+                                                               
getObjectDescriptionOids(classId, exists),
+                                                               
get_namespace_name(namespaceId))));
+                       else
+                               ereport(ERROR,
+                                               
(errcode(ERRCODE_DUPLICATE_OBJECT),
+                                                errmsg("%s already exists",
+                                                               
getObjectDescriptionOids(classId, exists))));
+                       ReleaseSysCache(tup);
+               }
+       }
+ 
+       /* Build modified tuple */
+       values = palloc0(RelationGetNumberOfAttributes(rel) * sizeof(Datum));
+       nulls = palloc0(RelationGetNumberOfAttributes(rel) * sizeof(bool));
+       replaces = palloc0(RelationGetNumberOfAttributes(rel) * sizeof(bool));
+       values[Anum_name - 1] = PointerGetDatum(new_name);
+       replaces[Anum_name - 1] = true;
+       newtup = heap_modify_tuple(oldtup, RelationGetDescr(rel),
+                                                          values, nulls, 
replaces);
+ 
+       /* Perform actual update */
+       simple_heap_update(rel, &oldtup->t_self, newtup);
+       CatalogUpdateIndexes(rel, newtup);
+ 
+       /* Release memory */
+       pfree(values);
+       pfree(nulls);
+       pfree(replaces);
+       heap_freetuple(newtup);
+ 
+       ReleaseSysCache(oldtup);
+ }
  
  /*
   * Executes an ALTER OBJECT / RENAME TO statement.    Based on the object
***************
*** 64,96 **** ExecRenameStmt(RenameStmt *stmt)
                case OBJECT_CONSTRAINT:
                        return RenameConstraint(stmt);
  
-               case OBJECT_CONVERSION:
-                       return RenameConversion(stmt->object, stmt->newname);
- 
                case OBJECT_DATABASE:
                        return RenameDatabase(stmt->subname, stmt->newname);
  
-               case OBJECT_FDW:
-                       return RenameForeignDataWrapper(stmt->subname, 
stmt->newname);
- 
-               case OBJECT_FOREIGN_SERVER:
-                       return RenameForeignServer(stmt->subname, 
stmt->newname);
- 
-               case OBJECT_EVENT_TRIGGER:
-                       return RenameEventTrigger(stmt->subname, stmt->newname);
- 
-               case OBJECT_FUNCTION:
-                       return RenameFunction(stmt->object, stmt->objarg, 
stmt->newname);
- 
-               case OBJECT_LANGUAGE:
-                       return RenameLanguage(stmt->subname, stmt->newname);
- 
                case OBJECT_OPCLASS:
                        return RenameOpClass(stmt->object, stmt->subname, 
stmt->newname);
  
                case OBJECT_OPFAMILY:
                        return RenameOpFamily(stmt->object, stmt->subname, 
stmt->newname);
  
                case OBJECT_ROLE:
                        return RenameRole(stmt->subname, stmt->newname);
  
--- 204,221 ----
                case OBJECT_CONSTRAINT:
                        return RenameConstraint(stmt);
  
                case OBJECT_DATABASE:
                        return RenameDatabase(stmt->subname, stmt->newname);
  
                case OBJECT_OPCLASS:
                        return RenameOpClass(stmt->object, stmt->subname, 
stmt->newname);
  
                case OBJECT_OPFAMILY:
                        return RenameOpFamily(stmt->object, stmt->subname, 
stmt->newname);
  
+               case OBJECT_FUNCTION:
+                       return RenameFunction(stmt->object, stmt->objarg, 
stmt->newname);
+ 
                case OBJECT_ROLE:
                        return RenameRole(stmt->subname, stmt->newname);
  
***************
*** 114,134 **** ExecRenameStmt(RenameStmt *stmt)
                case OBJECT_TRIGGER:
                        return renametrig(stmt);
  
!               case OBJECT_TSPARSER:
!                       return RenameTSParser(stmt->object, stmt->newname);
  
                case OBJECT_TSDICTIONARY:
!                       return RenameTSDictionary(stmt->object, stmt->newname);
! 
                case OBJECT_TSTEMPLATE:
!                       return RenameTSTemplate(stmt->object, stmt->newname);
  
!               case OBJECT_TSCONFIGURATION:
!                       return RenameTSConfiguration(stmt->object, 
stmt->newname);
  
!               case OBJECT_DOMAIN:
!               case OBJECT_TYPE:
!                       return RenameType(stmt);
  
                default:
                        elog(ERROR, "unrecognized rename stmt type: %d",
--- 239,277 ----
                case OBJECT_TRIGGER:
                        return renametrig(stmt);
  
!               case OBJECT_DOMAIN:
!               case OBJECT_TYPE:
!                       return RenameType(stmt);
  
+               case OBJECT_CONVERSION:
+               case OBJECT_EVENT_TRIGGER:
+               case OBJECT_FDW:
+               case OBJECT_FOREIGN_SERVER:
+               case OBJECT_LANGUAGE:
+               case OBJECT_TSCONFIGURATION:
                case OBJECT_TSDICTIONARY:
!               case OBJECT_TSPARSER:
                case OBJECT_TSTEMPLATE:
!                       {
!                               ObjectAddress   address;
!                               Relation        catalog;
!                               Relation        relation;
  
!                               address = get_object_address(stmt->renameType,
!                                                                               
         stmt->object, stmt->objarg,
!                                                                               
         &relation,
!                                                                               
         AccessExclusiveLock, false);
!                               catalog = heap_open(address.classId, 
RowExclusiveLock);
! 
!                               AlterObjectRename_internal(catalog,
!                                                                               
   address.objectId,
!                                                                               
   stmt->newname);
!                               if (relation)
!                                       heap_close(relation, NoLock);
!                               heap_close(catalog, RowExclusiveLock);
  
!                               return address.objectId;
!                       }
  
                default:
                        elog(ERROR, "unrecognized rename stmt type: %d",
*** a/src/backend/commands/collationcmds.c
--- b/src/backend/commands/collationcmds.c
***************
*** 154,160 **** RenameCollation(List *name, const char *newname)
        Oid                     namespaceOid;
        HeapTuple       tup;
        Relation        rel;
-       AclResult       aclresult;
  
        rel = heap_open(CollationRelationId, RowExclusiveLock);
  
--- 154,159 ----
***************
*** 189,211 **** RenameCollation(List *name, const char *newname)
                                                newname,
                                                
get_namespace_name(namespaceOid))));
  
!       /* must be owner */
!       if (!pg_collation_ownercheck(collationOid, GetUserId()))
!               aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_COLLATION,
!                                          NameListToString(name));
! 
!       /* must have CREATE privilege on namespace */
!       aclresult = pg_namespace_aclcheck(namespaceOid, GetUserId(), 
ACL_CREATE);
!       if (aclresult != ACLCHECK_OK)
!               aclcheck_error(aclresult, ACL_KIND_NAMESPACE,
!                                          get_namespace_name(namespaceOid));
! 
!       /* rename */
!       namestrcpy(&(((Form_pg_collation) GETSTRUCT(tup))->collname), newname);
!       simple_heap_update(rel, &tup->t_self, tup);
!       CatalogUpdateIndexes(rel, tup);
! 
!       heap_freetuple(tup);
  
        heap_close(rel, RowExclusiveLock);
  
--- 188,195 ----
                                                newname,
                                                
get_namespace_name(namespaceOid))));
  
!       /* ok, do the task */
!       AlterObjectRename_internal(rel, collationOid, newname);
  
        heap_close(rel, RowExclusiveLock);
  
*** a/src/backend/commands/conversioncmds.c
--- b/src/backend/commands/conversioncmds.c
***************
*** 114,169 **** CreateConversionCommand(CreateConversionStmt *stmt)
        return ConversionCreate(conversion_name, namespaceId, GetUserId(),
                                                        from_encoding, 
to_encoding, funcoid, stmt->def);
  }
- 
- /*
-  * Rename conversion
-  */
- Oid
- RenameConversion(List *name, const char *newname)
- {
-       Oid                     conversionOid;
-       Oid                     namespaceOid;
-       HeapTuple       tup;
-       Relation        rel;
-       AclResult       aclresult;
- 
-       rel = heap_open(ConversionRelationId, RowExclusiveLock);
- 
-       conversionOid = get_conversion_oid(name, false);
- 
-       tup = SearchSysCacheCopy1(CONVOID, ObjectIdGetDatum(conversionOid));
-       if (!HeapTupleIsValid(tup)) /* should not happen */
-               elog(ERROR, "cache lookup failed for conversion %u", 
conversionOid);
- 
-       namespaceOid = ((Form_pg_conversion) GETSTRUCT(tup))->connamespace;
- 
-       /* make sure the new name doesn't exist */
-       if (SearchSysCacheExists2(CONNAMENSP,
-                                                         
CStringGetDatum(newname),
-                                                         
ObjectIdGetDatum(namespaceOid)))
-               ereport(ERROR,
-                               (errcode(ERRCODE_DUPLICATE_OBJECT),
-                                errmsg("conversion \"%s\" already exists in 
schema \"%s\"",
-                                               newname, 
get_namespace_name(namespaceOid))));
- 
-       /* must be owner */
-       if (!pg_conversion_ownercheck(conversionOid, GetUserId()))
-               aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_CONVERSION,
-                                          NameListToString(name));
- 
-       /* must have CREATE privilege on namespace */
-       aclresult = pg_namespace_aclcheck(namespaceOid, GetUserId(), 
ACL_CREATE);
-       if (aclresult != ACLCHECK_OK)
-               aclcheck_error(aclresult, ACL_KIND_NAMESPACE,
-                                          get_namespace_name(namespaceOid));
- 
-       /* rename */
-       namestrcpy(&(((Form_pg_conversion) GETSTRUCT(tup))->conname), newname);
-       simple_heap_update(rel, &tup->t_self, tup);
-       CatalogUpdateIndexes(rel, tup);
- 
-       heap_close(rel, NoLock);
-       heap_freetuple(tup);
- 
-       return conversionOid;
- }
--- 114,116 ----
*** a/src/backend/commands/event_trigger.c
--- b/src/backend/commands/event_trigger.c
***************
*** 417,468 **** AlterEventTrigger(AlterEventTrigStmt *stmt)
        return trigoid;
  }
  
- 
- /*
-  * Rename event trigger
-  */
- Oid
- RenameEventTrigger(const char *trigname, const char *newname)
- {
-       Oid                     evtId;
-       HeapTuple       tup;
-       Relation        rel;
-       Form_pg_event_trigger evtForm;
- 
-       rel = heap_open(EventTriggerRelationId, RowExclusiveLock);
- 
-       /* newname must be available */
-       if (SearchSysCacheExists1(EVENTTRIGGERNAME, CStringGetDatum(newname)))
-               ereport(ERROR,
-                               (errcode(ERRCODE_DUPLICATE_OBJECT),
-                                errmsg("event trigger \"%s\" already exists", 
newname)));
- 
-       /* trigname must exists */
-       tup = SearchSysCacheCopy1(EVENTTRIGGERNAME, CStringGetDatum(trigname));
-       if (!HeapTupleIsValid(tup))
-               ereport(ERROR,
-                               (errcode(ERRCODE_UNDEFINED_OBJECT),
-                                errmsg("event trigger \"%s\" does not exist", 
trigname)));
-       if (!pg_event_trigger_ownercheck(HeapTupleGetOid(tup), GetUserId()))
-               aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_EVENT_TRIGGER,
-                                          trigname);
- 
-       evtId = HeapTupleGetOid(tup);
- 
-       evtForm = (Form_pg_event_trigger) GETSTRUCT(tup);
- 
-       /* tuple is a copy, so we can rename it now */
-       namestrcpy(&(evtForm->evtname), newname);
-       simple_heap_update(rel, &tup->t_self, tup);
-       CatalogUpdateIndexes(rel, tup);
- 
-       heap_freetuple(tup);
-       heap_close(rel, RowExclusiveLock);
- 
-       return evtId;
- }
- 
- 
  /*
   * Change event trigger's owner -- by name
   */
--- 417,422 ----
*** a/src/backend/commands/foreigncmds.c
--- b/src/backend/commands/foreigncmds.c
***************
*** 200,292 **** GetUserOidFromMapping(const char *username, bool missing_ok)
        return get_role_oid(username, missing_ok);
  }
  
- 
- /*
-  * Rename foreign-data wrapper
-  */
- Oid
- RenameForeignDataWrapper(const char *oldname, const char *newname)
- {
-       Oid                     fdwId;
-       HeapTuple       tup;
-       Relation        rel;
- 
-       rel = heap_open(ForeignDataWrapperRelationId, RowExclusiveLock);
- 
-       tup = SearchSysCacheCopy1(FOREIGNDATAWRAPPERNAME, 
CStringGetDatum(oldname));
-       if (!HeapTupleIsValid(tup))
-               ereport(ERROR,
-                               (errcode(ERRCODE_UNDEFINED_OBJECT),
-                        errmsg("foreign-data wrapper \"%s\" does not exist", 
oldname)));
- 
-       fdwId = HeapTupleGetOid(tup);
- 
-       /* make sure the new name doesn't exist */
-       if (SearchSysCacheExists1(FOREIGNDATAWRAPPERNAME, 
CStringGetDatum(newname)))
-               ereport(ERROR,
-                               (errcode(ERRCODE_DUPLICATE_OBJECT),
-                        errmsg("foreign-data wrapper \"%s\" already exists", 
newname)));
- 
-       /* must be owner of FDW */
-       if (!pg_foreign_data_wrapper_ownercheck(HeapTupleGetOid(tup), 
GetUserId()))
-               aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_FDW,
-                                          oldname);
- 
-       /* rename */
-       namestrcpy(&(((Form_pg_foreign_data_wrapper) GETSTRUCT(tup))->fdwname), 
newname);
-       simple_heap_update(rel, &tup->t_self, tup);
-       CatalogUpdateIndexes(rel, tup);
- 
-       heap_close(rel, NoLock);
-       heap_freetuple(tup);
- 
-       return fdwId;
- }
- 
- 
- /*
-  * Rename foreign server
-  */
- Oid
- RenameForeignServer(const char *oldname, const char *newname)
- {
-       Oid                     srvId;
-       HeapTuple       tup;
-       Relation        rel;
- 
-       rel = heap_open(ForeignServerRelationId, RowExclusiveLock);
- 
-       tup = SearchSysCacheCopy1(FOREIGNSERVERNAME, CStringGetDatum(oldname));
-       if (!HeapTupleIsValid(tup))
-               ereport(ERROR,
-                               (errcode(ERRCODE_UNDEFINED_OBJECT),
-                                errmsg("server \"%s\" does not exist", 
oldname)));
- 
-       srvId = HeapTupleGetOid(tup);
- 
-       /* make sure the new name doesn't exist */
-       if (SearchSysCacheExists1(FOREIGNSERVERNAME, CStringGetDatum(newname)))
-               ereport(ERROR,
-                               (errcode(ERRCODE_DUPLICATE_OBJECT),
-                                errmsg("server \"%s\" already exists", 
newname)));
- 
-       /* must be owner of server */
-       if (!pg_foreign_server_ownercheck(HeapTupleGetOid(tup), GetUserId()))
-               aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_FOREIGN_SERVER,
-                                          oldname);
- 
-       /* rename */
-       namestrcpy(&(((Form_pg_foreign_server) GETSTRUCT(tup))->srvname), 
newname);
-       simple_heap_update(rel, &tup->t_self, tup);
-       CatalogUpdateIndexes(rel, tup);
- 
-       heap_close(rel, NoLock);
-       heap_freetuple(tup);
- 
-       return srvId;
- }
- 
- 
  /*
   * Internal workhorse for changing a data wrapper's owner.
   *
--- 200,205 ----
*** a/src/backend/commands/functioncmds.c
--- b/src/backend/commands/functioncmds.c
***************
*** 1048,1061 **** RenameFunction(List *name, List *argtypes, const char 
*newname)
        HeapTuple       tup;
        Form_pg_proc procForm;
        Relation        rel;
-       AclResult       aclresult;
  
        rel = heap_open(ProcedureRelationId, RowExclusiveLock);
  
        procOid = LookupFuncNameTypeNames(name, argtypes, false);
  
!       tup = SearchSysCacheCopy1(PROCOID, ObjectIdGetDatum(procOid));
!       if (!HeapTupleIsValid(tup)) /* should not happen */
                elog(ERROR, "cache lookup failed for function %u", procOid);
        procForm = (Form_pg_proc) GETSTRUCT(tup);
  
--- 1048,1060 ----
        HeapTuple       tup;
        Form_pg_proc procForm;
        Relation        rel;
  
        rel = heap_open(ProcedureRelationId, RowExclusiveLock);
  
        procOid = LookupFuncNameTypeNames(name, argtypes, false);
  
!       tup = SearchSysCache1(PROCOID, ObjectIdGetDatum(procOid));
!       if (!HeapTupleIsValid(tup))     /* should not happen */
                elog(ERROR, "cache lookup failed for function %u", procOid);
        procForm = (Form_pg_proc) GETSTRUCT(tup);
  
***************
*** 1084,1107 **** RenameFunction(List *name, List *argtypes, const char 
*newname)
                                                
get_namespace_name(namespaceOid))));
        }
  
!       /* must be owner */
!       if (!pg_proc_ownercheck(procOid, GetUserId()))
!               aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_PROC,
!                                          NameListToString(name));
! 
!       /* must have CREATE privilege on namespace */
!       aclresult = pg_namespace_aclcheck(namespaceOid, GetUserId(), 
ACL_CREATE);
!       if (aclresult != ACLCHECK_OK)
!               aclcheck_error(aclresult, ACL_KIND_NAMESPACE,
!                                          get_namespace_name(namespaceOid));
! 
!       /* rename */
!       namestrcpy(&(procForm->proname), newname);
!       simple_heap_update(rel, &tup->t_self, tup);
!       CatalogUpdateIndexes(rel, tup);
  
        heap_close(rel, NoLock);
-       heap_freetuple(tup);
  
        return procOid;
  }
--- 1083,1093 ----
                                                
get_namespace_name(namespaceOid))));
        }
  
!       /* ok, do the work */
!       AlterObjectRename_internal(rel, procOid, newname);
  
+       ReleaseSysCache(tup);
        heap_close(rel, NoLock);
  
        return procOid;
  }
*** a/src/backend/commands/opclasscmds.c
--- b/src/backend/commands/opclasscmds.c
***************
*** 1670,1688 **** RenameOpClass(List *name, const char *access_method, const 
char *newname)
        Oid                     opcOid;
        Oid                     amOid;
        Oid                     namespaceOid;
-       HeapTuple       origtup;
        HeapTuple       tup;
        Relation        rel;
-       AclResult       aclresult;
  
        amOid = get_am_oid(access_method, false);
  
        rel = heap_open(OperatorClassRelationId, RowExclusiveLock);
  
        /* Look up the opclass. */
!       origtup = OpClassCacheLookup(amOid, name, false);
!       tup = heap_copytuple(origtup);
!       ReleaseSysCache(origtup);
        opcOid = HeapTupleGetOid(tup);
        namespaceOid = ((Form_pg_opclass) GETSTRUCT(tup))->opcnamespace;
  
--- 1670,1685 ----
        Oid                     opcOid;
        Oid                     amOid;
        Oid                     namespaceOid;
        HeapTuple       tup;
        Relation        rel;
  
        amOid = get_am_oid(access_method, false);
  
        rel = heap_open(OperatorClassRelationId, RowExclusiveLock);
  
        /* Look up the opclass. */
!       tup = OpClassCacheLookup(amOid, name, false);
! 
        opcOid = HeapTupleGetOid(tup);
        namespaceOid = ((Form_pg_opclass) GETSTRUCT(tup))->opcnamespace;
  
***************
*** 1699,1722 **** RenameOpClass(List *name, const char *access_method, const 
char *newname)
                                                
get_namespace_name(namespaceOid))));
        }
  
!       /* must be owner */
!       if (!pg_opclass_ownercheck(opcOid, GetUserId()))
!               aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_OPCLASS,
!                                          NameListToString(name));
! 
!       /* must have CREATE privilege on namespace */
!       aclresult = pg_namespace_aclcheck(namespaceOid, GetUserId(), 
ACL_CREATE);
!       if (aclresult != ACLCHECK_OK)
!               aclcheck_error(aclresult, ACL_KIND_NAMESPACE,
!                                          get_namespace_name(namespaceOid));
! 
!       /* rename */
!       namestrcpy(&(((Form_pg_opclass) GETSTRUCT(tup))->opcname), newname);
!       simple_heap_update(rel, &tup->t_self, tup);
!       CatalogUpdateIndexes(rel, tup);
  
        heap_close(rel, NoLock);
!       heap_freetuple(tup);
  
        return opcOid;
  }
--- 1696,1706 ----
                                                
get_namespace_name(namespaceOid))));
        }
  
!       /* ok, do the work */
!       AlterObjectRename_internal(rel, opcOid, newname);
  
        heap_close(rel, NoLock);
!       ReleaseSysCache(tup);
  
        return opcOid;
  }
***************
*** 1734,1740 **** RenameOpFamily(List *name, const char *access_method, const 
char *newname)
        char       *opfname;
        HeapTuple       tup;
        Relation        rel;
-       AclResult       aclresult;
  
        amOid = get_am_oid(access_method, false);
  
--- 1718,1723 ----
***************
*** 1749,1758 **** RenameOpFamily(List *name, const char *access_method, const 
char *newname)
        {
                namespaceOid = LookupExplicitNamespace(schemaname);
  
!               tup = SearchSysCacheCopy3(OPFAMILYAMNAMENSP,
!                                                                 
ObjectIdGetDatum(amOid),
!                                                                 
PointerGetDatum(opfname),
!                                                                 
ObjectIdGetDatum(namespaceOid));
                if (!HeapTupleIsValid(tup))
                        ereport(ERROR,
                                        (errcode(ERRCODE_UNDEFINED_OBJECT),
--- 1732,1741 ----
        {
                namespaceOid = LookupExplicitNamespace(schemaname);
  
!               tup = SearchSysCache3(OPFAMILYAMNAMENSP,
!                                                         
ObjectIdGetDatum(amOid),
!                                                         
PointerGetDatum(opfname),
!                                                         
ObjectIdGetDatum(namespaceOid));
                if (!HeapTupleIsValid(tup))
                        ereport(ERROR,
                                        (errcode(ERRCODE_UNDEFINED_OBJECT),
***************
*** 1760,1765 **** RenameOpFamily(List *name, const char *access_method, const 
char *newname)
--- 1743,1750 ----
                                                        opfname, 
access_method)));
  
                opfOid = HeapTupleGetOid(tup);
+ 
+               ReleaseSysCache(tup);
        }
        else
        {
***************
*** 1770,1780 **** RenameOpFamily(List *name, const char *access_method, const 
char *newname)
                                         errmsg("operator family \"%s\" does 
not exist for access method \"%s\"",
                                                        opfname, 
access_method)));
  
!               tup = SearchSysCacheCopy1(OPFAMILYOID, 
ObjectIdGetDatum(opfOid));
!               if (!HeapTupleIsValid(tup))             /* should not happen */
!                       elog(ERROR, "cache lookup failed for opfamily %u", 
opfOid);
  
                namespaceOid = ((Form_pg_opfamily) 
GETSTRUCT(tup))->opfnamespace;
        }
  
        /* make sure the new name doesn't exist */
--- 1755,1767 ----
                                         errmsg("operator family \"%s\" does 
not exist for access method \"%s\"",
                                                        opfname, 
access_method)));
  
!               tup = SearchSysCache1(OPFAMILYOID, ObjectIdGetDatum(opfOid));
!               if (!HeapTupleIsValid(tup))     /* should not happen */
!               elog(ERROR, "cache lookup failed for opfamily %u", opfOid);
  
                namespaceOid = ((Form_pg_opfamily) 
GETSTRUCT(tup))->opfnamespace;
+ 
+               ReleaseSysCache(tup);
        }
  
        /* make sure the new name doesn't exist */
***************
*** 1790,1813 **** RenameOpFamily(List *name, const char *access_method, const 
char *newname)
                                                
get_namespace_name(namespaceOid))));
        }
  
!       /* must be owner */
!       if (!pg_opfamily_ownercheck(opfOid, GetUserId()))
!               aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_OPFAMILY,
!                                          NameListToString(name));
! 
!       /* must have CREATE privilege on namespace */
!       aclresult = pg_namespace_aclcheck(namespaceOid, GetUserId(), 
ACL_CREATE);
!       if (aclresult != ACLCHECK_OK)
!               aclcheck_error(aclresult, ACL_KIND_NAMESPACE,
!                                          get_namespace_name(namespaceOid));
! 
!       /* rename */
!       namestrcpy(&(((Form_pg_opfamily) GETSTRUCT(tup))->opfname), newname);
!       simple_heap_update(rel, &tup->t_self, tup);
!       CatalogUpdateIndexes(rel, tup);
  
        heap_close(rel, NoLock);
-       heap_freetuple(tup);
  
        return opfOid;
  }
--- 1777,1786 ----
                                                
get_namespace_name(namespaceOid))));
        }
  
!       /* ok, do the work */
!       AlterObjectRename_internal(rel, opfOid, newname);
  
        heap_close(rel, NoLock);
  
        return opfOid;
  }
*** a/src/backend/commands/proclang.c
--- b/src/backend/commands/proclang.c
***************
*** 537,584 **** DropProceduralLanguageById(Oid langOid)
  }
  
  /*
-  * Rename language
-  */
- Oid
- RenameLanguage(const char *oldname, const char *newname)
- {
-       Oid                     lanId;
-       HeapTuple       tup;
-       Relation        rel;
- 
-       rel = heap_open(LanguageRelationId, RowExclusiveLock);
- 
-       tup = SearchSysCacheCopy1(LANGNAME, CStringGetDatum(oldname));
-       if (!HeapTupleIsValid(tup))
-               ereport(ERROR,
-                               (errcode(ERRCODE_UNDEFINED_OBJECT),
-                                errmsg("language \"%s\" does not exist", 
oldname)));
- 
-       lanId = HeapTupleGetOid(tup);
- 
-       /* make sure the new name doesn't exist */
-       if (SearchSysCacheExists1(LANGNAME, CStringGetDatum(newname)))
-               ereport(ERROR,
-                               (errcode(ERRCODE_DUPLICATE_OBJECT),
-                                errmsg("language \"%s\" already exists", 
newname)));
- 
-       /* must be owner of PL */
-       if (!pg_language_ownercheck(HeapTupleGetOid(tup), GetUserId()))
-               aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_LANGUAGE,
-                                          oldname);
- 
-       /* rename */
-       namestrcpy(&(((Form_pg_language) GETSTRUCT(tup))->lanname), newname);
-       simple_heap_update(rel, &tup->t_self, tup);
-       CatalogUpdateIndexes(rel, tup);
- 
-       heap_close(rel, NoLock);
-       heap_freetuple(tup);
- 
-       return lanId;
- }
- 
- /*
   * get_language_oid - given a language name, look up the OID
   *
   * If missing_ok is false, throw an error if language name not found.  If
--- 537,542 ----
*** a/src/backend/commands/tablespace.c
--- b/src/backend/commands/tablespace.c
***************
*** 61,66 ****
--- 61,67 ----
  #include "catalog/indexing.h"
  #include "catalog/objectaccess.h"
  #include "catalog/pg_tablespace.h"
+ #include "commands/alter.h"
  #include "commands/comment.h"
  #include "commands/seclabel.h"
  #include "commands/tablespace.h"
***************
*** 828,835 **** RenameTableSpace(const char *oldname, const char *newname)
        ScanKeyData entry[1];
        HeapScanDesc scan;
        HeapTuple       tup;
-       HeapTuple       newtuple;
-       Form_pg_tablespace newform;
  
        /* Search pg_tablespace */
        rel = heap_open(TableSpaceRelationId, RowExclusiveLock);
--- 829,834 ----
***************
*** 847,861 **** RenameTableSpace(const char *oldname, const char *newname)
                                                oldname)));
  
        tspId = HeapTupleGetOid(tup);
-       newtuple = heap_copytuple(tup);
-       newform = (Form_pg_tablespace) GETSTRUCT(newtuple);
  
        heap_endscan(scan);
  
-       /* Must be owner */
-       if (!pg_tablespace_ownercheck(HeapTupleGetOid(newtuple), GetUserId()))
-               aclcheck_error(ACLCHECK_NO_PRIV, ACL_KIND_TABLESPACE, oldname);
- 
        /* Validate new name */
        if (!allowSystemTableMods && IsReservedName(newname))
                ereport(ERROR,
--- 846,854 ----
***************
*** 879,888 **** RenameTableSpace(const char *oldname, const char *newname)
        heap_endscan(scan);
  
        /* OK, update the entry */
!       namestrcpy(&(newform->spcname), newname);
! 
!       simple_heap_update(rel, &newtuple->t_self, newtuple);
!       CatalogUpdateIndexes(rel, newtuple);
  
        heap_close(rel, NoLock);
  
--- 872,878 ----
        heap_endscan(scan);
  
        /* OK, update the entry */
!       AlterObjectRename_internal(rel, tspId, newname);
  
        heap_close(rel, NoLock);
  
*** a/src/backend/commands/tsearchcmds.c
--- b/src/backend/commands/tsearchcmds.c
***************
*** 305,355 **** RemoveTSParserById(Oid prsId)
        heap_close(relation, RowExclusiveLock);
  }
  
- /*
-  * ALTER TEXT SEARCH PARSER RENAME
-  */
- Oid
- RenameTSParser(List *oldname, const char *newname)
- {
-       HeapTuple       tup;
-       Relation        rel;
-       Oid                     prsId;
-       Oid                     namespaceOid;
- 
-       if (!superuser())
-               ereport(ERROR,
-                               (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
-                                errmsg("must be superuser to rename text 
search parsers")));
- 
-       rel = heap_open(TSParserRelationId, RowExclusiveLock);
- 
-       prsId = get_ts_parser_oid(oldname, false);
- 
-       tup = SearchSysCacheCopy1(TSPARSEROID, ObjectIdGetDatum(prsId));
- 
-       if (!HeapTupleIsValid(tup)) /* should not happen */
-               elog(ERROR, "cache lookup failed for text search parser %u", 
prsId);
- 
-       namespaceOid = ((Form_pg_ts_parser) GETSTRUCT(tup))->prsnamespace;
- 
-       if (SearchSysCacheExists2(TSPARSERNAMENSP,
-                                                         
PointerGetDatum(newname),
-                                                         
ObjectIdGetDatum(namespaceOid)))
-               ereport(ERROR,
-                               (errcode(ERRCODE_DUPLICATE_OBJECT),
-                                errmsg("text search parser \"%s\" already 
exists",
-                                               newname)));
- 
-       namestrcpy(&(((Form_pg_ts_parser) GETSTRUCT(tup))->prsname), newname);
-       simple_heap_update(rel, &tup->t_self, tup);
-       CatalogUpdateIndexes(rel, tup);
- 
-       heap_close(rel, NoLock);
-       heap_freetuple(tup);
- 
-       return prsId;
- }
- 
  /* ---------------------- TS Dictionary commands -----------------------*/
  
  /*
--- 305,310 ----
***************
*** 535,593 **** DefineTSDictionary(List *names, List *parameters)
  }
  
  /*
-  * ALTER TEXT SEARCH DICTIONARY RENAME
-  */
- Oid
- RenameTSDictionary(List *oldname, const char *newname)
- {
-       HeapTuple       tup;
-       Relation        rel;
-       Oid                     dictId;
-       Oid                     namespaceOid;
-       AclResult       aclresult;
- 
-       rel = heap_open(TSDictionaryRelationId, RowExclusiveLock);
- 
-       dictId = get_ts_dict_oid(oldname, false);
- 
-       tup = SearchSysCacheCopy1(TSDICTOID, ObjectIdGetDatum(dictId));
- 
-       if (!HeapTupleIsValid(tup)) /* should not happen */
-               elog(ERROR, "cache lookup failed for text search dictionary %u",
-                        dictId);
- 
-       namespaceOid = ((Form_pg_ts_dict) GETSTRUCT(tup))->dictnamespace;
- 
-       if (SearchSysCacheExists2(TSDICTNAMENSP,
-                                                         
PointerGetDatum(newname),
-                                                         
ObjectIdGetDatum(namespaceOid)))
-               ereport(ERROR,
-                               (errcode(ERRCODE_DUPLICATE_OBJECT),
-                                errmsg("text search dictionary \"%s\" already 
exists",
-                                               newname)));
- 
-       /* must be owner */
-       if (!pg_ts_dict_ownercheck(dictId, GetUserId()))
-               aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_TSDICTIONARY,
-                                          NameListToString(oldname));
- 
-       /* must have CREATE privilege on namespace */
-       aclresult = pg_namespace_aclcheck(namespaceOid, GetUserId(), 
ACL_CREATE);
-       if (aclresult != ACLCHECK_OK)
-               aclcheck_error(aclresult, ACL_KIND_NAMESPACE,
-                                          get_namespace_name(namespaceOid));
- 
-       namestrcpy(&(((Form_pg_ts_dict) GETSTRUCT(tup))->dictname), newname);
-       simple_heap_update(rel, &tup->t_self, tup);
-       CatalogUpdateIndexes(rel, tup);
- 
-       heap_close(rel, NoLock);
-       heap_freetuple(tup);
- 
-       return dictId;
- }
- 
- /*
   * Guts of TS dictionary deletion.
   */
  void
--- 490,495 ----
***************
*** 905,956 **** DefineTSTemplate(List *names, List *parameters)
  }
  
  /*
-  * ALTER TEXT SEARCH TEMPLATE RENAME
-  */
- Oid
- RenameTSTemplate(List *oldname, const char *newname)
- {
-       HeapTuple       tup;
-       Relation        rel;
-       Oid                     tmplId;
-       Oid                     namespaceOid;
- 
-       if (!superuser())
-               ereport(ERROR,
-                               (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
-                          errmsg("must be superuser to rename text search 
templates")));
- 
-       rel = heap_open(TSTemplateRelationId, RowExclusiveLock);
- 
-       tmplId = get_ts_template_oid(oldname, false);
- 
-       tup = SearchSysCacheCopy1(TSTEMPLATEOID, ObjectIdGetDatum(tmplId));
- 
-       if (!HeapTupleIsValid(tup)) /* should not happen */
-               elog(ERROR, "cache lookup failed for text search template %u",
-                        tmplId);
- 
-       namespaceOid = ((Form_pg_ts_template) GETSTRUCT(tup))->tmplnamespace;
- 
-       if (SearchSysCacheExists2(TSTEMPLATENAMENSP,
-                                                         
PointerGetDatum(newname),
-                                                         
ObjectIdGetDatum(namespaceOid)))
-               ereport(ERROR,
-                               (errcode(ERRCODE_DUPLICATE_OBJECT),
-                                errmsg("text search template \"%s\" already 
exists",
-                                               newname)));
- 
-       namestrcpy(&(((Form_pg_ts_template) GETSTRUCT(tup))->tmplname), 
newname);
-       simple_heap_update(rel, &tup->t_self, tup);
-       CatalogUpdateIndexes(rel, tup);
- 
-       heap_close(rel, NoLock);
-       heap_freetuple(tup);
- 
-       return tmplId;
- }
- 
- /*
   * Guts of TS template deletion.
   */
  void
--- 807,812 ----
***************
*** 1249,1306 **** DefineTSConfiguration(List *names, List *parameters)
  }
  
  /*
-  * ALTER TEXT SEARCH CONFIGURATION RENAME
-  */
- Oid
- RenameTSConfiguration(List *oldname, const char *newname)
- {
-       HeapTuple       tup;
-       Relation        rel;
-       Oid                     cfgId;
-       AclResult       aclresult;
-       Oid                     namespaceOid;
- 
-       rel = heap_open(TSConfigRelationId, RowExclusiveLock);
- 
-       cfgId = get_ts_config_oid(oldname, false);
- 
-       tup = SearchSysCacheCopy1(TSCONFIGOID, ObjectIdGetDatum(cfgId));
- 
-       if (!HeapTupleIsValid(tup)) /* should not happen */
-               elog(ERROR, "cache lookup failed for text search configuration 
%u",
-                        cfgId);
- 
-       namespaceOid = ((Form_pg_ts_config) GETSTRUCT(tup))->cfgnamespace;
- 
-       if (SearchSysCacheExists2(TSCONFIGNAMENSP,
-                                                         
PointerGetDatum(newname),
-                                                         
ObjectIdGetDatum(namespaceOid)))
-               ereport(ERROR,
-                               (errcode(ERRCODE_DUPLICATE_OBJECT),
-                                errmsg("text search configuration \"%s\" 
already exists",
-                                               newname)));
- 
-       /* must be owner */
-       if (!pg_ts_config_ownercheck(cfgId, GetUserId()))
-               aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_TSCONFIGURATION,
-                                          NameListToString(oldname));
- 
-       /* must have CREATE privilege on namespace */
-       aclresult = pg_namespace_aclcheck(namespaceOid, GetUserId(), 
ACL_CREATE);
-       aclcheck_error(aclresult, ACL_KIND_NAMESPACE,
-                                  get_namespace_name(namespaceOid));
- 
-       namestrcpy(&(((Form_pg_ts_config) GETSTRUCT(tup))->cfgname), newname);
-       simple_heap_update(rel, &tup->t_self, tup);
-       CatalogUpdateIndexes(rel, tup);
- 
-       heap_close(rel, NoLock);
-       heap_freetuple(tup);
- 
-       return cfgId;
- }
- 
- /*
   * Guts of TS configuration deletion.
   */
  void
--- 1105,1110 ----
*** a/src/backend/parser/gram.y
--- b/src/backend/parser/gram.y
***************
*** 6776,6782 **** RenameStmt: ALTER AGGREGATE func_name aggr_args RENAME TO 
name
                                {
                                        RenameStmt *n = makeNode(RenameStmt);
                                        n->renameType = OBJECT_FDW;
!                                       n->subname = $5;
                                        n->newname = $8;
                                        n->missing_ok = false;
                                        $$ = (Node *)n;
--- 6776,6782 ----
                                {
                                        RenameStmt *n = makeNode(RenameStmt);
                                        n->renameType = OBJECT_FDW;
!                                       n->object = list_make1(makeString($5));
                                        n->newname = $8;
                                        n->missing_ok = false;
                                        $$ = (Node *)n;
***************
*** 6804,6810 **** RenameStmt: ALTER AGGREGATE func_name aggr_args RENAME TO 
name
                                {
                                        RenameStmt *n = makeNode(RenameStmt);
                                        n->renameType = OBJECT_LANGUAGE;
!                                       n->subname = $4;
                                        n->newname = $7;
                                        n->missing_ok = false;
                                        $$ = (Node *)n;
--- 6804,6810 ----
                                {
                                        RenameStmt *n = makeNode(RenameStmt);
                                        n->renameType = OBJECT_LANGUAGE;
!                                       n->object = list_make1(makeString($4));
                                        n->newname = $7;
                                        n->missing_ok = false;
                                        $$ = (Node *)n;
***************
*** 6842,6848 **** RenameStmt: ALTER AGGREGATE func_name aggr_args RENAME TO 
name
                                {
                                        RenameStmt *n = makeNode(RenameStmt);
                                        n->renameType = OBJECT_FOREIGN_SERVER;
!                                       n->subname = $3;
                                        n->newname = $6;
                                        n->missing_ok = false;
                                        $$ = (Node *)n;
--- 6842,6848 ----
                                {
                                        RenameStmt *n = makeNode(RenameStmt);
                                        n->renameType = OBJECT_FOREIGN_SERVER;
!                                       n->object = list_make1(makeString($3));
                                        n->newname = $6;
                                        n->missing_ok = false;
                                        $$ = (Node *)n;
***************
*** 7015,7021 **** RenameStmt: ALTER AGGREGATE func_name aggr_args RENAME TO 
name
                                {
                                        RenameStmt *n = makeNode(RenameStmt);
                                        n->renameType = OBJECT_EVENT_TRIGGER;
!                                       n->subname = $4;
                                        n->newname = $7;
                                        $$ = (Node *)n;
                                }
--- 7015,7021 ----
                                {
                                        RenameStmt *n = makeNode(RenameStmt);
                                        n->renameType = OBJECT_EVENT_TRIGGER;
!                                       n->object = list_make1(makeString($4));
                                        n->newname = $7;
                                        $$ = (Node *)n;
                                }
*** a/src/include/commands/alter.h
--- b/src/include/commands/alter.h
***************
*** 18,23 ****
--- 18,25 ----
  #include "nodes/parsenodes.h"
  #include "utils/relcache.h"
  
+ extern void AlterObjectRename_internal(Relation rel, Oid objid,
+                                                  const char *newname);
  extern Oid ExecRenameStmt(RenameStmt *stmt);
  
  extern Oid ExecAlterObjectSchemaStmt(AlterObjectSchemaStmt *stmt);
*** a/src/include/commands/conversioncmds.h
--- b/src/include/commands/conversioncmds.h
***************
*** 18,23 ****
  #include "nodes/parsenodes.h"
  
  extern Oid CreateConversionCommand(CreateConversionStmt *parsetree);
- extern Oid RenameConversion(List *name, const char *newname);
  
  #endif   /* CONVERSIONCMDS_H */
--- 18,22 ----
*** a/src/include/commands/defrem.h
--- b/src/include/commands/defrem.h
***************
*** 102,109 **** extern text *serialize_deflist(List *deflist);
  extern List *deserialize_deflist(Datum txt);
  
  /* commands/foreigncmds.c */
- extern Oid RenameForeignServer(const char *oldname, const char *newname);
- extern Oid RenameForeignDataWrapper(const char *oldname, const char *newname);
  extern Oid AlterForeignServerOwner(const char *name, Oid newOwnerId);
  extern void AlterForeignServerOwner_oid(Oid, Oid newOwnerId);
  extern Oid AlterForeignDataWrapperOwner(const char *name, Oid newOwnerId);
--- 102,107 ----
*** a/src/include/commands/event_trigger.h
--- b/src/include/commands/event_trigger.h
***************
*** 36,42 **** extern void RemoveEventTriggerById(Oid ctrigOid);
  extern Oid    get_event_trigger_oid(const char *trigname, bool missing_ok);
  
  extern Oid AlterEventTrigger(AlterEventTrigStmt *stmt);
- extern Oid RenameEventTrigger(const char* trigname, const char *newname);
  extern Oid AlterEventTriggerOwner(const char *name, Oid newOwnerId);
  extern void AlterEventTriggerOwner_oid(Oid, Oid newOwnerId);
  
--- 36,41 ----
*** a/src/include/commands/proclang.h
--- b/src/include/commands/proclang.h
***************
*** 16,22 ****
  
  extern Oid CreateProceduralLanguage(CreatePLangStmt *stmt);
  extern void DropProceduralLanguageById(Oid langOid);
- extern Oid RenameLanguage(const char *oldname, const char *newname);
  extern bool PLTemplateExists(const char *languageName);
  extern Oid    get_language_oid(const char *langname, bool missing_ok);
  
--- 16,21 ----
*** a/src/test/regress/expected/alter_generic.out
--- b/src/test/regress/expected/alter_generic.out
***************
*** 110,116 **** SET SESSION AUTHORIZATION regtest_alter_user1;
  CREATE CONVERSION alt_conv1 FOR 'LATIN1' TO 'UTF8' FROM iso8859_1_to_utf8;
  CREATE CONVERSION alt_conv2 FOR 'LATIN1' TO 'UTF8' FROM iso8859_1_to_utf8;
  ALTER CONVERSION alt_conv1 RENAME TO alt_conv2;  -- failed (name conflict)
! ERROR:  conversion "alt_conv2" already exists in schema "alt_nsp1"
  ALTER CONVERSION alt_conv1 RENAME TO alt_conv3;  -- OK
  ALTER CONVERSION alt_conv2 OWNER TO regtest_alter_user2;  -- failed (no role 
membership)
  ERROR:  must be member of role "regtest_alter_user2"
--- 110,116 ----
  CREATE CONVERSION alt_conv1 FOR 'LATIN1' TO 'UTF8' FROM iso8859_1_to_utf8;
  CREATE CONVERSION alt_conv2 FOR 'LATIN1' TO 'UTF8' FROM iso8859_1_to_utf8;
  ALTER CONVERSION alt_conv1 RENAME TO alt_conv2;  -- failed (name conflict)
! ERROR:  conversion alt_conv2 already exists in schema "alt_nsp1"
  ALTER CONVERSION alt_conv1 RENAME TO alt_conv3;  -- OK
  ALTER CONVERSION alt_conv2 OWNER TO regtest_alter_user2;  -- failed (no role 
membership)
  ERROR:  must be member of role "regtest_alter_user2"
***************
*** 152,161 **** CREATE FOREIGN DATA WRAPPER alt_fdw2;
  CREATE SERVER alt_fserv1 FOREIGN DATA WRAPPER alt_fdw1;
  CREATE SERVER alt_fserv2 FOREIGN DATA WRAPPER alt_fdw2;
  ALTER FOREIGN DATA WRAPPER alt_fdw1 RENAME TO alt_fdw2;  -- failed (name 
conflict)
! ERROR:  foreign-data wrapper "alt_fdw2" already exists
  ALTER FOREIGN DATA WRAPPER alt_fdw1 RENAME TO alt_fdw3;  -- OK
  ALTER SERVER alt_fserv1 RENAME TO alt_fserv2;   -- failed (name conflict)
! ERROR:  server "alt_fserv2" already exists
  ALTER SERVER alt_fserv1 RENAME TO alt_fserv3;   -- OK
  SELECT fdwname FROM pg_foreign_data_wrapper WHERE fdwname like 'alt_fdw%';
   fdwname  
--- 152,161 ----
  CREATE SERVER alt_fserv1 FOREIGN DATA WRAPPER alt_fdw1;
  CREATE SERVER alt_fserv2 FOREIGN DATA WRAPPER alt_fdw2;
  ALTER FOREIGN DATA WRAPPER alt_fdw1 RENAME TO alt_fdw2;  -- failed (name 
conflict)
! ERROR:  foreign-data wrapper alt_fdw2 already exists
  ALTER FOREIGN DATA WRAPPER alt_fdw1 RENAME TO alt_fdw3;  -- OK
  ALTER SERVER alt_fserv1 RENAME TO alt_fserv2;   -- failed (name conflict)
! ERROR:  server alt_fserv2 already exists
  ALTER SERVER alt_fserv1 RENAME TO alt_fserv3;   -- OK
  SELECT fdwname FROM pg_foreign_data_wrapper WHERE fdwname like 'alt_fdw%';
   fdwname  
***************
*** 180,186 **** ALTER LANGUAGE alt_lang1 OWNER TO regtest_alter_user1;  -- OK
  ALTER LANGUAGE alt_lang2 OWNER TO regtest_alter_user2;  -- OK
  SET SESSION AUTHORIZATION regtest_alter_user1;
  ALTER LANGUAGE alt_lang1 RENAME TO alt_lang2;   -- failed (name conflict)
! ERROR:  language "alt_lang2" already exists
  ALTER LANGUAGE alt_lang2 RENAME TO alt_lang3;   -- failed (not owner)
  ERROR:  must be owner of language alt_lang2
  ALTER LANGUAGE alt_lang1 RENAME TO alt_lang3;   -- OK
--- 180,186 ----
  ALTER LANGUAGE alt_lang2 OWNER TO regtest_alter_user2;  -- OK
  SET SESSION AUTHORIZATION regtest_alter_user1;
  ALTER LANGUAGE alt_lang1 RENAME TO alt_lang2;   -- failed (name conflict)
! ERROR:  language alt_lang2 already exists
  ALTER LANGUAGE alt_lang2 RENAME TO alt_lang3;   -- failed (not owner)
  ERROR:  must be owner of language alt_lang2
  ALTER LANGUAGE alt_lang1 RENAME TO alt_lang3;   -- OK
***************
*** 327,333 **** SET SESSION AUTHORIZATION regtest_alter_user1;
  CREATE TEXT SEARCH DICTIONARY alt_ts_dict1 (template=simple);
  CREATE TEXT SEARCH DICTIONARY alt_ts_dict2 (template=simple);
  ALTER TEXT SEARCH DICTIONARY alt_ts_dict1 RENAME TO alt_ts_dict2;  -- failed 
(name conflict)
! ERROR:  text search dictionary "alt_ts_dict2" already exists
  ALTER TEXT SEARCH DICTIONARY alt_ts_dict1 RENAME TO alt_ts_dict3;  -- OK
  ALTER TEXT SEARCH DICTIONARY alt_ts_dict2 OWNER TO regtest_alter_user2;  -- 
failed (no role membership)
  ERROR:  must be member of role "regtest_alter_user2"
--- 327,333 ----
  CREATE TEXT SEARCH DICTIONARY alt_ts_dict1 (template=simple);
  CREATE TEXT SEARCH DICTIONARY alt_ts_dict2 (template=simple);
  ALTER TEXT SEARCH DICTIONARY alt_ts_dict1 RENAME TO alt_ts_dict2;  -- failed 
(name conflict)
! ERROR:  text search dictionary alt_ts_dict2 already exists in schema 
"alt_nsp1"
  ALTER TEXT SEARCH DICTIONARY alt_ts_dict1 RENAME TO alt_ts_dict3;  -- OK
  ALTER TEXT SEARCH DICTIONARY alt_ts_dict2 OWNER TO regtest_alter_user2;  -- 
failed (no role membership)
  ERROR:  must be member of role "regtest_alter_user2"
***************
*** 368,374 **** SET SESSION AUTHORIZATION regtest_alter_user1;
  CREATE TEXT SEARCH CONFIGURATION alt_ts_conf1 (copy=english);
  CREATE TEXT SEARCH CONFIGURATION alt_ts_conf2 (copy=english);
  ALTER TEXT SEARCH CONFIGURATION alt_ts_conf1 RENAME TO alt_ts_conf2;  -- 
failed (name conflict)
! ERROR:  text search configuration "alt_ts_conf2" already exists
  ALTER TEXT SEARCH CONFIGURATION alt_ts_conf1 RENAME TO alt_ts_conf3;  -- OK
  ALTER TEXT SEARCH CONFIGURATION alt_ts_conf2 OWNER TO regtest_alter_user2;  
-- failed (no role membership)
  ERROR:  must be member of role "regtest_alter_user2"
--- 368,374 ----
  CREATE TEXT SEARCH CONFIGURATION alt_ts_conf1 (copy=english);
  CREATE TEXT SEARCH CONFIGURATION alt_ts_conf2 (copy=english);
  ALTER TEXT SEARCH CONFIGURATION alt_ts_conf1 RENAME TO alt_ts_conf2;  -- 
failed (name conflict)
! ERROR:  text search configuration alt_ts_conf2 already exists in schema 
"alt_nsp1"
  ALTER TEXT SEARCH CONFIGURATION alt_ts_conf1 RENAME TO alt_ts_conf3;  -- OK
  ALTER TEXT SEARCH CONFIGURATION alt_ts_conf2 OWNER TO regtest_alter_user2;  
-- failed (no role membership)
  ERROR:  must be member of role "regtest_alter_user2"
***************
*** 408,414 **** SELECT nspname, cfgname, rolname
  CREATE TEXT SEARCH TEMPLATE alt_ts_temp1 (lexize=dsimple_lexize);
  CREATE TEXT SEARCH TEMPLATE alt_ts_temp2 (lexize=dsimple_lexize);
  ALTER TEXT SEARCH TEMPLATE alt_ts_temp1 RENAME TO alt_ts_temp2; -- failed 
(name conflict)
! ERROR:  text search template "alt_ts_temp2" already exists
  ALTER TEXT SEARCH TEMPLATE alt_ts_temp1 RENAME TO alt_ts_temp3; -- OK
  ALTER TEXT SEARCH TEMPLATE alt_ts_temp2 SET SCHEMA alt_nsp2;    -- OK
  CREATE TEXT SEARCH TEMPLATE alt_ts_temp2 (lexize=dsimple_lexize);
--- 408,414 ----
  CREATE TEXT SEARCH TEMPLATE alt_ts_temp1 (lexize=dsimple_lexize);
  CREATE TEXT SEARCH TEMPLATE alt_ts_temp2 (lexize=dsimple_lexize);
  ALTER TEXT SEARCH TEMPLATE alt_ts_temp1 RENAME TO alt_ts_temp2; -- failed 
(name conflict)
! ERROR:  text search template alt_ts_temp2 already exists in schema "alt_nsp1"
  ALTER TEXT SEARCH TEMPLATE alt_ts_temp1 RENAME TO alt_ts_temp3; -- OK
  ALTER TEXT SEARCH TEMPLATE alt_ts_temp2 SET SCHEMA alt_nsp2;    -- OK
  CREATE TEXT SEARCH TEMPLATE alt_ts_temp2 (lexize=dsimple_lexize);
***************
*** 433,439 **** CREATE TEXT SEARCH PARSER alt_ts_prs1
  CREATE TEXT SEARCH PARSER alt_ts_prs2
      (start = prsd_start, gettoken = prsd_nexttoken, end = prsd_end, lextypes 
= prsd_lextype);
  ALTER TEXT SEARCH PARSER alt_ts_prs1 RENAME TO alt_ts_prs2; -- failed (name 
conflict)
! ERROR:  text search parser "alt_ts_prs2" already exists
  ALTER TEXT SEARCH PARSER alt_ts_prs1 RENAME TO alt_ts_prs3; -- OK
  ALTER TEXT SEARCH PARSER alt_ts_prs2 SET SCHEMA alt_nsp2;   -- OK
  CREATE TEXT SEARCH PARSER alt_ts_prs2
--- 433,439 ----
  CREATE TEXT SEARCH PARSER alt_ts_prs2
      (start = prsd_start, gettoken = prsd_nexttoken, end = prsd_end, lextypes 
= prsd_lextype);
  ALTER TEXT SEARCH PARSER alt_ts_prs1 RENAME TO alt_ts_prs2; -- failed (name 
conflict)
! ERROR:  text search parser alt_ts_prs2 already exists in schema "alt_nsp1"
  ALTER TEXT SEARCH PARSER alt_ts_prs1 RENAME TO alt_ts_prs3; -- OK
  ALTER TEXT SEARCH PARSER alt_ts_prs2 SET SCHEMA alt_nsp2;   -- OK
  CREATE TEXT SEARCH PARSER alt_ts_prs2
*** a/src/test/regress/expected/event_trigger.out
--- b/src/test/regress/expected/event_trigger.out
***************
*** 77,83 **** alter role regression_bob superuser;
  alter event trigger regress_event_trigger owner to regression_bob;
  -- should fail, name collision
  alter event trigger regress_event_trigger rename to regress_event_trigger2;
! ERROR:  event trigger "regress_event_trigger2" already exists
  -- OK
  alter event trigger regress_event_trigger rename to regress_event_trigger3;
  -- should fail, doesn't exist any more
--- 77,83 ----
  alter event trigger regress_event_trigger owner to regression_bob;
  -- should fail, name collision
  alter event trigger regress_event_trigger rename to regress_event_trigger2;
! ERROR:  event trigger regress_event_trigger2 already exists
  -- OK
  alter event trigger regress_event_trigger rename to regress_event_trigger3;
  -- should fail, doesn't exist any more
-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to