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

Commit7980ab3

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".Back-patch to 9.4, but not into older branches where the set oftranslatable error strings is supposed to be stable.
1 parentd97e98e commit7980ab3

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
@@ -633,6 +633,7 @@ checkRuleResultList(List *targetList, TupleDesc resultDesc, bool isSelect,
633633
foreach(tllist,targetList)
634634
{
635635
TargetEntry*tle= (TargetEntry*)lfirst(tllist);
636+
Oidtletypid;
636637
int32tletypmod;
637638
Form_pg_attributeattr;
638639
char*attname;
@@ -664,19 +665,32 @@ checkRuleResultList(List *targetList, TupleDesc resultDesc, bool isSelect,
664665
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
665666
errmsg("cannot convert relation containing dropped columns to view")));
666667

668+
/* Check name match if required; no need for two error texts here */
667669
if (requireColumnNameMatch&&strcmp(tle->resname,attname)!=0)
668670
ereport(ERROR,
669671
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
670-
errmsg("SELECT rule's target entry %d has different column name from \"%s\"",i,attname)));
671-
672-
if (attr->atttypid!=exprType((Node*)tle->expr))
672+
errmsg("SELECT rule's target entry %d has different column name from column \"%s\"",
673+
i,attname),
674+
errdetail("SELECT target entry is named \"%s\".",
675+
tle->resname)));
676+
677+
/* Check type match. */
678+
tletypid=exprType((Node*)tle->expr);
679+
if (attr->atttypid!=tletypid)
673680
ereport(ERROR,
674681
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
675682
isSelect ?
676683
errmsg("SELECT rule's target entry %d has different type from column \"%s\"",
677684
i,attname) :
678685
errmsg("RETURNING list's entry %d has different type from column \"%s\"",
679-
i,attname)));
686+
i,attname),
687+
isSelect ?
688+
errdetail("SELECT target entry has type %s, but column has type %s.",
689+
format_type_be(tletypid),
690+
format_type_be(attr->atttypid)) :
691+
errdetail("RETURNING list entry has type %s, but column has type %s.",
692+
format_type_be(tletypid),
693+
format_type_be(attr->atttypid))));
680694

681695
/*
682696
* Allow typmods to be different only if one of them is -1, ie,
@@ -693,7 +707,16 @@ checkRuleResultList(List *targetList, TupleDesc resultDesc, bool isSelect,
693707
errmsg("SELECT rule's target entry %d has different size from column \"%s\"",
694708
i,attname) :
695709
errmsg("RETURNING list's entry %d has different size from column \"%s\"",
696-
i,attname)));
710+
i,attname),
711+
isSelect ?
712+
errdetail("SELECT target entry has type %s, but column has type %s.",
713+
format_type_with_typemod(tletypid,tletypmod),
714+
format_type_with_typemod(attr->atttypid,
715+
attr->atttypmod)) :
716+
errdetail("RETURNING list entry has type %s, but column has type %s.",
717+
format_type_with_typemod(tletypid,tletypmod),
718+
format_type_with_typemod(attr->atttypid,
719+
attr->atttypmod))));
697720
}
698721

699722
if (i!=resultDesc->natts)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp