aboutsummaryrefslogtreecommitdiff
path: root/src/backend/parser/parse_target.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2008-10-07 01:47:55 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2008-10-07 01:47:55 +0000
commit078aaf796eda274cd6cd241331278d4f089a6d7e (patch)
tree4c6864ed540927fb088aae746661acce99975feb /src/backend/parser/parse_target.c
parenta6586c0dc1f6d278f9932c90595828bf3d37f7d3 (diff)
downloadpostgresql-078aaf796eda274cd6cd241331278d4f089a6d7e.tar.gz
postgresql-078aaf796eda274cd6cd241331278d4f089a6d7e.zip
Improve parser error location for cases where an INSERT or UPDATE command
supplies an expression that can't be coerced to the target column type. The code previously attempted to point at the target column name, which doesn't work at all in an INSERT with omitted column name list, and is also not remarkably helpful when the problem is buried somewhere in a long INSERT-multi-VALUES command. Make it point at the failed expression instead.
Diffstat (limited to 'src/backend/parser/parse_target.c')
-rw-r--r--src/backend/parser/parse_target.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/backend/parser/parse_target.c b/src/backend/parser/parse_target.c
index d83caab7e8c..c12201fff7d 100644
--- a/src/backend/parser/parse_target.c
+++ b/src/backend/parser/parse_target.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/parser/parse_target.c,v 1.167 2008/10/06 15:15:22 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/parser/parse_target.c,v 1.168 2008/10/07 01:47:55 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -343,6 +343,11 @@ markTargetListOrigin(ParseState *pstate, TargetEntry *tle,
* location error cursor position for the target column, or -1
*
* Returns the modified expression.
+ *
+ * Note: location points at the target column name (SET target or INSERT
+ * column name list entry), and must therefore be -1 in an INSERT that
+ * omits the column name list. So we should usually prefer to use
+ * exprLocation(expr) for errors that can happen in a default INSERT.
*/
Expr *
transformAssignedExpr(ParseState *pstate,
@@ -446,9 +451,11 @@ transformAssignedExpr(ParseState *pstate,
* For normal non-qualified target column, do type checking and
* coercion.
*/
+ Node *orig_expr = (Node *) expr;
+
expr = (Expr *)
coerce_to_target_type(pstate,
- (Node *) expr, type_id,
+ orig_expr, type_id,
attrtype, attrtypmod,
COERCION_ASSIGNMENT,
COERCE_IMPLICIT_CAST,
@@ -462,7 +469,7 @@ transformAssignedExpr(ParseState *pstate,
format_type_be(attrtype),
format_type_be(type_id)),
errhint("You will need to rewrite or cast the expression."),
- parser_errposition(pstate, location)));
+ parser_errposition(pstate, exprLocation(orig_expr))));
}
return expr;