aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands/typecmds.c
diff options
context:
space:
mode:
authorRobert Haas <rhaas@postgresql.org>2015-11-19 10:49:25 -0500
committerRobert Haas <rhaas@postgresql.org>2015-11-19 10:49:25 -0500
commitbc4996e61b98d41eacf991c18508b7a2305a68c6 (patch)
treeb0f8404f7f1fe62f6fe0c530c23e4c70acc7dede /src/backend/commands/typecmds.c
parentf11c557e92c50d3d613d1173c15feb5310ba4744 (diff)
downloadpostgresql-bc4996e61b98d41eacf991c18508b7a2305a68c6.tar.gz
postgresql-bc4996e61b98d41eacf991c18508b7a2305a68c6.zip
Make ALTER .. SET SCHEMA do nothing, instead of throwing an ERROR.
This was already true for CREATE EXTENSION, but historically has not been true for other object types. Therefore, this is a backward incompatibility. Per discussion on pgsql-hackers, everyone seems to agree that the new behavior is better. Marti Raudsepp, reviewed by Haribabu Kommi and myself
Diffstat (limited to 'src/backend/commands/typecmds.c')
-rw-r--r--src/backend/commands/typecmds.c42
1 files changed, 25 insertions, 17 deletions
diff --git a/src/backend/commands/typecmds.c b/src/backend/commands/typecmds.c
index d2b3f2297b2..a126e666d88 100644
--- a/src/backend/commands/typecmds.c
+++ b/src/backend/commands/typecmds.c
@@ -3520,18 +3520,22 @@ AlterTypeNamespaceInternal(Oid typeOid, Oid nspOid,
oldNspOid = typform->typnamespace;
arrayOid = typform->typarray;
- /* common checks on switching namespaces */
- CheckSetNamespace(oldNspOid, nspOid, TypeRelationId, typeOid);
+ /* If the type is already there, we scan skip these next few checks. */
+ if (oldNspOid != nspOid)
+ {
+ /* common checks on switching namespaces */
+ CheckSetNamespace(oldNspOid, nspOid);
- /* check for duplicate name (more friendly than unique-index failure) */
- if (SearchSysCacheExists2(TYPENAMENSP,
- CStringGetDatum(NameStr(typform->typname)),
- ObjectIdGetDatum(nspOid)))
- ereport(ERROR,
- (errcode(ERRCODE_DUPLICATE_OBJECT),
- errmsg("type \"%s\" already exists in schema \"%s\"",
- NameStr(typform->typname),
- get_namespace_name(nspOid))));
+ /* check for duplicate name (more friendly than unique-index failure) */
+ if (SearchSysCacheExists2(TYPENAMENSP,
+ CStringGetDatum(NameStr(typform->typname)),
+ ObjectIdGetDatum(nspOid)))
+ ereport(ERROR,
+ (errcode(ERRCODE_DUPLICATE_OBJECT),
+ errmsg("type \"%s\" already exists in schema \"%s\"",
+ NameStr(typform->typname),
+ get_namespace_name(nspOid))));
+ }
/* Detect whether type is a composite type (but not a table rowtype) */
isCompositeType =
@@ -3547,13 +3551,16 @@ AlterTypeNamespaceInternal(Oid typeOid, Oid nspOid,
format_type_be(typeOid)),
errhint("Use ALTER TABLE instead.")));
- /* OK, modify the pg_type row */
+ if (oldNspOid != nspOid)
+ {
+ /* OK, modify the pg_type row */
- /* tup is a copy, so we can scribble directly on it */
- typform->typnamespace = nspOid;
+ /* tup is a copy, so we can scribble directly on it */
+ typform->typnamespace = nspOid;
- simple_heap_update(rel, &tup->t_self, tup);
- CatalogUpdateIndexes(rel, tup);
+ simple_heap_update(rel, &tup->t_self, tup);
+ CatalogUpdateIndexes(rel, tup);
+ }
/*
* Composite types have pg_class entries.
@@ -3592,7 +3599,8 @@ AlterTypeNamespaceInternal(Oid typeOid, Oid nspOid,
* Update dependency on schema, if any --- a table rowtype has not got
* one, and neither does an implicit array.
*/
- if ((isCompositeType || typform->typtype != TYPTYPE_COMPOSITE) &&
+ if (oldNspOid != nspOid &&
+ (isCompositeType || typform->typtype != TYPTYPE_COMPOSITE) &&
!isImplicitArray)
if (changeDependencyFor(TypeRelationId, typeOid,
NamespaceRelationId, oldNspOid, nspOid) != 1)