Skip to content

Commit d9d125d

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 0ff9718 commit d9d125d

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+
Oid tletypid;
540541
int32 tletypmod;
541542
Form_pg_attribute attr;
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)
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