case OBJECT_TYPE:
case OBJECT_DOMAIN:
- AlterTypeNamespace(stmt->object, stmt->newschema);
+ AlterTypeNamespace(stmt->object, stmt->newschema, stmt->objectType);
break;
default:
case OBJECT_TYPE:
case OBJECT_DOMAIN: /* same as TYPE */
- AlterTypeOwner(stmt->object, newowner);
+ AlterTypeOwner(stmt->object, newowner, stmt->objectType);
break;
case OBJECT_TSDICTIONARY:
* Change the owner of a type.
*/
void
-AlterTypeOwner(List *names, Oid newOwnerId)
+AlterTypeOwner(List *names, Oid newOwnerId, ObjectType objecttype)
{
TypeName *typename;
Oid typeOid;
tup = newtup;
typTup = (Form_pg_type) GETSTRUCT(tup);
+ /* Don't allow ALTER DOMAIN on a type */
+ if (objecttype == OBJECT_DOMAIN && typTup->typtype != TYPTYPE_DOMAIN)
+ ereport(ERROR,
+ (errcode(ERRCODE_WRONG_OBJECT_TYPE),
+ errmsg("%s is not a domain",
+ format_type_be(typeOid))));
+
/*
* If it's a composite type, we need to check that it really is a
* free-standing composite type, and not a table's rowtype. We want people
* Execute ALTER TYPE SET SCHEMA
*/
void
-AlterTypeNamespace(List *names, const char *newschema)
+AlterTypeNamespace(List *names, const char *newschema, ObjectType objecttype)
{
TypeName *typename;
Oid typeOid;
typename = makeTypeNameFromNameList(names);
typeOid = typenameTypeId(NULL, typename);
+ /* Don't allow ALTER DOMAIN on a type */
+ if (objecttype == OBJECT_DOMAIN && get_typtype(typeOid) != TYPTYPE_DOMAIN)
+ ereport(ERROR,
+ (errcode(ERRCODE_WRONG_OBJECT_TYPE),
+ errmsg("%s is not a domain",
+ format_type_be(typeOid))));
+
/* get schema OID and check its permissions */
nspOid = LookupCreationNamespace(newschema);
extern List *GetDomainConstraints(Oid typeOid);
extern void RenameType(RenameStmt *stmt);
-extern void AlterTypeOwner(List *names, Oid newOwnerId);
+extern void AlterTypeOwner(List *names, Oid newOwnerId, ObjectType objecttype);
extern void AlterTypeOwnerInternal(Oid typeOid, Oid newOwnerId,
bool hasDependEntry);
-extern void AlterTypeNamespace(List *names, const char *newschema);
+extern void AlterTypeNamespace(List *names, const char *newschema, ObjectType objecttype);
extern Oid AlterTypeNamespace_oid(Oid typeOid, Oid nspOid);
extern Oid AlterTypeNamespaceInternal(Oid typeOid, Oid nspOid,
bool isImplicitArray,