@@ -3520,18 +3520,22 @@ AlterTypeNamespaceInternal(Oid typeOid, Oid nspOid,
35203520 oldNspOid = typform -> typnamespace ;
35213521 arrayOid = typform -> typarray ;
35223522
3523- /* common checks on switching namespaces */
3524- CheckSetNamespace (oldNspOid , nspOid , TypeRelationId , typeOid );
3523+ /* If the type is already there, we scan skip these next few checks. */
3524+ if (oldNspOid != nspOid )
3525+ {
3526+ /* common checks on switching namespaces */
3527+ CheckSetNamespace (oldNspOid , nspOid );
35253528
3526- /* check for duplicate name (more friendly than unique-index failure) */
3527- if (SearchSysCacheExists2 (TYPENAMENSP ,
3528- CStringGetDatum (NameStr (typform -> typname )),
3529- ObjectIdGetDatum (nspOid )))
3530- ereport (ERROR ,
3531- (errcode (ERRCODE_DUPLICATE_OBJECT ),
3532- errmsg ("type \"%s\" already exists in schema \"%s\"" ,
3533- NameStr (typform -> typname ),
3534- get_namespace_name (nspOid ))));
3529+ /* check for duplicate name (more friendly than unique-index failure) */
3530+ if (SearchSysCacheExists2 (TYPENAMENSP ,
3531+ CStringGetDatum (NameStr (typform -> typname )),
3532+ ObjectIdGetDatum (nspOid )))
3533+ ereport (ERROR ,
3534+ (errcode (ERRCODE_DUPLICATE_OBJECT ),
3535+ errmsg ("type \"%s\" already exists in schema \"%s\"" ,
3536+ NameStr (typform -> typname ),
3537+ get_namespace_name (nspOid ))));
3538+ }
35353539
35363540 /* Detect whether type is a composite type (but not a table rowtype) */
35373541 isCompositeType =
@@ -3547,13 +3551,16 @@ AlterTypeNamespaceInternal(Oid typeOid, Oid nspOid,
35473551 format_type_be (typeOid )),
35483552 errhint ("Use ALTER TABLE instead." )));
35493553
3550- /* OK, modify the pg_type row */
3554+ if (oldNspOid != nspOid )
3555+ {
3556+ /* OK, modify the pg_type row */
35513557
3552- /* tup is a copy, so we can scribble directly on it */
3553- typform -> typnamespace = nspOid ;
3558+ /* tup is a copy, so we can scribble directly on it */
3559+ typform -> typnamespace = nspOid ;
35543560
3555- simple_heap_update (rel , & tup -> t_self , tup );
3556- CatalogUpdateIndexes (rel , tup );
3561+ simple_heap_update (rel , & tup -> t_self , tup );
3562+ CatalogUpdateIndexes (rel , tup );
3563+ }
35573564
35583565 /*
35593566 * Composite types have pg_class entries.
@@ -3592,7 +3599,8 @@ AlterTypeNamespaceInternal(Oid typeOid, Oid nspOid,
35923599 * Update dependency on schema, if any --- a table rowtype has not got
35933600 * one, and neither does an implicit array.
35943601 */
3595- if ((isCompositeType || typform -> typtype != TYPTYPE_COMPOSITE ) &&
3602+ if (oldNspOid != nspOid &&
3603+ (isCompositeType || typform -> typtype != TYPTYPE_COMPOSITE ) &&
35963604 !isImplicitArray )
35973605 if (changeDependencyFor (TypeRelationId , typeOid ,
35983606 NamespaceRelationId , oldNspOid , nspOid ) != 1 )
0 commit comments