Use format_type_be() instead of TypeNameToString() for some more user-facing
authorPeter Eisentraut <peter_e@gmx.net>
Tue, 21 Oct 2008 10:38:51 +0000 (10:38 +0000)
committerPeter Eisentraut <peter_e@gmx.net>
Tue, 21 Oct 2008 10:38:51 +0000 (10:38 +0000)
error messages where the type existence is established.

src/backend/commands/comment.c
src/backend/commands/functioncmds.c
src/backend/commands/tablecmds.c
src/backend/commands/typecmds.c
src/test/regress/expected/alter_table.out

index b1c0f0a8c59fd3ed61d823f423b3bd5eee37294f..67bed6c7ed7827a89ce9e86ea6d0450d4a57d559 100644 (file)
@@ -882,7 +882,7 @@ CommentType(List *typename, char *comment)
 
        if (!pg_type_ownercheck(oid, GetUserId()))
                aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_TYPE,
-                                          TypeNameToString(tname));
+                                          format_type_be(oid));
 
        /* Call CreateComments() to create/drop the comments */
        CreateComments(oid, TypeRelationId, 0, comment);
@@ -1464,8 +1464,8 @@ CommentCast(List *qualname, List *arguments, char *comment)
                ereport(ERROR,
                                (errcode(ERRCODE_UNDEFINED_OBJECT),
                                 errmsg("cast from type %s to type %s does not exist",
-                                               TypeNameToString(sourcetype),
-                                               TypeNameToString(targettype))));
+                                               format_type_be(sourcetypeid),
+                                               format_type_be(targettypeid))));
 
        /* Get the OID of the cast */
        castOid = HeapTupleGetOid(tuple);
@@ -1476,8 +1476,8 @@ CommentCast(List *qualname, List *arguments, char *comment)
                ereport(ERROR,
                                (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
                                 errmsg("must be owner of type %s or type %s",
-                                               TypeNameToString(sourcetype),
-                                               TypeNameToString(targettype))));
+                                               format_type_be(sourcetypeid),
+                                               format_type_be(targettypeid))));
 
        ReleaseSysCache(tuple);
 
index 6f5b501dc5f0b65738ac7be9e0ff4e32b472bd10..fe6d547cd20ae5ea5178553b2b44a9a8beded907 100644 (file)
@@ -1412,8 +1412,8 @@ CreateCast(CreateCastStmt *stmt)
                ereport(ERROR,
                                (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
                                 errmsg("must be owner of type %s or type %s",
-                                               TypeNameToString(stmt->sourcetype),
-                                               TypeNameToString(stmt->targettype))));
+                                               format_type_be(sourcetypeid),
+                                               format_type_be(targettypeid))));
 
        if (stmt->func != NULL)
        {
@@ -1554,8 +1554,8 @@ CreateCast(CreateCastStmt *stmt)
                ereport(ERROR,
                                (errcode(ERRCODE_DUPLICATE_OBJECT),
                                 errmsg("cast from type %s to type %s already exists",
-                                               TypeNameToString(stmt->sourcetype),
-                                               TypeNameToString(stmt->targettype))));
+                                               format_type_be(sourcetypeid),
+                                               format_type_be(targettypeid))));
 
        /* ready to go */
        values[Anum_pg_cast_castsource - 1] = ObjectIdGetDatum(sourcetypeid);
@@ -1629,13 +1629,13 @@ DropCast(DropCastStmt *stmt)
                        ereport(ERROR,
                                        (errcode(ERRCODE_UNDEFINED_OBJECT),
                                         errmsg("cast from type %s to type %s does not exist",
-                                                       TypeNameToString(stmt->sourcetype),
-                                                       TypeNameToString(stmt->targettype))));
+                                                       format_type_be(sourcetypeid),
+                                                       format_type_be(targettypeid))));
                else
                        ereport(NOTICE,
                         (errmsg("cast from type %s to type %s does not exist, skipping",
-                                        TypeNameToString(stmt->sourcetype),
-                                        TypeNameToString(stmt->targettype))));
+                                        format_type_be(sourcetypeid),
+                                        format_type_be(targettypeid))));
 
                return;
        }
