MCPcopy Create free account
hub / github.com/apache/cloudberry / RenameType

Function RenameType

src/backend/commands/typecmds.c:3722–3794  ·  view source on GitHub ↗

* Execute ALTER TYPE RENAME */

Source from the content-addressed store, hash-verified

3720 * Execute ALTER TYPE RENAME
3721 */
3722ObjectAddress
3723RenameType(RenameStmt *stmt)
3724{
3725 List *names = castNode(List, stmt->object);
3726 const char *newTypeName = stmt->newname;
3727 TypeName *typename;
3728 Oid typeOid;
3729 Relation rel;
3730 HeapTuple tup;
3731 Form_pg_type typTup;
3732 ObjectAddress address;
3733
3734 /* Make a TypeName so we can use standard type lookup machinery */
3735 typename = makeTypeNameFromNameList(names);
3736 typeOid = typenameTypeId(NULL, typename);
3737
3738 /* Look up the type in the type table */
3739 rel = table_open(TypeRelationId, RowExclusiveLock);
3740
3741 tup = SearchSysCacheCopy1(TYPEOID, ObjectIdGetDatum(typeOid));
3742 if (!HeapTupleIsValid(tup))
3743 elog(ERROR, "cache lookup failed for type %u", typeOid);
3744 typTup = (Form_pg_type) GETSTRUCT(tup);
3745
3746 /* check permissions on type */
3747 if (!pg_type_ownercheck(typeOid, GetUserId()))
3748 aclcheck_error_type(ACLCHECK_NOT_OWNER, typeOid);
3749
3750 /* ALTER DOMAIN used on a non-domain? */
3751 if (stmt->renameType == OBJECT_DOMAIN && typTup->typtype != TYPTYPE_DOMAIN)
3752 ereport(ERROR,
3753 (errcode(ERRCODE_WRONG_OBJECT_TYPE),
3754 errmsg("%s is not a domain",
3755 format_type_be(typeOid))));
3756
3757 /*
3758 * If it's a composite type, we need to check that it really is a
3759 * free-standing composite type, and not a table's rowtype. We want people
3760 * to use ALTER TABLE not ALTER TYPE for that case.
3761 */
3762 if (typTup->typtype == TYPTYPE_COMPOSITE &&
3763 get_rel_relkind(typTup->typrelid) != RELKIND_COMPOSITE_TYPE)
3764 ereport(ERROR,
3765 (errcode(ERRCODE_WRONG_OBJECT_TYPE),
3766 errmsg("%s is a table's row type",
3767 format_type_be(typeOid)),
3768 errhint("Use ALTER TABLE instead.")));
3769
3770 /* don't allow direct alteration of array types, either */
3771 if (IsTrueArrayType(typTup))
3772 ereport(ERROR,
3773 (errcode(ERRCODE_WRONG_OBJECT_TYPE),
3774 errmsg("cannot alter array type %s",
3775 format_type_be(typeOid)),
3776 errhint("You can alter type %s, which will alter the array type as well.",
3777 format_type_be(typTup->typelem))));
3778
3779 /*

Callers 1

ExecRenameStmt_internalFunction · 0.85

Calls 15

makeTypeNameFromNameListFunction · 0.85
typenameTypeIdFunction · 0.85
table_openFunction · 0.85
ObjectIdGetDatumFunction · 0.85
pg_type_ownercheckFunction · 0.85
GetUserIdFunction · 0.85
aclcheck_error_typeFunction · 0.85
format_type_beFunction · 0.85
get_rel_relkindFunction · 0.85
RenameRelationInternalFunction · 0.85
RenameTypeInternalFunction · 0.85
table_closeFunction · 0.85

Tested by

no test coverage detected