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

Commite78791e

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 parent9fc8661 commite78791e

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
@@ -525,6 +525,7 @@ checkRuleResultList(List *targetList, TupleDesc resultDesc, bool isSelect)
525525
foreach(tllist,targetList)
526526
{
527527
TargetEntry*tle= (TargetEntry*)lfirst(tllist);
528+
Oidtletypid;
528529
int32tletypmod;
529530
Form_pg_attributeattr;
530531
char*attname;
@@ -556,19 +557,32 @@ checkRuleResultList(List *targetList, TupleDesc resultDesc, bool isSelect)
556557
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
557558
errmsg("cannot convert relation containing dropped columns to view")));
558559

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

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

591614
if (i!=resultDesc->natts)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp