+ /* Normal dependency from a domain to its base type. */
+ if (OidIsValid(baseType))
+ {
+ referenced.classId = TypeRelationId;
+ referenced.objectId = baseType;
+ referenced.objectSubId = 0;
+ recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
+ }
+
+ /* Normal dependency on the default expression. */
+ if (defaultExpr)
+ recordDependencyOnExpr(&myself, defaultExpr, NIL, DEPENDENCY_NORMAL);
+
+ /* Shared dependency on owner. */
+ recordDependencyOnOwner(TypeRelationId, typeObjectId, owner);
+}
+
+/*
+ * TypeRename
+ * This renames a type
+ *
+ * Note: any associated array type is *not* renamed; caller must make
+ * another call to handle that case. Currently this is only used for
+ * renaming types associated with tables, for which there are no arrays.
+ */
+void
+TypeRename(const char *oldTypeName, Oid typeNamespace,
+ const char *newTypeName)
+{
+ Relation pg_type_desc;
+ HeapTuple tuple;
+
+ pg_type_desc = heap_open(TypeRelationId, RowExclusiveLock);
+
+ tuple = SearchSysCacheCopy(TYPENAMENSP,
+ CStringGetDatum(oldTypeName),
+ ObjectIdGetDatum(typeNamespace),
+ 0, 0);
+ if (!HeapTupleIsValid(tuple))
+ ereport(ERROR,
+ (errcode(ERRCODE_UNDEFINED_OBJECT),
+ errmsg("type \"%s\" does not exist", oldTypeName)));
+
+ if (SearchSysCacheExists(TYPENAMENSP,
+ CStringGetDatum(newTypeName),
+ ObjectIdGetDatum(typeNamespace),
+ 0, 0))
+ ereport(ERROR,
+ (errcode(ERRCODE_DUPLICATE_OBJECT),
+ errmsg("type \"%s\" already exists", newTypeName)));
+
+ namestrcpy(&(((Form_pg_type) GETSTRUCT(tuple))->typname), newTypeName);
+
+ simple_heap_update(pg_type_desc, &tuple->t_self, tuple);
+
+ /* update the system catalog indexes */
+ CatalogUpdateIndexes(pg_type_desc, tuple);
+
+ heap_freetuple(tuple);
+ heap_close(pg_type_desc, RowExclusiveLock);