@@ -1646,8 +1646,8 @@ DropCast(DropCastStmt *stmt)
                ereport(ERROR,
                                (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
                                 errmsg("must be owner of type %s or type %s",
-                                               TypeNameToString(stmt->sourcetype),
-                                               TypeNameToString(stmt->targettype))));
+                                               format_type_be(sourcetypeid),
+                                               format_type_be(targettypeid))));
 
        /*
         * Do the deletion
index b039227c3c257bc5279a694a66bd4f3f7e74ec09..ee1b5849f54ff86783ab061a520cf7339221161a 100644 (file)
@@ -5520,8 +5520,8 @@ ATPrepAlterColumnType(List **wqueue,
        if (transform == NULL)
                ereport(ERROR,
                                (errcode(ERRCODE_DATATYPE_MISMATCH),
-                                errmsg("column \"%s\" cannot be cast to type \"%s\"",
-                                               colName, TypeNameToString(typename))));
+                                errmsg("column \"%s\" cannot be cast to type %s",
+                                               colName, format_type_be(targettype))));
 
        /*
         * Add a work queue item to make ATRewriteTable update the column
@@ -5619,8 +5619,8 @@ ATExecAlterColumnType(AlteredTableInfo *tab, Relation rel,
                if (defaultexpr == NULL)
                        ereport(ERROR,
                                        (errcode(ERRCODE_DATATYPE_MISMATCH),
-                       errmsg("default for column \"%s\" cannot be cast to type \"%s\"",
-                                  colName, TypeNameToString(typename))));
+                       errmsg("default for column \"%s\" cannot be cast to type %s",
+                                  colName, format_type_be(targettype))));
        }
        else
                defaultexpr = NULL;
index a1c009d4a9706af23ddd3cc79c1f8bc1bc307482..bee300c79736c60a8bd1c1e4057347b0c4cf2eea 100644 (file)
@@ -581,7 +581,7 @@ RemoveTypes(DropStmt *drop)
                if (!pg_type_ownercheck(typeoid, GetUserId()) &&
                        !pg_namespace_ownercheck(typ->typnamespace, GetUserId()))
                        aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_TYPE,
-                                                  TypeNameToString(typename));
+                                                  format_type_be(typeoid));
 
                if (drop->removeType == OBJECT_DOMAIN)
                {
@@ -2082,7 +2082,7 @@ checkDomainOwner(HeapTuple tup, TypeName *typename)
        /* Permission check: must own type */
        if (!pg_type_ownercheck(HeapTupleGetOid(tup), GetUserId()))
                aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_TYPE,
-                                          TypeNameToString(typename));
+                                          format_type_be(HeapTupleGetOid(tup)));
 }
 
 /*
@@ -2487,7 +2487,7 @@ AlterTypeOwner(List *names, Oid newOwnerId)
                        /* Otherwise, must be owner of the existing object */
                        if (!pg_type_ownercheck(HeapTupleGetOid(tup), GetUserId()))
                                aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_TYPE,
-                                                          TypeNameToString(typename));
+                                                          format_type_be(HeapTupleGetOid(tup)));
 
                        /* Must be able to become new owner */
                        check_is_member_of_role(GetUserId(), newOwnerId);
index 15179540a2d9179c283c5cf0caebe2a8a2fabf7d..388e25e9dbad9dec8c293b2713c37e79ed87c0b5 100644 (file)
@@ -1301,7 +1301,7 @@ select f3,max(f1) from foo group by f3;
 
 -- Simple tests for alter table column type
 alter table foo alter f1 TYPE integer; -- fails
-ERROR:  column "f1" cannot be cast to type "pg_catalog.int4"
+ERROR:  column "f1" cannot be cast to type integer
 alter table foo alter f1 TYPE varchar(10);
 create table anothertab (atcol1 serial8, atcol2 boolean,
        constraint anothertab_chk check (atcol1 <= 3));
@@ -1316,7 +1316,7 @@ select * from anothertab;
 (2 rows)
 
 alter table anothertab alter column atcol1 type boolean; -- fails
-ERROR:  column "atcol1" cannot be cast to type "pg_catalog.bool"
+ERROR:  column "atcol1" cannot be cast to type boolean
 alter table anothertab alter column atcol1 type integer;
 select * from anothertab;
  atcol1 | atcol2 
@@ -1350,7 +1350,7 @@ select * from anothertab;
 
 alter table anothertab alter column atcol1 type boolean
         using case when atcol1 % 2 = 0 then true else false end; -- fails
-ERROR:  default for column "atcol1" cannot be cast to type "pg_catalog.bool"
+ERROR:  default for column "atcol1" cannot be cast to type boolean
 alter table anothertab alter column atcol1 drop default;
 alter table anothertab alter column atcol1 type boolean
         using case when atcol1 % 2 = 0 then true else false end; -- fails