Skip to content

Commit d0091e3

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 people to do manually. So not all that much effort was spent on the error messages; in particular, while the code will complain that you got the column types wrong it won't say exactly what they are. But since we repurposed the code to also check compatibility of rule RETURNING lists, it's definitely user-facing. It now seems worthwhile to add errdetail messages showing exactly what the conflict is when there's a mismatch of column names or types. This is prompted by bug #10836 from Matthias Raffelsieper, which might have been forestalled if the error message had reported the wrong column type as being "record". Per Alvaro's advice, back-patch to branches before 9.4, but resist the temptation to rephrase any existing strings there. Adding new strings is not really a translation degradation; anyway having the info presented in English is better than not having it at all.
1 parent c6b3fb4 commit d0091e3

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+
Oid tletypid;
527528
int32 tletypmod;
528529
Form_pg_attribute attr;
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy