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

Commitd0091e3

Browse files
committed
Add some errdetail to checkRuleResultList().
This function wasn't originally thought to be really user-facing,because converting a table to a view isn't something we expect peopleto do manually. So not all that much effort was spent on the errormessages; in particular, while the code will complain that you gotthe column types wrong it won't say exactly what they are. But sincewe repurposed the code to also check compatibility of rule RETURNINGlists, it's definitely user-facing. It now seems worthwhile to adderrdetail messages showing exactly what the conflict is when there'sa mismatch of column names or types. This is prompted by bug #10836from Matthias Raffelsieper, which might have been forestalled if theerror message had reported the wrong column type as being "record".Per Alvaro's advice, back-patch to branches before 9.4, but resistthe temptation to rephrase any existing strings there. Adding newstrings is not really a translation degradation; anyway having theinfo presented in English is better than not having it at all.
1 parentc6b3fb4 commitd0091e3

File tree

1 file changed

+28
-5
lines changed

1 file changed

+28
-5
lines changed

‎src/backend/rewrite/rewriteDefine.c

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,7 @@ checkRuleResultList(List *targetList, TupleDesc resultDesc, bool isSelect)
524524
foreach(tllist,targetList)
525525
{
526526
TargetEntry*tle= (TargetEntry*)lfirst(tllist);
527+
Oidtletypid;
527528
int32tletypmod;
528529
Form_pg_attributeattr;
529530
char*attname;
@@ -555,19 +556,32 @@ checkRuleResultList(List *targetList, TupleDesc resultDesc, bool isSelect)
555556
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
556557
errmsg("cannot convert relation containing dropped columns to view")));
557558

559+
/* Check name match if required; no need for two error texts here */
558560
if (isSelect&&strcmp(tle->resname,attname)!=0)
559561
ereport(ERROR,
560562
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
561-
errmsg("SELECT rule's target entry %d has different column name from \"%s\"",i,attname)));
562-
563-
if (attr->atttypid!=exprType((Node*)tle->expr))
563+
errmsg("SELECT rule's target entry %d has different column name from \"%s\"",
564+
i,attname),
565+
errdetail("SELECT target entry is named \"%s\".",
566+
tle->resname)));
567+
568+
/* Check type match. */
569+
tletypid=exprType((Node*)tle->expr);
570+
if (attr->atttypid!=tletypid)
564571
ereport(ERROR,
565572
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
566573
isSelect ?
567574
errmsg("SELECT rule's target entry %d has different type from column \"%s\"",
568575
i,attname) :
569576
errmsg("RETURNING list's entry %d has different type from column \"%s\"",
570-
i,attname)));
577+
i,attname),
578+
isSelect ?
579+
errdetail("SELECT target entry has type %s, but column has type %s.",
580+
format_type_be(tletypid),
581+
format_type_be(attr->atttypid)) :
582+
errdetail("RETURNING list entry has type %s, but column has type %s.",
583+
format_type_be(tletypid),
584+
format_type_be(attr->atttypid))));
571585

572586
/*
573587
* Allow typmods to be different only if one of them is -1, ie,
@@ -584,7 +598,16 @@ checkRuleResultList(List *targetList, TupleDesc resultDesc, bool isSelect)
584598
errmsg("SELECT rule's target entry %d has different size from column \"%s\"",
585599
i,attname) :
586600
errmsg("RETURNING list's entry %d has different size from column \"%s\"",
587-
i,attname)));
601+
i,attname),
602+
isSelect ?
603+
errdetail("SELECT target entry has type %s, but column has type %s.",
604+
format_type_with_typemod(tletypid,tletypmod),
605+
format_type_with_typemod(attr->atttypid,
606+
attr->atttypmod)) :
607+
errdetail("RETURNING list entry has type %s, but column has type %s.",
608+
format_type_with_typemod(tletypid,tletypmod),
609+
format_type_with_typemod(attr->atttypid,
610+
attr->atttypmod))));
588611
}
589612

590613
if (i!=resultDesc->natts)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp