mirror of
https://github.com/postgres/postgres.git
synced 2025-07-28 23:42:10 +03: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:
@ -213,7 +213,7 @@ ExecAlterObjectSchemaStmt(AlterObjectSchemaStmt *stmt)
|
|||||||
|
|
||||||
case OBJECT_TYPE:
|
case OBJECT_TYPE:
|
||||||
case OBJECT_DOMAIN:
|
case OBJECT_DOMAIN:
|
||||||
AlterTypeNamespace(stmt->object, stmt->newschema);
|
AlterTypeNamespace(stmt->object, stmt->newschema, stmt->objectType);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@ -510,7 +510,7 @@ ExecAlterOwnerStmt(AlterOwnerStmt *stmt)
|
|||||||
|
|
||||||
case OBJECT_TYPE:
|
case OBJECT_TYPE:
|
||||||
case OBJECT_DOMAIN: /* same as TYPE */
|
case OBJECT_DOMAIN: /* same as TYPE */
|
||||||
AlterTypeOwner(stmt->object, newowner);
|
AlterTypeOwner(stmt->object, newowner, stmt->objectType);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case OBJECT_TSDICTIONARY:
|
case OBJECT_TSDICTIONARY:
|
||||||
|
@ -3165,7 +3165,7 @@ RenameType(RenameStmt *stmt)
|
|||||||
* Change the owner of a type.
|
* Change the owner of a type.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
AlterTypeOwner(List *names, Oid newOwnerId)
|
AlterTypeOwner(List *names, Oid newOwnerId, ObjectType objecttype)
|
||||||
{
|
{
|
||||||
TypeName *typename;
|
TypeName *typename;
|
||||||
Oid typeOid;
|
Oid typeOid;
|
||||||
@ -3195,6 +3195,13 @@ AlterTypeOwner(List *names, Oid newOwnerId)
|
|||||||
tup = newtup;
|
tup = newtup;
|
||||||
typTup = (Form_pg_type) GETSTRUCT(tup);
|
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
|
* 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
|
* 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
|
* Execute ALTER TYPE SET SCHEMA
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
AlterTypeNamespace(List *names, const char *newschema)
|
AlterTypeNamespace(List *names, const char *newschema, ObjectType objecttype)
|
||||||
{
|
{
|
||||||
TypeName *typename;
|
TypeName *typename;
|
||||||
Oid typeOid;
|
Oid typeOid;
|
||||||
@ -3338,6 +3345,13 @@ AlterTypeNamespace(List *names, const char *newschema)
|
|||||||
typename = makeTypeNameFromNameList(names);
|
typename = makeTypeNameFromNameList(names);
|
||||||
typeOid = typenameTypeId(NULL, typename);
|
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 */
|
/* get schema OID and check its permissions */
|
||||||
nspOid = LookupCreationNamespace(newschema);
|
nspOid = LookupCreationNamespace(newschema);
|
||||||
|
|
||||||
|
@ -38,10 +38,10 @@ extern void AlterDomainDropConstraint(List *names, const char *constrName,
|
|||||||
extern List *GetDomainConstraints(Oid typeOid);
|
extern List *GetDomainConstraints(Oid typeOid);
|
||||||
|
|
||||||
extern void RenameType(RenameStmt *stmt);
|
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,
|
extern void AlterTypeOwnerInternal(Oid typeOid, Oid newOwnerId,
|
||||||
bool hasDependEntry);
|
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 AlterTypeNamespace_oid(Oid typeOid, Oid nspOid);
|
||||||
extern Oid AlterTypeNamespaceInternal(Oid typeOid, Oid nspOid,
|
extern Oid AlterTypeNamespaceInternal(Oid typeOid, Oid nspOid,
|
||||||
bool isImplicitArray,
|
bool isImplicitArray,
|
||||||
|
Reference in New Issue
Block a user