mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-12-15 08:20:16 +08:00
Disallow ALTER DOMAIN on non-domain type everywhere
This has been the behavior already in most cases, but through omission, ALTER DOMAIN / OWNER TO and ALTER DOMAIN / SET SCHEMA would silently work on non-domain types as well.
This commit is contained in:
parent
8137f2c323
commit
2787458362
@ -213,7 +213,7 @@ ExecAlterObjectSchemaStmt(AlterObjectSchemaStmt *stmt)
|
||||
|
||||
case OBJECT_TYPE:
|
||||
case OBJECT_DOMAIN:
|
||||
AlterTypeNamespace(stmt->object, stmt->newschema);
|
||||
AlterTypeNamespace(stmt->object, stmt->newschema, stmt->objectType);
|
||||
break;
|
||||
|
||||
default:
|
||||
@ -510,7 +510,7 @@ ExecAlterOwnerStmt(AlterOwnerStmt *stmt)
|
||||
|
||||
case OBJECT_TYPE:
|
||||
case OBJECT_DOMAIN: /* same as TYPE */
|
||||
AlterTypeOwner(stmt->object, newowner);
|
||||
AlterTypeOwner(stmt->object, newowner, stmt->objectType);
|
||||
break;
|
||||
|
||||
case OBJECT_TSDICTIONARY:
|
||||
|
@ -3165,7 +3165,7 @@ RenameType(RenameStmt *stmt)
|
||||
* Change the owner of a type.
|
||||
*/
|
||||
void
|
||||
AlterTypeOwner(List *names, Oid newOwnerId)
|
||||
AlterTypeOwner(List *names, Oid newOwnerId, ObjectType objecttype)
|
||||
{
|
||||
TypeName *typename;
|
||||
Oid typeOid;
|
||||
@ -3195,6 +3195,13 @@ AlterTypeOwner(List *names, Oid newOwnerId)
|
||||
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
|
||||
@ -3328,7 +3335,7 @@ AlterTypeOwnerInternal(Oid typeOid, Oid newOwnerId,
|
||||
* Execute ALTER TYPE SET SCHEMA
|
||||
*/
|
||||
void
|
||||
AlterTypeNamespace(List *names, const char *newschema)
|
||||
AlterTypeNamespace(List *names, const char *newschema, ObjectType objecttype)
|
||||
{
|
||||
TypeName *typename;
|
||||
Oid typeOid;
|
||||
@ -3338,6 +3345,13 @@ AlterTypeNamespace(List *names, const char *newschema)
|
||||
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);
|
||||
|
||||
|
@ -38,10 +38,10 @@ extern void AlterDomainDropConstraint(List *names, const char *constrName,
|
||||
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,
|
||||
|
Loading…
Reference in New Issue
Block a user