diff options
author | Alvaro Herrera <alvherre@alvh.no-ip.org> | 2013-01-21 12:06:41 -0300 |
---|---|---|
committer | Alvaro Herrera <alvherre@alvh.no-ip.org> | 2013-01-21 12:06:41 -0300 |
commit | 765cbfdc9263bf7c90b9d1f1044c6950b8b7088c (patch) | |
tree | b7fc0ebfb2be1d051c2c223f5215239aeb3c1558 /src/backend/commands/functioncmds.c | |
parent | 8f0d8f481e86514bb35538827df7e1e35baee368 (diff) | |
download | postgresql-765cbfdc9263bf7c90b9d1f1044c6950b8b7088c.tar.gz postgresql-765cbfdc9263bf7c90b9d1f1044c6950b8b7088c.zip |
Refactor ALTER some-obj RENAME implementation
Remove duplicate implementations of catalog munging and miscellaneous
privilege checks. Instead rely on already existing data in
objectaddress.c to do the work.
Author: KaiGai Kohei, changes by me
Reviewed by: Robert Haas, Álvaro Herrera, Dimitri Fontaine
Diffstat (limited to 'src/backend/commands/functioncmds.c')
-rw-r--r-- | src/backend/commands/functioncmds.c | 61 |
1 files changed, 1 insertions, 60 deletions
diff --git a/src/backend/commands/functioncmds.c b/src/backend/commands/functioncmds.c index 4f8e82a8e69..7b912332feb 100644 --- a/src/backend/commands/functioncmds.c +++ b/src/backend/commands/functioncmds.c @@ -1036,65 +1036,6 @@ RemoveFunctionById(Oid funcOid) } } - -/* - * Rename function - */ -Oid -RenameFunction(List *name, List *argtypes, const char *newname) -{ - Oid procOid; - Oid namespaceOid; - 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); - - if (procForm->proisagg) - ereport(ERROR, - (errcode(ERRCODE_WRONG_OBJECT_TYPE), - errmsg("\"%s\" is an aggregate function", - NameListToString(name)), - errhint("Use ALTER AGGREGATE to rename aggregate functions."))); - - namespaceOid = procForm->pronamespace; - - /* make sure the new name doesn't exist */ - IsThereFunctionInNamespace(newname, procForm->pronargs, - procForm->proargtypes, - 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; -} - /* * Implements the ALTER FUNCTION utility command (except for the * RENAME and OWNER clauses, which are handled as part of the generic @@ -1677,7 +1618,7 @@ DropCastById(Oid castOid) } /* - * Subroutine for ALTER FUNCTION/AGGREGATE SET SCHEMA + * Subroutine for ALTER FUNCTION/AGGREGATE SET SCHEMA/RENAME * * Is there a function with the given name and signature already in the given * namespace? If so, raise an appropriate error message. |