mirror of
https://github.com/postgres/postgres.git
synced 2025-10-25 13:17:41 +03:00
Centralize some ALTER <whatever> .. SET SCHEMA checks.
Any flavor of ALTER <whatever> .. SET SCHEMA fails if (1) the object is already in the new schema, (2) either the old or new schema is a temp schema, or (3) either the old or new schema is the TOAST schema. Extraced from a patch by Dimitri Fontaine, with additional hacking by me.
This commit is contained in:
@@ -1899,24 +1899,8 @@ AlterFunctionNamespace(List *name, List *argtypes, bool isagg,
|
||||
/* get schema OID and check its permissions */
|
||||
nspOid = LookupCreationNamespace(newschema);
|
||||
|
||||
if (oldNspOid == nspOid)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_DUPLICATE_FUNCTION),
|
||||
errmsg("function \"%s\" is already in schema \"%s\"",
|
||||
NameListToString(name),
|
||||
newschema)));
|
||||
|
||||
/* disallow renaming into or out of temp schemas */
|
||||
if (isAnyTempNamespace(nspOid) || isAnyTempNamespace(oldNspOid))
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("cannot move objects into or out of temporary schemas")));
|
||||
|
||||
/* same for TOAST schema */
|
||||
if (nspOid == PG_TOAST_NAMESPACE || oldNspOid == PG_TOAST_NAMESPACE)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("cannot move objects into or out of TOAST schema")));
|
||||
/* common checks on switching namespaces */
|
||||
CheckSetNamespace(oldNspOid, nspOid, ProcedureRelationId, procOid);
|
||||
|
||||
/* check for duplicate name (more friendly than unique-index failure) */
|
||||
if (SearchSysCacheExists3(PROCNAMEARGSNSP,
|
||||
|
||||
@@ -8114,24 +8114,8 @@ AlterTableNamespace(RangeVar *relation, const char *newschema,
|
||||
/* get schema OID and check its permissions */
|
||||
nspOid = LookupCreationNamespace(newschema);
|
||||
|
||||
if (oldNspOid == nspOid)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_DUPLICATE_TABLE),
|
||||
errmsg("relation \"%s\" is already in schema \"%s\"",
|
||||
RelationGetRelationName(rel),
|
||||
newschema)));
|
||||
|
||||
/* disallow renaming into or out of temp schemas */
|
||||
if (isAnyTempNamespace(nspOid) || isAnyTempNamespace(oldNspOid))
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("cannot move objects into or out of temporary schemas")));
|
||||
|
||||
/* same for TOAST schema */
|
||||
if (nspOid == PG_TOAST_NAMESPACE || oldNspOid == PG_TOAST_NAMESPACE)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("cannot move objects into or out of TOAST schema")));
|
||||
/* common checks on switching namespaces */
|
||||
CheckSetNamespace(oldNspOid, nspOid, RelationRelationId, relid);
|
||||
|
||||
/* OK, modify the pg_class row and pg_depend entry */
|
||||
classRel = heap_open(RelationRelationId, RowExclusiveLock);
|
||||
|
||||
@@ -2828,24 +2828,8 @@ AlterTypeNamespaceInternal(Oid typeOid, Oid nspOid,
|
||||
oldNspOid = typform->typnamespace;
|
||||
arrayOid = typform->typarray;
|
||||
|
||||
if (oldNspOid == nspOid)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_DUPLICATE_OBJECT),
|
||||
errmsg("type %s is already in schema \"%s\"",
|
||||
format_type_be(typeOid),
|
||||
get_namespace_name(nspOid))));
|
||||
|
||||
/* disallow renaming into or out of temp schemas */
|
||||
if (isAnyTempNamespace(nspOid) || isAnyTempNamespace(oldNspOid))
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("cannot move objects into or out of temporary schemas")));
|
||||
|
||||
/* same for TOAST schema */
|
||||
if (nspOid == PG_TOAST_NAMESPACE || oldNspOid == PG_TOAST_NAMESPACE)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("cannot move objects into or out of TOAST schema")));
|
||||
/* common checks on switching namespaces */
|
||||
CheckSetNamespace(oldNspOid, nspOid, TypeRelationId, typeOid);
|
||||
|
||||
/* check for duplicate name (more friendly than unique-index failure) */
|
||||
if (SearchSysCacheExists2(TYPENAMENSP,
|
||||
|
||||
Reference in New Issue
Block a user