diff --git a/src/backend/parser/analyze.c b/src/backend/parser/analyze.c
index 8e762f824c237a772d443e3cd039988d2bde844a..2a99d099d8e3d040513f9ebfd59dbe8c16dec38c 100644
--- a/src/backend/parser/analyze.c
+++ b/src/backend/parser/analyze.c
@@ -17,7 +17,7 @@
  * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- *	$PostgreSQL: pgsql/src/backend/parser/analyze.c,v 1.381 2008/10/06 15:15:22 tgl Exp $
+ *	$PostgreSQL: pgsql/src/backend/parser/analyze.c,v 1.382 2008/10/07 01:47:54 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -426,11 +426,15 @@ transformInsertStmt(ParseState *pstate, InsertStmt *stmt)
 				exprType((Node *) tle->expr) == UNKNOWNOID)
 				expr = tle->expr;
 			else
-				expr = (Expr *) makeVar(rtr->rtindex,
-										tle->resno,
-										exprType((Node *) tle->expr),
-										exprTypmod((Node *) tle->expr),
-										0);
+			{
+				Var	   *var = makeVar(rtr->rtindex,
+									  tle->resno,
+									  exprType((Node *) tle->expr),
+									  exprTypmod((Node *) tle->expr),
+									  0);
+				var->location = exprLocation((Node *) tle->expr);
+				expr = (Expr *) var;
+			}
 			exprList = lappend(exprList, expr);
 		}
 
diff --git a/src/backend/parser/parse_target.c b/src/backend/parser/parse_target.c
index d83caab7e8c706f7c0bf3c6a2999aeeef8928b44..c12201fff7d6876ccbf2581e3368df67d62afe2f 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;