1
0
mirror of https://github.com/postgres/postgres.git synced 2025-08-27 07:42:10 +03:00

First batch of object rename commands.

This commit is contained in:
Peter Eisentraut
2003-06-27 14:45:32 +00:00
parent 5bac7d11dd
commit b256f24264
60 changed files with 2018 additions and 442 deletions

View File

@@ -9,7 +9,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/functioncmds.c,v 1.25 2003/02/01 22:09:26 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/commands/functioncmds.c,v 1.26 2003/06/27 14:45:27 petere Exp $
*
* DESCRIPTION
* These routines take the parse tree and pick out the
@@ -591,6 +591,72 @@ RemoveFunctionById(Oid funcOid)
}
/*
* Rename function
*/
void
RenameFunction(List *name, List *argtypes, const char *newname)
{
Oid procOid;
Oid namespaceOid;
Oid oid_array[FUNC_MAX_ARGS];
HeapTuple tup;
Relation rel;
AclResult aclresult;
int16 nargs;
rel = heap_openr(ProcedureRelationName, RowExclusiveLock);
procOid = LookupFuncNameTypeNames(name, argtypes, "RenameFunction");
tup = SearchSysCacheCopy(PROCOID,
ObjectIdGetDatum(procOid),
0, 0, 0);
if (!HeapTupleIsValid(tup)) /* should not happen */
elog(ERROR, "RenameFunction: couldn't find pg_proc tuple for %s",
NameListToString(name));
if (((Form_pg_proc) GETSTRUCT(tup))->proisagg)
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR_OR_ACCESS_RULE_VIOLATION),
errmsg("%s is an aggregate function", NameListToString(name)),
errhint("Use ALTER AGGREGATE to rename aggregate functions.")));
namespaceOid = ((Form_pg_proc) GETSTRUCT(tup))->pronamespace;
/* make sure the new name doesn't exist */
nargs = compute_parameter_types(argtypes, ((Form_pg_proc) GETSTRUCT(tup))->prolang, oid_array);
if (SearchSysCacheExists(PROCNAMENSP,
CStringGetDatum(newname),
Int16GetDatum(nargs),
PointerGetDatum(oid_array),
ObjectIdGetDatum(namespaceOid)))
{
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR_OR_ACCESS_RULE_VIOLATION),
errmsg("function %s with the same argument types already exists in schema %s",
newname, get_namespace_name(namespaceOid))));
}
/* must be owner */
if (!pg_proc_ownercheck(procOid, GetUserId()))
aclcheck_error(ACLCHECK_NOT_OWNER, NameListToString(name));
/* must have CREATE privilege on namespace */
aclresult = pg_namespace_aclcheck(namespaceOid, GetUserId(), ACL_CREATE);
if (aclresult != ACLCHECK_OK)
aclcheck_error(aclresult, 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);
}
/*
* SetFunctionReturnType - change declared return type of a function
*