* Change the owner of a type. */
| 3797 | * Change the owner of a type. |
| 3798 | */ |
| 3799 | ObjectAddress |
| 3800 | AlterTypeOwner(List *names, Oid newOwnerId, ObjectType objecttype) |
| 3801 | { |
| 3802 | TypeName *typename; |
| 3803 | Oid typeOid; |
| 3804 | Relation rel; |
| 3805 | HeapTuple tup; |
| 3806 | HeapTuple newtup; |
| 3807 | Form_pg_type typTup; |
| 3808 | AclResult aclresult; |
| 3809 | ObjectAddress address; |
| 3810 | |
| 3811 | rel = table_open(TypeRelationId, RowExclusiveLock); |
| 3812 | |
| 3813 | /* Make a TypeName so we can use standard type lookup machinery */ |
| 3814 | typename = makeTypeNameFromNameList(names); |
| 3815 | |
| 3816 | /* Use LookupTypeName here so that shell types can be processed */ |
| 3817 | tup = LookupTypeName(NULL, typename, NULL, false); |
| 3818 | if (tup == NULL) |
| 3819 | ereport(ERROR, |
| 3820 | (errcode(ERRCODE_UNDEFINED_OBJECT), |
| 3821 | errmsg("type \"%s\" does not exist", |
| 3822 | TypeNameToString(typename)))); |
| 3823 | typeOid = typeTypeId(tup); |
| 3824 | |
| 3825 | /* Copy the syscache entry so we can scribble on it below */ |
| 3826 | newtup = heap_copytuple(tup); |
| 3827 | ReleaseSysCache(tup); |
| 3828 | tup = newtup; |
| 3829 | typTup = (Form_pg_type) GETSTRUCT(tup); |
| 3830 | |
| 3831 | /* Don't allow ALTER DOMAIN on a type */ |
| 3832 | if (objecttype == OBJECT_DOMAIN && typTup->typtype != TYPTYPE_DOMAIN) |
| 3833 | ereport(ERROR, |
| 3834 | (errcode(ERRCODE_WRONG_OBJECT_TYPE), |
| 3835 | errmsg("%s is not a domain", |
| 3836 | format_type_be(typeOid)))); |
| 3837 | |
| 3838 | /* |
| 3839 | * If it's a composite type, we need to check that it really is a |
| 3840 | * free-standing composite type, and not a table's rowtype. We want people |
| 3841 | * to use ALTER TABLE not ALTER TYPE for that case. |
| 3842 | */ |
| 3843 | if (typTup->typtype == TYPTYPE_COMPOSITE && |
| 3844 | get_rel_relkind(typTup->typrelid) != RELKIND_COMPOSITE_TYPE) |
| 3845 | ereport(ERROR, |
| 3846 | (errcode(ERRCODE_WRONG_OBJECT_TYPE), |
| 3847 | errmsg("%s is a table's row type", |
| 3848 | format_type_be(typeOid)), |
| 3849 | errhint("Use ALTER TABLE instead."))); |
| 3850 | |
| 3851 | /* don't allow direct alteration of array types, either */ |
| 3852 | if (IsTrueArrayType(typTup)) |
| 3853 | ereport(ERROR, |
| 3854 | (errcode(ERRCODE_WRONG_OBJECT_TYPE), |
| 3855 | errmsg("cannot alter array type %s", |
| 3856 | format_type_be(typeOid)), |
no test coverage detected