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

Commitd9d125d

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 parent0ff9718 commitd9d125d

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
@@ -537,6 +537,7 @@ checkRuleResultList(List *targetList, TupleDesc resultDesc, bool isSelect)
537537
foreach(tllist,targetList)
538538
{
539539
TargetEntry*tle= (TargetEntry*)lfirst(tllist);
540+
Oidtletypid;
540541
int32tletypmod;
541542
Form_pg_attributeattr;
542543
char*attname;
@@ -568,19 +569,32 @@ checkRuleResultList(List *targetList, TupleDesc resultDesc, bool isSelect)
568569
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
569570
errmsg("cannot convert relation containing dropped columns to view")));
570571

572+
/* Check name match if required; no need for two error texts here */
571573
if (isSelect&&strcmp(tle->resname,attname)!=0)
572574
ereport(ERROR,
573575
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
574-
errmsg("SELECT rule's target entry %d has different column name from \"%s\"",i,attname)));
575-
576-
if (attr->atttypid!=exprType((Node*)tle->expr))
576+
errmsg("SELECT rule's target entry %d has different column name from \"%s\"",
577+
i,attname),
578+
errdetail("SELECT target entry is named \"%s\".",
579+
tle->resname)));
580+
581+
/* Check type match. */
582+
tletypid=exprType((Node*)tle->expr);
583+
if (attr->atttypid!=tletypid)
577584
ereport(ERROR,
578585
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
579586
isSelect ?
580587
errmsg("SELECT rule's target entry %d has different type from column \"%s\"",
581588
i,attname) :
582589
errmsg("RETURNING list's entry %d has different type from column \"%s\"",
583-
i,attname)));
590+
i,attname),
591+
isSelect ?
592+
errdetail("SELECT target entry has type %s, but column has type %s.",
593+
format_type_be(tletypid),
594+
format_type_be(attr->atttypid)) :
595+
errdetail("RETURNING list entry has type %s, but column has type %s.",
596+
format_type_be(tletypid),
597+
format_type_be(attr->atttypid))));
584598

585599
/*
586600
* Allow typmods to be different only if one of them is -1, ie,
@@ -597,7 +611,16 @@ checkRuleResultList(List *targetList, TupleDesc resultDesc, bool isSelect)
597611
errmsg("SELECT rule's target entry %d has different size from column \"%s\"",
598612
i,attname) :
599613
errmsg("RETURNING list's entry %d has different size from column \"%s\"",
600-
i,attname)));
614+
i,attname),
615+
isSelect ?
616+
errdetail("SELECT target entry has type %s, but column has type %s.",
617+
format_type_with_typemod(tletypid,tletypmod),
618+
format_type_with_typemod(attr->atttypid,
619+
attr->atttypmod)) :
620+
errdetail("RETURNING list entry has type %s, but column has type %s.",
621+
format_type_with_typemod(tletypid,tletypmod),
622+
format_type_with_typemod(attr->atttypid,
623+
attr->atttypmod))));
601624
}
602625

603626
if (i!=resultDesc->natts)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp