aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/backend/rewrite/rewriteDefine.c33
1 files changed, 28 insertions, 5 deletions
diff --git a/src/backend/rewrite/rewriteDefine.c b/src/backend/rewrite/rewriteDefine.c
index 35698f37abc..3185b6b342c 100644
--- a/src/backend/rewrite/rewriteDefine.c
+++ b/src/backend/rewrite/rewriteDefine.c
@@ -636,6 +636,7 @@ checkRuleResultList(List *targetList, TupleDesc resultDesc, bool isSelect,
foreach(tllist, targetList)
{
TargetEntry *tle = (TargetEntry *) lfirst(tllist);
+ Oid tletypid;
int32 tletypmod;
Form_pg_attribute attr;
char *attname;
@@ -667,19 +668,32 @@ checkRuleResultList(List *targetList, TupleDesc resultDesc, bool isSelect,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot convert relation containing dropped columns to view")));
+ /* Check name match if required; no need for two error texts here */
if (requireColumnNameMatch && strcmp(tle->resname, attname) != 0)
ereport(ERROR,
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
- errmsg("SELECT rule's target entry %d has different column name from \"%s\"", i, attname)));
-
- if (attr->atttypid != exprType((Node *) tle->expr))
+ errmsg("SELECT rule's target entry %d has different column name from \"%s\"",
+ i, attname),
+ errdetail("SELECT target entry is named \"%s\".",
+ tle->resname)));
+
+ /* Check type match. */
+ tletypid = exprType((Node *) tle->expr);
+ if (attr->atttypid != tletypid)
ereport(ERROR,
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
isSelect ?
errmsg("SELECT rule's target entry %d has different type from column \"%s\"",
i, attname) :
errmsg("RETURNING list's entry %d has different type from column \"%s\"",
- i, attname)));
+ i, attname),
+ isSelect ?
+ errdetail("SELECT target entry has type %s, but column has type %s.",
+ format_type_be(tletypid),
+ format_type_be(attr->atttypid)) :
+ errdetail("RETURNING list entry has type %s, but column has type %s.",
+ format_type_be(tletypid),
+ format_type_be(attr->atttypid))));
/*
* Allow typmods to be different only if one of them is -1, ie,
@@ -696,7 +710,16 @@ checkRuleResultList(List *targetList, TupleDesc resultDesc, bool isSelect,
errmsg("SELECT rule's target entry %d has different size from column \"%s\"",
i, attname) :
errmsg("RETURNING list's entry %d has different size from column \"%s\"",
- i, attname)));
+ i, attname),
+ isSelect ?
+ errdetail("SELECT target entry has type %s, but column has type %s.",
+ format_type_with_typemod(tletypid, tletypmod),
+ format_type_with_typemod(attr->atttypid,
+ attr->atttypmod)) :
+ errdetail("RETURNING list entry has type %s, but column has type %s.",
+ format_type_with_typemod(tletypid, tletypmod),
+ format_type_with_typemod(attr->atttypid,
+ attr->atttypmod))));
}
if (i != resultDesc->natts)