]> granicus.if.org Git - postgresql/commitdiff
Disallow ALTER DOMAIN on non-domain type everywhere
authorPeter Eisentraut <peter_e@gmx.net>
Fri, 27 Jan 2012 19:20:34 +0000 (21:20 +0200)
committerPeter Eisentraut <peter_e@gmx.net>
Fri, 27 Jan 2012 19:20:34 +0000 (21:20 +0200)
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.

src/backend/commands/alter.c
src/backend/commands/typecmds.c
src/include/commands/typecmds.h

index 7c658c0348a78881cb40ba0aba43c1a37bd224d0..9175405af2af5f2a0dd4c7dcd0c95a1b416ed60f 100644 (file)
@@ -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:
index 03918486a15fba64d7c49d2da8574020d14af69c..c6bc6c8e8769a03d4c1641a0e24f2b6d71c2f050 100644 (file)
@@ -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);
 
index 3748bd56af12560508702a2ec01ebe3691c8c2c8..9de5330924e6a8b8d2fafe8560a3a4557c821617 100644 (file)
@@ -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,