diff options
| author | Robert Haas <rhaas@postgresql.org> | 2010-11-22 19:46:15 -0500 |
|---|---|---|
| committer | Robert Haas <rhaas@postgresql.org> | 2010-11-22 19:53:34 -0500 |
| commit | 44475e782f4674d257b9e5c1a3930218a4b4deea (patch) | |
| tree | 2bf5afa62c678a3a29abfbadf41a41682837c809 /src/backend/catalog/namespace.c | |
| parent | 5272d7987506554f6b2bde740e1b4d7e4a0b8608 (diff) | |
| download | postgresql-44475e782f4674d257b9e5c1a3930218a4b4deea.tar.gz | |
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.
Diffstat (limited to 'src/backend/catalog/namespace.c')
| -rw-r--r-- | src/backend/catalog/namespace.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/backend/catalog/namespace.c b/src/backend/catalog/namespace.c index 3727146ea0..653c9ada11 100644 --- a/src/backend/catalog/namespace.c +++ b/src/backend/catalog/namespace.c @@ -2340,6 +2340,40 @@ LookupCreationNamespace(const char *nspname) } /* + * Common checks on switching namespaces. + * + * We complain if (1) the old and new namespaces are the same, (2) either the + * old or new namespaces is a temporary schema (or temporary toast schema), or + * (3) either the old or new namespaces is the TOAST schema. + */ +void +CheckSetNamespace(Oid oldNspOid, Oid nspOid, Oid classid, Oid objid) +{ + if (oldNspOid == nspOid) + ereport(ERROR, + (classid == RelationRelationId ? + errcode(ERRCODE_DUPLICATE_TABLE) : + classid == ProcedureRelationId ? + errcode(ERRCODE_DUPLICATE_FUNCTION) : + errcode(ERRCODE_DUPLICATE_OBJECT), + errmsg("%s is already in schema \"%s\"", + getObjectDescriptionOids(classid, objid), + 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"))); +} + +/* * QualifiedNameGetCreationNamespace * Given a possibly-qualified name for an object (in List-of-Values * format), determine what namespace the object should be created in. |
