aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands/functioncmds.c
diff options
context:
space:
mode:
authorAlvaro Herrera <alvherre@alvh.no-ip.org>2012-09-27 18:13:09 -0300
committerAlvaro Herrera <alvherre@alvh.no-ip.org>2012-10-02 18:13:54 -0300
commit2164f9a1254980a02ef9ca99ee3bcb8c1298b219 (patch)
treeee8a05a3997289cbcde799728f1b4a81601bc64c /src/backend/commands/functioncmds.c
parenta563d941803535dbd27d4191fe7729497b7fdf31 (diff)
downloadpostgresql-2164f9a1254980a02ef9ca99ee3bcb8c1298b219.tar.gz
postgresql-2164f9a1254980a02ef9ca99ee3bcb8c1298b219.zip
Refactor "ALTER some-obj SET SCHEMA" implementation
Instead of having each object type implement the catalog munging independently, centralize knowledge about how to do it and expand the existing table in objectaddress.c with enough data about each object type to support this operation. Author: KaiGai Kohei Tweaks by me Reviewed by Robert Haas
Diffstat (limited to 'src/backend/commands/functioncmds.c')
-rw-r--r--src/backend/commands/functioncmds.c33
1 files changed, 8 insertions, 25 deletions
diff --git a/src/backend/commands/functioncmds.c b/src/backend/commands/functioncmds.c
index bf040730fa0..ef6eadc95fd 100644
--- a/src/backend/commands/functioncmds.c
+++ b/src/backend/commands/functioncmds.c
@@ -47,6 +47,7 @@
#include "catalog/pg_proc_fn.h"
#include "catalog/pg_type.h"
#include "catalog/pg_type_fn.h"
+#include "commands/alter.h"
#include "commands/defrem.h"
#include "commands/proclang.h"
#include "miscadmin.h"
@@ -1851,21 +1852,16 @@ AlterFunctionNamespace_oid(Oid procOid, Oid nspOid)
procRel = heap_open(ProcedureRelationId, RowExclusiveLock);
+ /*
+ * We have to check for name collisions ourselves, because
+ * AlterObjectNamespace_internal doesn't know how to deal with the
+ * argument types.
+ */
tup = SearchSysCacheCopy1(PROCOID, ObjectIdGetDatum(procOid));
if (!HeapTupleIsValid(tup))
elog(ERROR, "cache lookup failed for function %u", procOid);
proc = (Form_pg_proc) GETSTRUCT(tup);
- /* check permissions on function */
- if (!pg_proc_ownercheck(procOid, GetUserId()))
- aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_PROC,
- NameStr(proc->proname));
-
- oldNspOid = proc->pronamespace;
-
- /* common checks on switching namespaces */
- CheckSetNamespace(oldNspOid, nspOid, ProcedureRelationId, procOid);
-
/* check for duplicate name (more friendly than unique-index failure) */
if (SearchSysCacheExists3(PROCNAMEARGSNSP,
CStringGetDatum(NameStr(proc->proname)),
@@ -1877,21 +1873,8 @@ AlterFunctionNamespace_oid(Oid procOid, Oid nspOid)
NameStr(proc->proname),
get_namespace_name(nspOid))));
- /* OK, modify the pg_proc row */
-
- /* tup is a copy, so we can scribble directly on it */
- proc->pronamespace = nspOid;
-
- simple_heap_update(procRel, &tup->t_self, tup);
- CatalogUpdateIndexes(procRel, tup);
-
- /* Update dependency on schema */
- if (changeDependencyFor(ProcedureRelationId, procOid,
- NamespaceRelationId, oldNspOid, nspOid) != 1)
- elog(ERROR, "failed to change schema dependency for function \"%s\"",
- NameStr(proc->proname));
-
- heap_freetuple(tup);
+ /* OK, do the work */
+ oldNspOid = AlterObjectNamespace_internal(procRel, procOid, nspOid);
heap_close(procRel, RowExclusiveLock);