Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd1b02e7

Browse files
committed
Use format_type_be() instead of TypeNameToString() for some more user-facing
error messages where the type existence is established.
1 parent1471e38 commitd1b02e7

File tree

5 files changed

+29
-29
lines changed

5 files changed

+29
-29
lines changed

‎src/backend/commands/comment.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Copyright (c) 1996-2008, PostgreSQL Global Development Group
88
*
99
* IDENTIFICATION
10-
* $PostgreSQL: pgsql/src/backend/commands/comment.c,v 1.103 2008/06/19 00:46:04 alvherre Exp $
10+
* $PostgreSQL: pgsql/src/backend/commands/comment.c,v 1.104 2008/10/21 10:38:51 petere Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -882,7 +882,7 @@ CommentType(List *typename, char *comment)
882882

883883
if (!pg_type_ownercheck(oid,GetUserId()))
884884
aclcheck_error(ACLCHECK_NOT_OWNER,ACL_KIND_TYPE,
885-
TypeNameToString(tname));
885+
format_type_be(oid));
886886

887887
/* Call CreateComments() to create/drop the comments */
888888
CreateComments(oid,TypeRelationId,0,comment);
@@ -1464,8 +1464,8 @@ CommentCast(List *qualname, List *arguments, char *comment)
14641464
ereport(ERROR,
14651465
(errcode(ERRCODE_UNDEFINED_OBJECT),
14661466
errmsg("cast from type %s to type %s does not exist",
1467-
TypeNameToString(sourcetype),
1468-
TypeNameToString(targettype))));
1467+
format_type_be(sourcetypeid),
1468+
format_type_be(targettypeid))));
14691469

14701470
/* Get the OID of the cast */
14711471
castOid=HeapTupleGetOid(tuple);
@@ -1476,8 +1476,8 @@ CommentCast(List *qualname, List *arguments, char *comment)
14761476
ereport(ERROR,
14771477
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
14781478
errmsg("must be owner of type %s or type %s",
1479-
TypeNameToString(sourcetype),
1480-
TypeNameToString(targettype))));
1479+
format_type_be(sourcetypeid),
1480+
format_type_be(targettypeid))));
14811481

14821482
ReleaseSysCache(tuple);
14831483

‎src/backend/commands/functioncmds.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
*
1212
* IDENTIFICATION
13-
* $PostgreSQL: pgsql/src/backend/commands/functioncmds.c,v 1.98 2008/07/18 03:32:52 tgl Exp $
13+
* $PostgreSQL: pgsql/src/backend/commands/functioncmds.c,v 1.99 2008/10/21 10:38:51 petere Exp $
1414
*
1515
* DESCRIPTION
1616
* These routines take the parse tree and pick out the
@@ -1412,8 +1412,8 @@ CreateCast(CreateCastStmt *stmt)
14121412
ereport(ERROR,
14131413
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
14141414
errmsg("must be owner of type %s or type %s",
1415-
TypeNameToString(stmt->sourcetype),
1416-
TypeNameToString(stmt->targettype))));
1415+
format_type_be(sourcetypeid),
1416+
format_type_be(targettypeid))));
14171417

14181418
if (stmt->func!=NULL)
14191419
{
@@ -1554,8 +1554,8 @@ CreateCast(CreateCastStmt *stmt)
15541554
ereport(ERROR,
15551555
(errcode(ERRCODE_DUPLICATE_OBJECT),
15561556
errmsg("cast from type %s to type %s already exists",
1557-
TypeNameToString(stmt->sourcetype),
1558-
TypeNameToString(stmt->targettype))));
1557+
format_type_be(sourcetypeid),
1558+
format_type_be(targettypeid))));
15591559

15601560
/* ready to go */
15611561
values[Anum_pg_cast_castsource-1]=ObjectIdGetDatum(sourcetypeid);
@@ -1629,13 +1629,13 @@ DropCast(DropCastStmt *stmt)
16291629
ereport(ERROR,
16301630
(errcode(ERRCODE_UNDEFINED_OBJECT),
16311631
errmsg("cast from type %s to type %s does not exist",
1632-
TypeNameToString(stmt->sourcetype),
1633-
TypeNameToString(stmt->targettype))));
1632+
format_type_be(sourcetypeid),
1633+
format_type_be(targettypeid))));
16341634
else
16351635
ereport(NOTICE,
16361636
(errmsg("cast from type %s to type %s does not exist, skipping",
1637-
TypeNameToString(stmt->sourcetype),
1638-
TypeNameToString(stmt->targettype))));
1637+
format_type_be(sourcetypeid),
1638+
format_type_be(targettypeid))));
16391639

16401640
return;
16411641
}
@@ -1646,8 +1646,8 @@ DropCast(DropCastStmt *stmt)
16461646
ereport(ERROR,
16471647
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
16481648
errmsg("must be owner of type %s or type %s",
1649-
TypeNameToString(stmt->sourcetype),
1650-
TypeNameToString(stmt->targettype))));
1649+
format_type_be(sourcetypeid),
1650+
format_type_be(targettypeid))));
16511651

