Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 2787458

Browse files
committed
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.
1 parent 8137f2c commit 2787458

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

src/backend/commands/alter.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ ExecAlterObjectSchemaStmt(AlterObjectSchemaStmt *stmt)
213213

214214
case OBJECT_TYPE:
215215
case OBJECT_DOMAIN:
216-
AlterTypeNamespace(stmt->object, stmt->newschema);
216+
AlterTypeNamespace(stmt->object, stmt->newschema, stmt->objectType);
217217
break;
218218

219219
default:
@@ -510,7 +510,7 @@ ExecAlterOwnerStmt(AlterOwnerStmt *stmt)
510510

511511
case OBJECT_TYPE:
512512
case OBJECT_DOMAIN: /* same as TYPE */
513-
AlterTypeOwner(stmt->object, newowner);
513+
AlterTypeOwner(stmt->object, newowner, stmt->objectType);
514514
break;
515515

516516
case OBJECT_TSDICTIONARY:

src/backend/commands/typecmds.c

+16-2
Original file line numberDiff line numberDiff line change
@@ -3165,7 +3165,7 @@ RenameType(RenameStmt *stmt)
31653165
* Change the owner of a type.
31663166
*/
31673167
void
3168-
AlterTypeOwner(List *names, Oid newOwnerId)
3168+
AlterTypeOwner(List *names, Oid newOwnerId, ObjectType objecttype)
31693169
{
31703170
TypeName *typename;
31713171
Oid typeOid;
@@ -3195,6 +3195,13 @@ AlterTypeOwner(List *names, Oid newOwnerId)
31953195
tup = newtup;
31963196
typTup = (Form_pg_type) GETSTRUCT(tup);
31973197

3198+
/* Don't allow ALTER DOMAIN on a type */
3199+
if (objecttype == OBJECT_DOMAIN && typTup->typtype != TYPTYPE_DOMAIN)
3200+
ereport(ERROR,
3201+
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
3202+
errmsg("%s is not a domain",
3203+
format_type_be(typeOid))));
3204+
31983205
/*
31993206
* If it's a composite type, we need to check that it really is a
32003207
* free-standing composite type, and not a table's rowtype. We want people
@@ -3328,7 +3335,7 @@ AlterTypeOwnerInternal(Oid typeOid, Oid newOwnerId,
33283335
* Execute ALTER TYPE SET SCHEMA
33293336
*/
33303337
void
3331-
AlterTypeNamespace(List *names, const char *newschema)
3338+
AlterTypeNamespace(List *names, const char *newschema, ObjectType objecttype)
33323339
{
33333340
TypeName *typename;
33343341
Oid typeOid;
@@ -3338,6 +3345,13 @@ AlterTypeNamespace(List *names, const char *newschema)
33383345
typename = makeTypeNameFromNameList(names);
33393346
typeOid = typenameTypeId(NULL, typename);
33403347

3348+
/* Don't allow ALTER DOMAIN on a type */
3349+
if (objecttype == OBJECT_DOMAIN && get_typtype(typeOid) != TYPTYPE_DOMAIN)
3350+
ereport(ERROR,
3351+
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
3352+
errmsg("%s is not a domain",
3353+
format_type_be(typeOid))));
3354+
33413355
/* get schema OID and check its permissions */
33423356
nspOid = LookupCreationNamespace(newschema);
33433357

src/include/commands/typecmds.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ extern void AlterDomainDropConstraint(List *names, const char *constrName,
3838
extern List *GetDomainConstraints(Oid typeOid);
3939

4040
extern void RenameType(RenameStmt *stmt);
41-
extern void AlterTypeOwner(List *names, Oid newOwnerId);
41+
extern void AlterTypeOwner(List *names, Oid newOwnerId, ObjectType objecttype);
4242
extern void AlterTypeOwnerInternal(Oid typeOid, Oid newOwnerId,
4343
bool hasDependEntry);
44-
extern void AlterTypeNamespace(List *names, const char *newschema);
44+
extern void AlterTypeNamespace(List *names, const char *newschema, ObjectType objecttype);
4545
extern Oid AlterTypeNamespace_oid(Oid typeOid, Oid nspOid);
4646
extern Oid AlterTypeNamespaceInternal(Oid typeOid, Oid nspOid,
4747
bool isImplicitArray,

0 commit comments

Comments
 (0)