16521652
/*
16531653
* Do the deletion

‎src/backend/commands/tablecmds.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.267 2008/10/07 11:15:41 heikki Exp $
11+
* $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.268 2008/10/21 10:38:51 petere Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -5520,8 +5520,8 @@ ATPrepAlterColumnType(List **wqueue,
55205520
if (transform==NULL)
55215521
ereport(ERROR,
55225522
(errcode(ERRCODE_DATATYPE_MISMATCH),
5523-
errmsg("column \"%s\" cannot be cast to type\"%s\"",
5524-
colName,TypeNameToString(typename))));
5523+
errmsg("column \"%s\" cannot be cast to type%s",
5524+
colName,format_type_be(targettype))));
55255525

55265526
/*
55275527
* Add a work queue item to make ATRewriteTable update the column
@@ -5619,8 +5619,8 @@ ATExecAlterColumnType(AlteredTableInfo *tab, Relation rel,
56195619
if (defaultexpr==NULL)
56205620
ereport(ERROR,
56215621
(errcode(ERRCODE_DATATYPE_MISMATCH),
5622-
errmsg("default for column \"%s\" cannot be cast to type\"%s\"",
5623-
colName,TypeNameToString(typename))));
5622+
errmsg("default for column \"%s\" cannot be cast to type%s",
5623+
colName,format_type_be(targettype))));
56245624
}
56255625
else
56265626
defaultexpr=NULL;

‎src/backend/commands/typecmds.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/commands/typecmds.c,v 1.124 2008/09/25 03:28:56 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/commands/typecmds.c,v 1.125 2008/10/21 10:38:51 petere Exp $
1212
*
1313
* DESCRIPTION
1414
* The "DefineFoo" routines take the parse tree and pick out the
@@ -581,7 +581,7 @@ RemoveTypes(DropStmt *drop)
581581
if (!pg_type_ownercheck(typeoid,GetUserId())&&
582582
!pg_namespace_ownercheck(typ->typnamespace,GetUserId()))
583583
aclcheck_error(ACLCHECK_NOT_OWNER,ACL_KIND_TYPE,
584-
TypeNameToString(typename));
584+
format_type_be(typeoid));
585585

586586
if (drop->removeType==OBJECT_DOMAIN)
587587
{
@@ -2082,7 +2082,7 @@ checkDomainOwner(HeapTuple tup, TypeName *typename)
20822082
/* Permission check: must own type */
20832083
if (!pg_type_ownercheck(HeapTupleGetOid(tup),GetUserId()))
20842084
aclcheck_error(ACLCHECK_NOT_OWNER,ACL_KIND_TYPE,
2085-
TypeNameToString(typename));
2085+
format_type_be(HeapTupleGetOid(tup)));
20862086
}
20872087

20882088
/*
@@ -2487,7 +2487,7 @@ AlterTypeOwner(List *names, Oid newOwnerId)
24872487
/* Otherwise, must be owner of the existing object */
24882488
if (!pg_type_ownercheck(HeapTupleGetOid(tup),GetUserId()))
24892489
aclcheck_error(ACLCHECK_NOT_OWNER,ACL_KIND_TYPE,
2490-
TypeNameToString(typename));
2490+
format_type_be(HeapTupleGetOid(tup)));
24912491

24922492
/* Must be able to become new owner */
24932493
check_is_member_of_role(GetUserId(),newOwnerId);

‎src/test/regress/expected/alter_table.out

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1301,7 +1301,7 @@ select f3,max(f1) from foo group by f3;
13011301

13021302
-- Simple tests for alter table column type
13031303
alter table foo alter f1 TYPE integer; -- fails
1304-
ERROR: column "f1" cannot be cast to type"pg_catalog.int4"
1304+
ERROR: column "f1" cannot be cast to typeinteger
13051305
alter table foo alter f1 TYPE varchar(10);
13061306
create table anothertab (atcol1 serial8, atcol2 boolean,
13071307
constraint anothertab_chk check (atcol1 <= 3));
@@ -1316,7 +1316,7 @@ select * from anothertab;
13161316
(2 rows)
13171317

13181318
alter table anothertab alter column atcol1 type boolean; -- fails
1319-
ERROR: column "atcol1" cannot be cast to type"pg_catalog.bool"
1319+
ERROR: column "atcol1" cannot be cast to typeboolean
13201320
alter table anothertab alter column atcol1 type integer;
13211321
select * from anothertab;
13221322
atcol1 | atcol2
@@ -1350,7 +1350,7 @@ select * from anothertab;
13501350

13511351
alter table anothertab alter column atcol1 type boolean
13521352
using case when atcol1 % 2 = 0 then true else false end; -- fails
1353-
ERROR: default for column "atcol1" cannot be cast to type"pg_catalog.bool"
1353+
ERROR: default for column "atcol1" cannot be cast to typeboolean
13541354
alter table anothertab alter column atcol1 drop default;
13551355
alter table anothertab alter column atcol1 type boolean
13561356
using case when atcol1 % 2 = 0 then true else false end; -- fails

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp