From d13629ee08803e045e5e626aff98557130153336 Mon Sep 17 00:00:00 2001
From: Franck Verrot <franck@verrot.fr>
Date: Tue, 4 Oct 2016 22:29:19 -0700
Subject: [PATCH] Report column for which type coercion fails

This commit pushes a new `error_context_stack` callback that helps users
understanding which column type coercion fails during INSERTs:

    # create table foo(bar varchar(2), baz int4);
    CREATE TABLE

    # insert into foo values('ok', 1234);
    INSERT 0 1

    # insert into foo values('ko', 'abcd');
    ERROR:  invalid input syntax for integer: "abcd"
    LINE 1: insert into foo values('ko', 'abcd');
                                          ^
    CONTEXT:  coercion failed for column "baz" of type integer
---
 src/backend/parser/parse_target.c         | 30 +++++++++++++++++++++++++++++-
 src/test/regress/expected/abstime.out     |  3 +++
 src/test/regress/expected/box.out         |  2 ++
 src/test/regress/expected/circle.out      |  3 +++
 src/test/regress/expected/date.out        |  1 +
 src/test/regress/expected/float4.out      | 12 ++++++++++++
 src/test/regress/expected/float8.out      | 12 ++++++++++++
 src/test/regress/expected/inet.out        |  2 ++
 src/test/regress/expected/insert.out      |  2 ++
 src/test/regress/expected/int2.out        |  8 ++++++++
 src/test/regress/expected/int4.out        |  8 ++++++++
 src/test/regress/expected/int8.out        |  7 +++++++
 src/test/regress/expected/interval.out    |  2 ++
 src/test/regress/expected/line.out        |  6 ++++++
 src/test/regress/expected/lseg.out        |  4 ++++
 src/test/regress/expected/macaddr.out     |  2 ++
 src/test/regress/expected/numeric.out     |  8 ++++++++
 src/test/regress/expected/oid.out         | 10 ++++++++++
 src/test/regress/expected/path.out        |  2 ++
 src/test/regress/expected/pg_lsn.out      |  5 +++++
 src/test/regress/expected/point.out       |  3 +++
 src/test/regress/expected/polygon.out     |  5 +++++
 src/test/regress/expected/reltime.out     |  2 ++
 src/test/regress/expected/rowtypes.out    |  1 +
 src/test/regress/expected/time.out        |  1 +
 src/test/regress/expected/timestamp.out   |  7 +++++++
 src/test/regress/expected/timestamptz.out |  7 +++++++
 src/test/regress/expected/timetz.out      |  1 +
 src/test/regress/expected/tinterval.out   |  2 ++
 src/test/regress/expected/uuid.out        |  6 ++++++
 src/test/regress/expected/xml_1.out       |  3 +++
 31 files changed, 166 insertions(+), 1 deletion(-)

diff --git a/src/backend/parser/parse_target.c b/src/backend/parser/parse_target.c
index b7b82bf..31d000b 100644
--- a/src/backend/parser/parse_target.c
+++ b/src/backend/parser/parse_target.c
@@ -389,6 +389,23 @@ markTargetListOrigin(ParseState *pstate, TargetEntry *tle,
  * omits the column name list.  So we should usually prefer to use
  * exprLocation(expr) for errors that can happen in a default INSERT.
  */
+
+typedef struct TransformExprState
+{
+	const char *column_name;
+	Oid expected_type;
+} TransformExprState;
+
+static void
+TransformExprCallback(void *arg)
+{
+	TransformExprState *state = (TransformExprState *) arg;
+
+	errcontext("coercion failed for column \"%s\" of type %s",
+			state->column_name,
+			format_type_be(state->expected_type));
+}
+
 Expr *
 transformAssignedExpr(ParseState *pstate,
 					  Expr *expr,
@@ -404,7 +421,14 @@ transformAssignedExpr(ParseState *pstate,
 	int32		attrtypmod;
 	Oid			attrcollation;	/* collation of target column */
 	ParseExprKind sv_expr_kind;
-
+	ErrorContextCallback errcallback;
+	TransformExprState testate;
+
+	/* Set up callback to identify error line number. */
+	errcallback.callback = TransformExprCallback;
+	errcallback.arg = (void *) &testate;
+	errcallback.previous = error_context_stack;
+	error_context_stack = &errcallback;
 	/*
 	 * Save and restore identity of expression type we're parsing.  We must
 	 * set p_expr_kind here because we can parse subscripts without going
@@ -425,6 +449,9 @@ transformAssignedExpr(ParseState *pstate,
 	attrtypmod = rd->rd_att->attrs[attrno - 1]->atttypmod;
 	attrcollation = rd->rd_att->attrs[attrno - 1]->attcollation;
 
+	testate.column_name = colname;
+	testate.expected_type = attrtype;
+
 	/*
 	 * If the expression is a DEFAULT placeholder, insert the attribute's
 	 * type/typmod/collation into it so that exprType etc will report the
@@ -529,6 +556,7 @@ transformAssignedExpr(ParseState *pstate,
 					 parser_errposition(pstate, exprLocation(orig_expr))));
 	}
 
+	error_context_stack = errcallback.previous;
 	pstate->p_expr_kind = sv_expr_kind;
 
 	return expr;
diff --git a/src/test/regress/expected/abstime.out b/src/test/regress/expected/abstime.out
index ed48f64..2317b28 100644
--- a/src/test/regress/expected/abstime.out
+++ b/src/test/regress/expected/abstime.out
@@ -32,15 +32,18 @@ ERROR:  date/time field value out of range: "Feb 35, 1946 10:00:00"
 LINE 1: INSERT INTO ABSTIME_TBL (f1) VALUES ('Feb 35, 1946 10:00:00'...
                                              ^
 HINT:  Perhaps you need a different "datestyle" setting.
+CONTEXT:  coercion failed for column "f1" of type abstime
 INSERT INTO ABSTIME_TBL (f1) VALUES ('Feb 28, 1984 25:08:10');
 ERROR:  date/time field value out of range: "Feb 28, 1984 25:08:10"
 LINE 1: INSERT INTO ABSTIME_TBL (f1) VALUES ('Feb 28, 1984 25:08:10'...
                                              ^
+CONTEXT:  coercion failed for column "f1" of type abstime
 -- badly formatted abstimes:  these should result in invalid abstimes
 INSERT INTO ABSTIME_TBL (f1) VALUES ('bad date format');
 ERROR:  invalid input syntax for type abstime: "bad date format"
 LINE 1: INSERT INTO ABSTIME_TBL (f1) VALUES ('bad date format');
                                              ^
+CONTEXT:  coercion failed for column "f1" of type abstime
 INSERT INTO ABSTIME_TBL (f1) VALUES ('Jun 10, 1843');
 -- test abstime operators
 SELECT '' AS eight, * FROM ABSTIME_TBL;
diff --git a/src/test/regress/expected/box.out b/src/test/regress/expected/box.out
index 5f8b945..5566c84 100644
--- a/src/test/regress/expected/box.out
+++ b/src/test/regress/expected/box.out
@@ -27,10 +27,12 @@ INSERT INTO BOX_TBL (f1) VALUES ('(2.3, 4.5)');
 ERROR:  invalid input syntax for type box: "(2.3, 4.5)"
 LINE 1: INSERT INTO BOX_TBL (f1) VALUES ('(2.3, 4.5)');
                                          ^
+CONTEXT:  coercion failed for column "f1" of type box
 INSERT INTO BOX_TBL (f1) VALUES ('asdfasdf(ad');
 ERROR:  invalid input syntax for type box: "asdfasdf(ad"
 LINE 1: INSERT INTO BOX_TBL (f1) VALUES ('asdfasdf(ad');
                                          ^
+CONTEXT:  coercion failed for column "f1" of type box
 SELECT '' AS four, * FROM BOX_TBL;
  four |         f1          
 ------+---------------------
diff --git a/src/test/regress/expected/circle.out b/src/test/regress/expected/circle.out
index 9ba4a04..ece0eb8 100644
--- a/src/test/regress/expected/circle.out
+++ b/src/test/regress/expected/circle.out
@@ -13,14 +13,17 @@ INSERT INTO CIRCLE_TBL VALUES ('<(-100,0),-100>');
 ERROR:  invalid input syntax for type circle: "<(-100,0),-100>"
 LINE 1: INSERT INTO CIRCLE_TBL VALUES ('<(-100,0),-100>');
                                        ^
+CONTEXT:  coercion failed for column "f1" of type circle
 INSERT INTO CIRCLE_TBL VALUES ('1abc,3,5');
 ERROR:  invalid input syntax for type circle: "1abc,3,5"
 LINE 1: INSERT INTO CIRCLE_TBL VALUES ('1abc,3,5');
                                        ^
+CONTEXT:  coercion failed for column "f1" of type circle
 INSERT INTO CIRCLE_TBL VALUES ('(3,(1,2),3)');
 ERROR:  invalid input syntax for type circle: "(3,(1,2),3)"
 LINE 1: INSERT INTO CIRCLE_TBL VALUES ('(3,(1,2),3)');
                                        ^
+CONTEXT:  coercion failed for column "f1" of type circle
 SELECT * FROM CIRCLE_TBL;
        f1       
 ----------------
diff --git a/src/test/regress/expected/date.out b/src/test/regress/expected/date.out
index 418b146..856374a 100644
--- a/src/test/regress/expected/date.out
+++ b/src/test/regress/expected/date.out
@@ -13,6 +13,7 @@ INSERT INTO DATE_TBL VALUES ('1997-02-29');
 ERROR:  date/time field value out of range: "1997-02-29"
 LINE 1: INSERT INTO DATE_TBL VALUES ('1997-02-29');
                                      ^
+CONTEXT:  coercion failed for column "f1" of type date
 INSERT INTO DATE_TBL VALUES ('1997-03-01');
 INSERT INTO DATE_TBL VALUES ('1997-03-02');
 INSERT INTO DATE_TBL VALUES ('2000-04-01');
diff --git a/src/test/regress/expected/float4.out b/src/test/regress/expected/float4.out
index fd46a4a..c04176f 100644
--- a/src/test/regress/expected/float4.out
+++ b/src/test/regress/expected/float4.out
@@ -12,51 +12,63 @@ INSERT INTO FLOAT4_TBL(f1) VALUES ('10e70');
 ERROR:  value out of range: overflow
 LINE 1: INSERT INTO FLOAT4_TBL(f1) VALUES ('10e70');
                                            ^
+CONTEXT:  coercion failed for column "f1" of type real
 INSERT INTO FLOAT4_TBL(f1) VALUES ('-10e70');
 ERROR:  value out of range: overflow
 LINE 1: INSERT INTO FLOAT4_TBL(f1) VALUES ('-10e70');
                                            ^
+CONTEXT:  coercion failed for column "f1" of type real
 INSERT INTO FLOAT4_TBL(f1) VALUES ('10e-70');
 ERROR:  value out of range: underflow
 LINE 1: INSERT INTO FLOAT4_TBL(f1) VALUES ('10e-70');
                                            ^
+CONTEXT:  coercion failed for column "f1" of type real
 INSERT INTO FLOAT4_TBL(f1) VALUES ('-10e-70');
 ERROR:  value out of range: underflow
 LINE 1: INSERT INTO FLOAT4_TBL(f1) VALUES ('-10e-70');
                                            ^
+CONTEXT:  coercion failed for column "f1" of type real
 -- bad input
 INSERT INTO FLOAT4_TBL(f1) VALUES ('');
 ERROR:  invalid input syntax for type real: ""
 LINE 1: INSERT INTO FLOAT4_TBL(f1) VALUES ('');
                                            ^
+CONTEXT:  coercion failed for column "f1" of type real
 INSERT INTO FLOAT4_TBL(f1) VALUES ('       ');
 ERROR:  invalid input syntax for type real: "       "
 LINE 1: INSERT INTO FLOAT4_TBL(f1) VALUES ('       ');
                                            ^
+CONTEXT:  coercion failed for column "f1" of type real
 INSERT INTO FLOAT4_TBL(f1) VALUES ('xyz');
 ERROR:  invalid input syntax for type real: "xyz"
 LINE 1: INSERT INTO FLOAT4_TBL(f1) VALUES ('xyz');
                                            ^
+CONTEXT:  coercion failed for column "f1" of type real
 INSERT INTO FLOAT4_TBL(f1) VALUES ('5.0.0');
 ERROR:  invalid input syntax for type real: "5.0.0"
 LINE 1: INSERT INTO FLOAT4_TBL(f1) VALUES ('5.0.0');
                                            ^
+CONTEXT:  coercion failed for column "f1" of type real
 INSERT INTO FLOAT4_TBL(f1) VALUES ('5 . 0');
 ERROR:  invalid input syntax for type real: "5 . 0"
 LINE 1: INSERT INTO FLOAT4_TBL(f1) VALUES ('5 . 0');
                                            ^
+CONTEXT:  coercion failed for column "f1" of type real
 INSERT INTO FLOAT4_TBL(f1) VALUES ('5.   0');
 ERROR:  invalid input syntax for type real: "5.   0"
 LINE 1: INSERT INTO FLOAT4_TBL(f1) VALUES ('5.   0');
                                            ^
+CONTEXT:  coercion failed for column "f1" of type real
 INSERT INTO FLOAT4_TBL(f1) VALUES ('     - 3.0');
 ERROR:  invalid input syntax for type real: "     - 3.0"
 LINE 1: INSERT INTO FLOAT4_TBL(f1) VALUES ('     - 3.0');
                                            ^
+CONTEXT:  coercion failed for column "f1" of type real
 INSERT INTO FLOAT4_TBL(f1) VALUES ('123            5');
 ERROR:  invalid input syntax for type real: "123            5"
 LINE 1: INSERT INTO FLOAT4_TBL(f1) VALUES ('123            5');
                                            ^
+CONTEXT:  coercion failed for column "f1" of type real
 -- special inputs
 SELECT 'NaN'::float4;
  float4 
diff --git a/src/test/regress/expected/float8.out b/src/test/regress/expected/float8.out
index 20c985e..dc52103 100644
--- a/src/test/regress/expected/float8.out
+++ b/src/test/regress/expected/float8.out
@@ -29,34 +29,42 @@ INSERT INTO FLOAT8_TBL(f1) VALUES ('');
 ERROR:  invalid input syntax for type double precision: ""
 LINE 1: INSERT INTO FLOAT8_TBL(f1) VALUES ('');
                                            ^
+CONTEXT:  coercion failed for column "f1" of type double precision
 INSERT INTO FLOAT8_TBL(f1) VALUES ('     ');
 ERROR:  invalid input syntax for type double precision: "     "
 LINE 1: INSERT INTO FLOAT8_TBL(f1) VALUES ('     ');
                                            ^
+CONTEXT:  coercion failed for column "f1" of type double precision
 INSERT INTO FLOAT8_TBL(f1) VALUES ('xyz');
 ERROR:  invalid input syntax for type double precision: "xyz"
 LINE 1: INSERT INTO FLOAT8_TBL(f1) VALUES ('xyz');
                                            ^
+CONTEXT:  coercion failed for column "f1" of type double precision
 INSERT INTO FLOAT8_TBL(f1) VALUES ('5.0.0');
 ERROR:  invalid input syntax for type double precision: "5.0.0"
 LINE 1: INSERT INTO FLOAT8_TBL(f1) VALUES ('5.0.0');
                                            ^
+CONTEXT:  coercion failed for column "f1" of type double precision
 INSERT INTO FLOAT8_TBL(f1) VALUES ('5 . 0');
 ERROR:  invalid input syntax for type double precision: "5 . 0"
 LINE 1: INSERT INTO FLOAT8_TBL(f1) VALUES ('5 . 0');
                                            ^
+CONTEXT:  coercion failed for column "f1" of type double precision
 INSERT INTO FLOAT8_TBL(f1) VALUES ('5.   0');
 ERROR:  invalid input syntax for type double precision: "5.   0"
 LINE 1: INSERT INTO FLOAT8_TBL(f1) VALUES ('5.   0');
                                            ^
+CONTEXT:  coercion failed for column "f1" of type double precision
 INSERT INTO FLOAT8_TBL(f1) VALUES ('    - 3');
 ERROR:  invalid input syntax for type double precision: "    - 3"
 LINE 1: INSERT INTO FLOAT8_TBL(f1) VALUES ('    - 3');
                                            ^
+CONTEXT:  coercion failed for column "f1" of type double precision
 INSERT INTO FLOAT8_TBL(f1) VALUES ('123           5');
 ERROR:  invalid input syntax for type double precision: "123           5"
 LINE 1: INSERT INTO FLOAT8_TBL(f1) VALUES ('123           5');
                                            ^
+CONTEXT:  coercion failed for column "f1" of type double precision
 -- special inputs
 SELECT 'NaN'::float8;
  float8 
@@ -414,18 +422,22 @@ INSERT INTO FLOAT8_TBL(f1) VALUES ('10e400');
 ERROR:  "10e400" is out of range for type double precision
 LINE 1: INSERT INTO FLOAT8_TBL(f1) VALUES ('10e400');
                                            ^
+CONTEXT:  coercion failed for column "f1" of type double precision
 INSERT INTO FLOAT8_TBL(f1) VALUES ('-10e400');
 ERROR:  "-10e400" is out of range for type double precision
 LINE 1: INSERT INTO FLOAT8_TBL(f1) VALUES ('-10e400');
                                            ^
+CONTEXT:  coercion failed for column "f1" of type double precision
 INSERT INTO FLOAT8_TBL(f1) VALUES ('10e-400');
 ERROR:  "10e-400" is out of range for type double precision
 LINE 1: INSERT INTO FLOAT8_TBL(f1) VALUES ('10e-400');
                                            ^
+CONTEXT:  coercion failed for column "f1" of type double precision
 INSERT INTO FLOAT8_TBL(f1) VALUES ('-10e-400');
 ERROR:  "-10e-400" is out of range for type double precision
 LINE 1: INSERT INTO FLOAT8_TBL(f1) VALUES ('-10e-400');
                                            ^
+CONTEXT:  coercion failed for column "f1" of type double precision
 -- maintain external table consistency across platforms
 -- delete all values and reinsert well-behaved ones
 DELETE FROM FLOAT8_TBL;
diff --git a/src/test/regress/expected/inet.out b/src/test/regress/expected/inet.out
index be9427e..fc1fff7 100644
--- a/src/test/regress/expected/inet.out
+++ b/src/test/regress/expected/inet.out
@@ -28,10 +28,12 @@ ERROR:  invalid cidr value: "192.168.1.2/30"
 LINE 1: INSERT INTO INET_TBL (c, i) VALUES ('192.168.1.2/30', '192.1...
                                             ^
 DETAIL:  Value has bits set to right of mask.
+CONTEXT:  coercion failed for column "c" of type cidr
 INSERT INTO INET_TBL (c, i) VALUES ('1234::1234::1234', '::1.2.3.4');
 ERROR:  invalid input syntax for type cidr: "1234::1234::1234"
 LINE 1: INSERT INTO INET_TBL (c, i) VALUES ('1234::1234::1234', '::1...
                                             ^
+CONTEXT:  coercion failed for column "c" of type cidr
 -- check that CIDR rejects invalid input when converting from text:
 INSERT INTO INET_TBL (c, i) VALUES (cidr('192.168.1.2/30'), '192.168.1.226');
 ERROR:  invalid cidr value: "192.168.1.2/30"
diff --git a/src/test/regress/expected/insert.out b/src/test/regress/expected/insert.out
index 70107b5..9b599ae 100644
--- a/src/test/regress/expected/insert.out
+++ b/src/test/regress/expected/insert.out
@@ -96,6 +96,7 @@ insert into inserttest (f2[1], f2[2]) values (1,default);  -- not supported
 ERROR:  cannot set an array element to DEFAULT
 LINE 1: insert into inserttest (f2[1], f2[2]) values (1,default);
                                        ^
+CONTEXT:  coercion failed for column "f2" of type integer[]
 insert into inserttest (f3.if1, f3.if2) values (1,array['foo']);
 insert into inserttest (f3.if1, f3.if2) values (1,'{foo}'), (2,'{bar}');
 insert into inserttest (f3.if1, f3.if2) select 3, '{baz,quux}';
@@ -103,6 +104,7 @@ insert into inserttest (f3.if1, f3.if2) values (1,default);  -- not supported
 ERROR:  cannot set a subfield to DEFAULT
 LINE 1: insert into inserttest (f3.if1, f3.if2) values (1,default);
                                         ^
+CONTEXT:  coercion failed for column "f3" of type insert_test_type
 insert into inserttest (f3.if2[1], f3.if2[2]) values ('foo', 'bar');
 insert into inserttest (f3.if2[1], f3.if2[2]) values ('foo', 'bar'), ('baz', 'quux');
 insert into inserttest (f3.if2[1], f3.if2[2]) select 'bear', 'beer';
diff --git a/src/test/regress/expected/int2.out b/src/test/regress/expected/int2.out
index 3ea4ed9..c4ab9d8 100644
--- a/src/test/regress/expected/int2.out
+++ b/src/test/regress/expected/int2.out
@@ -9,6 +9,7 @@ INSERT INTO INT2_TBL(f1) VALUES ('34.5');
 ERROR:  invalid input syntax for integer: "34.5"
 LINE 1: INSERT INTO INT2_TBL(f1) VALUES ('34.5');
                                          ^
+CONTEXT:  coercion failed for column "f1" of type smallint
 -- largest and smallest values
 INSERT INTO INT2_TBL(f1) VALUES ('32767');
 INSERT INTO INT2_TBL(f1) VALUES ('-32767');
@@ -17,30 +18,37 @@ INSERT INTO INT2_TBL(f1) VALUES ('100000');
 ERROR:  value "100000" is out of range for type smallint
 LINE 1: INSERT INTO INT2_TBL(f1) VALUES ('100000');
                                          ^
+CONTEXT:  coercion failed for column "f1" of type smallint
 INSERT INTO INT2_TBL(f1) VALUES ('asdf');
 ERROR:  invalid input syntax for integer: "asdf"
 LINE 1: INSERT INTO INT2_TBL(f1) VALUES ('asdf');
                                          ^
+CONTEXT:  coercion failed for column "f1" of type smallint
 INSERT INTO INT2_TBL(f1) VALUES ('    ');
 ERROR:  invalid input syntax for integer: "    "
 LINE 1: INSERT INTO INT2_TBL(f1) VALUES ('    ');
                                          ^
+CONTEXT:  coercion failed for column "f1" of type smallint
 INSERT INTO INT2_TBL(f1) VALUES ('- 1234');
 ERROR:  invalid input syntax for integer: "- 1234"
 LINE 1: INSERT INTO INT2_TBL(f1) VALUES ('- 1234');
                                          ^
+CONTEXT:  coercion failed for column "f1" of type smallint
 INSERT INTO INT2_TBL(f1) VALUES ('4 444');
 ERROR:  invalid input syntax for integer: "4 444"
 LINE 1: INSERT INTO INT2_TBL(f1) VALUES ('4 444');
                                          ^
+CONTEXT:  coercion failed for column "f1" of type smallint
 INSERT INTO INT2_TBL(f1) VALUES ('123 dt');
 ERROR:  invalid input syntax for integer: "123 dt"
 LINE 1: INSERT INTO INT2_TBL(f1) VALUES ('123 dt');
                                          ^
+CONTEXT:  coercion failed for column "f1" of type smallint
 INSERT INTO INT2_TBL(f1) VALUES ('');
 ERROR:  invalid input syntax for integer: ""
 LINE 1: INSERT INTO INT2_TBL(f1) VALUES ('');
                                          ^
+CONTEXT:  coercion failed for column "f1" of type smallint
 SELECT '' AS five, * FROM INT2_TBL;
  five |   f1   
 ------+--------
diff --git a/src/test/regress/expected/int4.out b/src/test/regress/expected/int4.out
index 372fd4d..4bd9cc9 100644
--- a/src/test/regress/expected/int4.out
+++ b/src/test/regress/expected/int4.out
@@ -9,6 +9,7 @@ INSERT INTO INT4_TBL(f1) VALUES ('34.5');
 ERROR:  invalid input syntax for integer: "34.5"
 LINE 1: INSERT INTO INT4_TBL(f1) VALUES ('34.5');
                                          ^
+CONTEXT:  coercion failed for column "f1" of type integer
 -- largest and smallest values
 INSERT INTO INT4_TBL(f1) VALUES ('2147483647');
 INSERT INTO INT4_TBL(f1) VALUES ('-2147483647');
@@ -17,30 +18,37 @@ INSERT INTO INT4_TBL(f1) VALUES ('1000000000000');
 ERROR:  value "1000000000000" is out of range for type integer
 LINE 1: INSERT INTO INT4_TBL(f1) VALUES ('1000000000000');
                                          ^
+CONTEXT:  coercion failed for column "f1" of type integer
 INSERT INTO INT4_TBL(f1) VALUES ('asdf');
 ERROR:  invalid input syntax for integer: "asdf"
 LINE 1: INSERT INTO INT4_TBL(f1) VALUES ('asdf');
                                          ^
+CONTEXT:  coercion failed for column "f1" of type integer
 INSERT INTO INT4_TBL(f1) VALUES ('     ');
 ERROR:  invalid input syntax for integer: "     "
 LINE 1: INSERT INTO INT4_TBL(f1) VALUES ('     ');
                                          ^
+CONTEXT:  coercion failed for column "f1" of type integer
 INSERT INTO INT4_TBL(f1) VALUES ('   asdf   ');
 ERROR:  invalid input syntax for integer: "   asdf   "
 LINE 1: INSERT INTO INT4_TBL(f1) VALUES ('   asdf   ');
                                          ^
+CONTEXT:  coercion failed for column "f1" of type integer
 INSERT INTO INT4_TBL(f1) VALUES ('- 1234');
 ERROR:  invalid input syntax for integer: "- 1234"
 LINE 1: INSERT INTO INT4_TBL(f1) VALUES ('- 1234');
                                          ^
+CONTEXT:  coercion failed for column "f1" of type integer
 INSERT INTO INT4_TBL(f1) VALUES ('123       5');
 ERROR:  invalid input syntax for integer: "123       5"
 LINE 1: INSERT INTO INT4_TBL(f1) VALUES ('123       5');
                                          ^
+CONTEXT:  coercion failed for column "f1" of type integer
 INSERT INTO INT4_TBL(f1) VALUES ('');
 ERROR:  invalid input syntax for integer: ""
 LINE 1: INSERT INTO INT4_TBL(f1) VALUES ('');
                                          ^
+CONTEXT:  coercion failed for column "f1" of type integer
 SELECT '' AS five, * FROM INT4_TBL;
  five |     f1      
 ------+-------------
diff --git a/src/test/regress/expected/int8.out b/src/test/regress/expected/int8.out
index ed0bd34..3dfb38d 100644
--- a/src/test/regress/expected/int8.out
+++ b/src/test/regress/expected/int8.out
@@ -13,30 +13,37 @@ INSERT INTO INT8_TBL(q1) VALUES ('      ');
 ERROR:  invalid input syntax for integer: "      "
 LINE 1: INSERT INTO INT8_TBL(q1) VALUES ('      ');
                                          ^
+CONTEXT:  coercion failed for column "q1" of type bigint
 INSERT INTO INT8_TBL(q1) VALUES ('xxx');
 ERROR:  invalid input syntax for integer: "xxx"
 LINE 1: INSERT INTO INT8_TBL(q1) VALUES ('xxx');
                                          ^
+CONTEXT:  coercion failed for column "q1" of type bigint
 INSERT INTO INT8_TBL(q1) VALUES ('3908203590239580293850293850329485');
 ERROR:  value "3908203590239580293850293850329485" is out of range for type bigint
 LINE 1: INSERT INTO INT8_TBL(q1) VALUES ('39082035902395802938502938...
                                          ^
+CONTEXT:  coercion failed for column "q1" of type bigint
 INSERT INTO INT8_TBL(q1) VALUES ('-1204982019841029840928340329840934');
 ERROR:  value "-1204982019841029840928340329840934" is out of range for type bigint
 LINE 1: INSERT INTO INT8_TBL(q1) VALUES ('-1204982019841029840928340...
                                          ^
+CONTEXT:  coercion failed for column "q1" of type bigint
 INSERT INTO INT8_TBL(q1) VALUES ('- 123');
 ERROR:  invalid input syntax for integer: "- 123"
 LINE 1: INSERT INTO INT8_TBL(q1) VALUES ('- 123');
                                          ^
+CONTEXT:  coercion failed for column "q1" of type bigint
 INSERT INTO INT8_TBL(q1) VALUES ('  345     5');
 ERROR:  invalid input syntax for integer: "  345     5"
 LINE 1: INSERT INTO INT8_TBL(q1) VALUES ('  345     5');
                                          ^
+CONTEXT:  coercion failed for column "q1" of type bigint
 INSERT INTO INT8_TBL(q1) VALUES ('');
 ERROR:  invalid input syntax for integer: ""
 LINE 1: INSERT INTO INT8_TBL(q1) VALUES ('');
                                          ^
+CONTEXT:  coercion failed for column "q1" of type bigint
 SELECT * FROM INT8_TBL;
         q1        |        q2         
 ------------------+-------------------
diff --git a/src/test/regress/expected/interval.out b/src/test/regress/expected/interval.out
index c873a99..439272e 100644
--- a/src/test/regress/expected/interval.out
+++ b/src/test/regress/expected/interval.out
@@ -68,10 +68,12 @@ INSERT INTO INTERVAL_TBL (f1) VALUES ('badly formatted interval');
 ERROR:  invalid input syntax for type interval: "badly formatted interval"
 LINE 1: INSERT INTO INTERVAL_TBL (f1) VALUES ('badly formatted inter...
                                               ^
+CONTEXT:  coercion failed for column "f1" of type interval
 INSERT INTO INTERVAL_TBL (f1) VALUES ('@ 30 eons ago');
 ERROR:  invalid input syntax for type interval: "@ 30 eons ago"
 LINE 1: INSERT INTO INTERVAL_TBL (f1) VALUES ('@ 30 eons ago');
                                               ^
+CONTEXT:  coercion failed for column "f1" of type interval
 -- test interval operators
 SELECT '' AS ten, * FROM INTERVAL_TBL;
  ten |       f1        
diff --git a/src/test/regress/expected/line.out b/src/test/regress/expected/line.out
index f20abdc..85ae175 100644
--- a/src/test/regress/expected/line.out
+++ b/src/test/regress/expected/line.out
@@ -13,6 +13,7 @@ INSERT INTO LINE_TBL VALUES ('[(1,0),(1,0)]');
 ERROR:  invalid line specification: must be two distinct points
 LINE 1: INSERT INTO LINE_TBL VALUES ('[(1,0),(1,0)]');
                                      ^
+CONTEXT:  coercion failed for column "s" of type line
 -- horizontal
 INSERT INTO LINE_TBL VALUES ('[(1,3),(2,3)]');
 -- vertical
@@ -22,22 +23,27 @@ INSERT INTO LINE_TBL VALUES ('{0,0,1}');
 ERROR:  invalid line specification: A and B cannot both be zero
 LINE 1: INSERT INTO LINE_TBL VALUES ('{0,0,1}');
                                      ^
+CONTEXT:  coercion failed for column "s" of type line
 INSERT INTO LINE_TBL VALUES ('(3asdf,2 ,3,4r2)');
 ERROR:  invalid input syntax for type line: "(3asdf,2 ,3,4r2)"
 LINE 1: INSERT INTO LINE_TBL VALUES ('(3asdf,2 ,3,4r2)');
                                      ^
+CONTEXT:  coercion failed for column "s" of type line
 INSERT INTO LINE_TBL VALUES ('[1,2,3, 4');
 ERROR:  invalid input syntax for type line: "[1,2,3, 4"
 LINE 1: INSERT INTO LINE_TBL VALUES ('[1,2,3, 4');
                                      ^
+CONTEXT:  coercion failed for column "s" of type line
 INSERT INTO LINE_TBL VALUES ('[(,2),(3,4)]');
 ERROR:  invalid input syntax for type line: "[(,2),(3,4)]"
 LINE 1: INSERT INTO LINE_TBL VALUES ('[(,2),(3,4)]');
                                      ^
+CONTEXT:  coercion failed for column "s" of type line
 INSERT INTO LINE_TBL VALUES ('[(1,2),(3,4)');
 ERROR:  invalid input syntax for type line: "[(1,2),(3,4)"
 LINE 1: INSERT INTO LINE_TBL VALUES ('[(1,2),(3,4)');
                                      ^
+CONTEXT:  coercion failed for column "s" of type line
 select * from LINE_TBL;
                       s                      
 ---------------------------------------------
diff --git a/src/test/regress/expected/lseg.out b/src/test/regress/expected/lseg.out
index bba1f3e..58c79af 100644
--- a/src/test/regress/expected/lseg.out
+++ b/src/test/regress/expected/lseg.out
@@ -14,18 +14,22 @@ INSERT INTO LSEG_TBL VALUES ('(3asdf,2 ,3,4r2)');
 ERROR:  invalid input syntax for type lseg: "(3asdf,2 ,3,4r2)"
 LINE 1: INSERT INTO LSEG_TBL VALUES ('(3asdf,2 ,3,4r2)');
                                      ^
+CONTEXT:  coercion failed for column "s" of type lseg
 INSERT INTO LSEG_TBL VALUES ('[1,2,3, 4');
 ERROR:  invalid input syntax for type lseg: "[1,2,3, 4"
 LINE 1: INSERT INTO LSEG_TBL VALUES ('[1,2,3, 4');
                                      ^
+CONTEXT:  coercion failed for column "s" of type lseg
 INSERT INTO LSEG_TBL VALUES ('[(,2),(3,4)]');
 ERROR:  invalid input syntax for type lseg: "[(,2),(3,4)]"
 LINE 1: INSERT INTO LSEG_TBL VALUES ('[(,2),(3,4)]');
                                      ^
+CONTEXT:  coercion failed for column "s" of type lseg
 INSERT INTO LSEG_TBL VALUES ('[(1,2),(3,4)');
 ERROR:  invalid input syntax for type lseg: "[(1,2),(3,4)"
 LINE 1: INSERT INTO LSEG_TBL VALUES ('[(1,2),(3,4)');
                                      ^
+CONTEXT:  coercion failed for column "s" of type lseg
 select * from LSEG_TBL;
                s               
 -------------------------------
diff --git a/src/test/regress/expected/macaddr.out b/src/test/regress/expected/macaddr.out
index e84ff5f..bd30b5f 100644
--- a/src/test/regress/expected/macaddr.out
+++ b/src/test/regress/expected/macaddr.out
@@ -13,10 +13,12 @@ INSERT INTO macaddr_data VALUES (8, '0800:2b01:0203'); -- invalid
 ERROR:  invalid input syntax for type macaddr: "0800:2b01:0203"
 LINE 1: INSERT INTO macaddr_data VALUES (8, '0800:2b01:0203');
                                             ^
+CONTEXT:  coercion failed for column "b" of type macaddr
 INSERT INTO macaddr_data VALUES (9, 'not even close'); -- invalid
 ERROR:  invalid input syntax for type macaddr: "not even close"
 LINE 1: INSERT INTO macaddr_data VALUES (9, 'not even close');
                                             ^
+CONTEXT:  coercion failed for column "b" of type macaddr
 INSERT INTO macaddr_data VALUES (10, '08:00:2b:01:02:04');
 INSERT INTO macaddr_data VALUES (11, '08:00:2b:01:02:02');
 INSERT INTO macaddr_data VALUES (12, '08:00:2a:01:02:03');
diff --git a/src/test/regress/expected/numeric.out b/src/test/regress/expected/numeric.out
index ae0beb9..a1a03fe 100644
--- a/src/test/regress/expected/numeric.out
+++ b/src/test/regress/expected/numeric.out
@@ -1293,34 +1293,42 @@ INSERT INTO num_input_test(n1) VALUES ('     ');
 ERROR:  invalid input syntax for type numeric: "     "
 LINE 1: INSERT INTO num_input_test(n1) VALUES ('     ');
                                                ^
+CONTEXT:  coercion failed for column "n1" of type numeric
 INSERT INTO num_input_test(n1) VALUES ('   1234   %');
 ERROR:  invalid input syntax for type numeric: "   1234   %"
 LINE 1: INSERT INTO num_input_test(n1) VALUES ('   1234   %');
                                                ^
+CONTEXT:  coercion failed for column "n1" of type numeric
 INSERT INTO num_input_test(n1) VALUES ('xyz');
 ERROR:  invalid input syntax for type numeric: "xyz"
 LINE 1: INSERT INTO num_input_test(n1) VALUES ('xyz');
                                                ^
+CONTEXT:  coercion failed for column "n1" of type numeric
 INSERT INTO num_input_test(n1) VALUES ('- 1234');
 ERROR:  invalid input syntax for type numeric: "- 1234"
 LINE 1: INSERT INTO num_input_test(n1) VALUES ('- 1234');
                                                ^
+CONTEXT:  coercion failed for column "n1" of type numeric
 INSERT INTO num_input_test(n1) VALUES ('5 . 0');
 ERROR:  invalid input syntax for type numeric: "5 . 0"
 LINE 1: INSERT INTO num_input_test(n1) VALUES ('5 . 0');
                                                ^
+CONTEXT:  coercion failed for column "n1" of type numeric
 INSERT INTO num_input_test(n1) VALUES ('5. 0   ');
 ERROR:  invalid input syntax for type numeric: "5. 0   "
 LINE 1: INSERT INTO num_input_test(n1) VALUES ('5. 0   ');
                                                ^
+CONTEXT:  coercion failed for column "n1" of type numeric
 INSERT INTO num_input_test(n1) VALUES ('');
 ERROR:  invalid input syntax for type numeric: ""
 LINE 1: INSERT INTO num_input_test(n1) VALUES ('');
                                                ^
+CONTEXT:  coercion failed for column "n1" of type numeric
 INSERT INTO num_input_test(n1) VALUES (' N aN ');
 ERROR:  invalid input syntax for type numeric: " N aN "
 LINE 1: INSERT INTO num_input_test(n1) VALUES (' N aN ');
                                                ^
+CONTEXT:  coercion failed for column "n1" of type numeric
 SELECT * FROM num_input_test;
    n1    
 ---------
diff --git a/src/test/regress/expected/oid.out b/src/test/regress/expected/oid.out
index 1eab9cc..ce8f149 100644
--- a/src/test/regress/expected/oid.out
+++ b/src/test/regress/expected/oid.out
@@ -16,42 +16,52 @@ INSERT INTO OID_TBL(f1) VALUES ('');
 ERROR:  invalid input syntax for type oid: ""
 LINE 1: INSERT INTO OID_TBL(f1) VALUES ('');
                                         ^
+CONTEXT:  coercion failed for column "f1" of type oid
 INSERT INTO OID_TBL(f1) VALUES ('    ');
 ERROR:  invalid input syntax for type oid: "    "
 LINE 1: INSERT INTO OID_TBL(f1) VALUES ('    ');
                                         ^
+CONTEXT:  coercion failed for column "f1" of type oid
 INSERT INTO OID_TBL(f1) VALUES ('asdfasd');
 ERROR:  invalid input syntax for type oid: "asdfasd"
 LINE 1: INSERT INTO OID_TBL(f1) VALUES ('asdfasd');
                                         ^
+CONTEXT:  coercion failed for column "f1" of type oid
 INSERT INTO OID_TBL(f1) VALUES ('99asdfasd');
 ERROR:  invalid input syntax for type oid: "99asdfasd"
 LINE 1: INSERT INTO OID_TBL(f1) VALUES ('99asdfasd');
                                         ^
+CONTEXT:  coercion failed for column "f1" of type oid
 INSERT INTO OID_TBL(f1) VALUES ('5    d');
 ERROR:  invalid input syntax for type oid: "5    d"
 LINE 1: INSERT INTO OID_TBL(f1) VALUES ('5    d');
                                         ^
+CONTEXT:  coercion failed for column "f1" of type oid
 INSERT INTO OID_TBL(f1) VALUES ('    5d');
 ERROR:  invalid input syntax for type oid: "    5d"
 LINE 1: INSERT INTO OID_TBL(f1) VALUES ('    5d');
                                         ^
+CONTEXT:  coercion failed for column "f1" of type oid
 INSERT INTO OID_TBL(f1) VALUES ('5    5');
 ERROR:  invalid input syntax for type oid: "5    5"
 LINE 1: INSERT INTO OID_TBL(f1) VALUES ('5    5');
                                         ^
+CONTEXT:  coercion failed for column "f1" of type oid
 INSERT INTO OID_TBL(f1) VALUES (' - 500');
 ERROR:  invalid input syntax for type oid: " - 500"
 LINE 1: INSERT INTO OID_TBL(f1) VALUES (' - 500');
                                         ^
+CONTEXT:  coercion failed for column "f1" of type oid
 INSERT INTO OID_TBL(f1) VALUES ('32958209582039852935');
 ERROR:  value "32958209582039852935" is out of range for type oid
 LINE 1: INSERT INTO OID_TBL(f1) VALUES ('32958209582039852935');
                                         ^
+CONTEXT:  coercion failed for column "f1" of type oid
 INSERT INTO OID_TBL(f1) VALUES ('-23582358720398502385');
 ERROR:  value "-23582358720398502385" is out of range for type oid
 LINE 1: INSERT INTO OID_TBL(f1) VALUES ('-23582358720398502385');
                                         ^
+CONTEXT:  coercion failed for column "f1" of type oid
 SELECT '' AS six, * FROM OID_TBL;
  six |     f1     
 -----+------------
diff --git a/src/test/regress/expected/path.out b/src/test/regress/expected/path.out
index 08d6d61..53a40f9 100644
--- a/src/test/regress/expected/path.out
+++ b/src/test/regress/expected/path.out
@@ -16,10 +16,12 @@ INSERT INTO PATH_TBL VALUES ('[(,2),(3,4)]');
 ERROR:  invalid input syntax for type path: "[(,2),(3,4)]"
 LINE 1: INSERT INTO PATH_TBL VALUES ('[(,2),(3,4)]');
                                      ^
+CONTEXT:  coercion failed for column "f1" of type path
 INSERT INTO PATH_TBL VALUES ('[(1,2),(3,4)');
 ERROR:  invalid input syntax for type path: "[(1,2),(3,4)"
 LINE 1: INSERT INTO PATH_TBL VALUES ('[(1,2),(3,4)');
                                      ^
+CONTEXT:  coercion failed for column "f1" of type path
 SELECT f1 FROM PATH_TBL;
             f1             
 ---------------------------
diff --git a/src/test/regress/expected/pg_lsn.out b/src/test/regress/expected/pg_lsn.out
index 2854cfd..869929e 100644
--- a/src/test/regress/expected/pg_lsn.out
+++ b/src/test/regress/expected/pg_lsn.out
@@ -10,22 +10,27 @@ INSERT INTO PG_LSN_TBL VALUES ('G/0');
 ERROR:  invalid input syntax for type pg_lsn: "G/0"
 LINE 1: INSERT INTO PG_LSN_TBL VALUES ('G/0');
                                        ^
+CONTEXT:  coercion failed for column "f1" of type pg_lsn
 INSERT INTO PG_LSN_TBL VALUES ('-1/0');
 ERROR:  invalid input syntax for type pg_lsn: "-1/0"
 LINE 1: INSERT INTO PG_LSN_TBL VALUES ('-1/0');
                                        ^
+CONTEXT:  coercion failed for column "f1" of type pg_lsn
 INSERT INTO PG_LSN_TBL VALUES (' 0/12345678');
 ERROR:  invalid input syntax for type pg_lsn: " 0/12345678"
 LINE 1: INSERT INTO PG_LSN_TBL VALUES (' 0/12345678');
                                        ^
+CONTEXT:  coercion failed for column "f1" of type pg_lsn
 INSERT INTO PG_LSN_TBL VALUES ('ABCD/');
 ERROR:  invalid input syntax for type pg_lsn: "ABCD/"
 LINE 1: INSERT INTO PG_LSN_TBL VALUES ('ABCD/');
                                        ^
+CONTEXT:  coercion failed for column "f1" of type pg_lsn
 INSERT INTO PG_LSN_TBL VALUES ('/ABCD');
 ERROR:  invalid input syntax for type pg_lsn: "/ABCD"
 LINE 1: INSERT INTO PG_LSN_TBL VALUES ('/ABCD');
                                        ^
+CONTEXT:  coercion failed for column "f1" of type pg_lsn
 DROP TABLE PG_LSN_TBL;
 -- Operators
 SELECT '0/16AE7F8' = '0/16AE7F8'::pg_lsn;
diff --git a/src/test/regress/expected/point.out b/src/test/regress/expected/point.out
index bfc0962..2733b4c 100644
--- a/src/test/regress/expected/point.out
+++ b/src/test/regress/expected/point.out
@@ -12,15 +12,18 @@ INSERT INTO POINT_TBL(f1) VALUES ('asdfasdf');
 ERROR:  invalid input syntax for type point: "asdfasdf"
 LINE 1: INSERT INTO POINT_TBL(f1) VALUES ('asdfasdf');
                                           ^
+CONTEXT:  coercion failed for column "f1" of type point
 INSERT INTO POINT_TBL(f1) VALUES ('10.0,10.0');
 INSERT INTO POINT_TBL(f1) VALUES ('(10.0 10.0)');
 ERROR:  invalid input syntax for type point: "(10.0 10.0)"
 LINE 1: INSERT INTO POINT_TBL(f1) VALUES ('(10.0 10.0)');
                                           ^
+CONTEXT:  coercion failed for column "f1" of type point
 INSERT INTO POINT_TBL(f1) VALUES ('(10.0,10.0');
 ERROR:  invalid input syntax for type point: "(10.0,10.0"
 LINE 1: INSERT INTO POINT_TBL(f1) VALUES ('(10.0,10.0');
                                           ^
+CONTEXT:  coercion failed for column "f1" of type point
 SELECT '' AS six, * FROM POINT_TBL;
  six |     f1     
 -----+------------
diff --git a/src/test/regress/expected/polygon.out b/src/test/regress/expected/polygon.out
index 2361274..882d342 100644
--- a/src/test/regress/expected/polygon.out
+++ b/src/test/regress/expected/polygon.out
@@ -14,22 +14,27 @@ INSERT INTO POLYGON_TBL(f1) VALUES ('0.0');
 ERROR:  invalid input syntax for type polygon: "0.0"
 LINE 1: INSERT INTO POLYGON_TBL(f1) VALUES ('0.0');
                                             ^
+CONTEXT:  coercion failed for column "f1" of type polygon
 INSERT INTO POLYGON_TBL(f1) VALUES ('(0.0 0.0');
 ERROR:  invalid input syntax for type polygon: "(0.0 0.0"
 LINE 1: INSERT INTO POLYGON_TBL(f1) VALUES ('(0.0 0.0');
                                             ^
+CONTEXT:  coercion failed for column "f1" of type polygon
 INSERT INTO POLYGON_TBL(f1) VALUES ('(0,1,2)');
 ERROR:  invalid input syntax for type polygon: "(0,1,2)"
 LINE 1: INSERT INTO POLYGON_TBL(f1) VALUES ('(0,1,2)');
                                             ^
+CONTEXT:  coercion failed for column "f1" of type polygon
 INSERT INTO POLYGON_TBL(f1) VALUES ('(0,1,2,3');
 ERROR:  invalid input syntax for type polygon: "(0,1,2,3"
 LINE 1: INSERT INTO POLYGON_TBL(f1) VALUES ('(0,1,2,3');
                                             ^
+CONTEXT:  coercion failed for column "f1" of type polygon
 INSERT INTO POLYGON_TBL(f1) VALUES ('asdf');
 ERROR:  invalid input syntax for type polygon: "asdf"
 LINE 1: INSERT INTO POLYGON_TBL(f1) VALUES ('asdf');
                                             ^
+CONTEXT:  coercion failed for column "f1" of type polygon
 SELECT '' AS four, * FROM POLYGON_TBL;
  four |         f1          
 ------+---------------------
diff --git a/src/test/regress/expected/reltime.out b/src/test/regress/expected/reltime.out
index 14fdc6a..4a82bd4 100644
--- a/src/test/regress/expected/reltime.out
+++ b/src/test/regress/expected/reltime.out
@@ -13,10 +13,12 @@ INSERT INTO RELTIME_TBL (f1) VALUES ('badly formatted reltime');
 ERROR:  invalid input syntax for type reltime: "badly formatted reltime"
 LINE 1: INSERT INTO RELTIME_TBL (f1) VALUES ('badly formatted reltim...
                                              ^
+CONTEXT:  coercion failed for column "f1" of type reltime
 INSERT INTO RELTIME_TBL (f1) VALUES ('@ 30 eons ago');
 ERROR:  invalid input syntax for type reltime: "@ 30 eons ago"
 LINE 1: INSERT INTO RELTIME_TBL (f1) VALUES ('@ 30 eons ago');
                                              ^
+CONTEXT:  coercion failed for column "f1" of type reltime
 -- test reltime operators
 SELECT '' AS six, * FROM RELTIME_TBL;
  six |      f1       
diff --git a/src/test/regress/expected/rowtypes.out b/src/test/regress/expected/rowtypes.out
index 25b0828..227dde0 100644
--- a/src/test/regress/expected/rowtypes.out
+++ b/src/test/regress/expected/rowtypes.out
@@ -416,6 +416,7 @@ ERROR:  column "f1" is of type integer but expression is of type compos
 LINE 2: insert into compos values (v);  -- fail
                                    ^
 HINT:  You will need to rewrite or cast the expression.
+CONTEXT:  coercion failed for column "f1" of type integer
 create function fcompos1(v compos) returns void as $$
 insert into compos values (v.*);
 $$ language sql;
diff --git a/src/test/regress/expected/time.out b/src/test/regress/expected/time.out
index 8e0afe6..aecb238 100644
--- a/src/test/regress/expected/time.out
+++ b/src/test/regress/expected/time.out
@@ -18,6 +18,7 @@ INSERT INTO TIME_TBL VALUES ('15:36:39 America/New_York');
 ERROR:  invalid input syntax for type time: "15:36:39 America/New_York"
 LINE 1: INSERT INTO TIME_TBL VALUES ('15:36:39 America/New_York');
                                      ^
+CONTEXT:  coercion failed for column "f1" of type time without time zone
 SELECT f1 AS "Time" FROM TIME_TBL;
     Time     
 -------------
diff --git a/src/test/regress/expected/timestamp.out b/src/test/regress/expected/timestamp.out
index 4a2fabd..1778274 100644
--- a/src/test/regress/expected/timestamp.out
+++ b/src/test/regress/expected/timestamp.out
@@ -84,14 +84,17 @@ INSERT INTO TIMESTAMP_TBL VALUES ('invalid');
 ERROR:  date/time value "invalid" is no longer supported
 LINE 1: INSERT INTO TIMESTAMP_TBL VALUES ('invalid');
                                           ^
+CONTEXT:  coercion failed for column "d1" of type timestamp without time zone
 INSERT INTO TIMESTAMP_TBL VALUES ('undefined');
 ERROR:  date/time value "undefined" is no longer supported
 LINE 1: INSERT INTO TIMESTAMP_TBL VALUES ('undefined');
                                           ^
+CONTEXT:  coercion failed for column "d1" of type timestamp without time zone
 INSERT INTO TIMESTAMP_TBL VALUES ('current');
 ERROR:  date/time value "current" is no longer supported
 LINE 1: INSERT INTO TIMESTAMP_TBL VALUES ('current');
                                           ^
+CONTEXT:  coercion failed for column "d1" of type timestamp without time zone
 -- Postgres v6.0 standard output format
 INSERT INTO TIMESTAMP_TBL VALUES ('Mon Feb 10 17:32:01 1997 PST');
 -- Variations on Postgres v6.1 standard output format
@@ -135,6 +138,7 @@ INSERT INTO TIMESTAMP_TBL VALUES ('19970710 173201 America/Does_not_exist');
 ERROR:  time zone "america/does_not_exist" not recognized
 LINE 1: INSERT INTO TIMESTAMP_TBL VALUES ('19970710 173201 America/D...
                                           ^
+CONTEXT:  coercion failed for column "d1" of type timestamp without time zone
 -- Check date conversion and date arithmetic
 INSERT INTO TIMESTAMP_TBL VALUES ('1997-06-10 18:32:01 PDT');
 INSERT INTO TIMESTAMP_TBL VALUES ('Feb 10 17:32:01 1997');
@@ -164,6 +168,7 @@ INSERT INTO TIMESTAMP_TBL VALUES ('Feb 29 17:32:01 1997');
 ERROR:  date/time field value out of range: "Feb 29 17:32:01 1997"
 LINE 1: INSERT INTO TIMESTAMP_TBL VALUES ('Feb 29 17:32:01 1997');
                                           ^
+CONTEXT:  coercion failed for column "d1" of type timestamp without time zone
 INSERT INTO TIMESTAMP_TBL VALUES ('Mar 01 17:32:01 1997');
 INSERT INTO TIMESTAMP_TBL VALUES ('Dec 30 17:32:01 1997');
 INSERT INTO TIMESTAMP_TBL VALUES ('Dec 31 17:32:01 1997');
@@ -176,10 +181,12 @@ INSERT INTO TIMESTAMP_TBL VALUES ('Feb 16 17:32:01 -0097');
 ERROR:  time zone displacement out of range: "Feb 16 17:32:01 -0097"
 LINE 1: INSERT INTO TIMESTAMP_TBL VALUES ('Feb 16 17:32:01 -0097');
                                           ^
+CONTEXT:  coercion failed for column "d1" of type timestamp without time zone
 INSERT INTO TIMESTAMP_TBL VALUES ('Feb 16 17:32:01 5097 BC');
 ERROR:  timestamp out of range: "Feb 16 17:32:01 5097 BC"
 LINE 1: INSERT INTO TIMESTAMP_TBL VALUES ('Feb 16 17:32:01 5097 BC')...
                                           ^
+CONTEXT:  coercion failed for column "d1" of type timestamp without time zone
 SELECT '' AS "64", d1 FROM TIMESTAMP_TBL;
  64 |             d1              
 ----+-----------------------------
diff --git a/src/test/regress/expected/timestamptz.out b/src/test/regress/expected/timestamptz.out
index 9fa93a4..9a7760f 100644
--- a/src/test/regress/expected/timestamptz.out
+++ b/src/test/regress/expected/timestamptz.out
@@ -83,14 +83,17 @@ INSERT INTO TIMESTAMPTZ_TBL VALUES ('invalid');
 ERROR:  date/time value "invalid" is no longer supported
 LINE 1: INSERT INTO TIMESTAMPTZ_TBL VALUES ('invalid');
                                             ^
+CONTEXT:  coercion failed for column "d1" of type timestamp with time zone
 INSERT INTO TIMESTAMPTZ_TBL VALUES ('undefined');
 ERROR:  date/time value "undefined" is no longer supported
 LINE 1: INSERT INTO TIMESTAMPTZ_TBL VALUES ('undefined');
                                             ^
+CONTEXT:  coercion failed for column "d1" of type timestamp with time zone
 INSERT INTO TIMESTAMPTZ_TBL VALUES ('current');
 ERROR:  date/time value "current" is no longer supported
 LINE 1: INSERT INTO TIMESTAMPTZ_TBL VALUES ('current');
                                             ^
+CONTEXT:  coercion failed for column "d1" of type timestamp with time zone
 -- Postgres v6.0 standard output format
 INSERT INTO TIMESTAMPTZ_TBL VALUES ('Mon Feb 10 17:32:01 1997 PST');
 -- Variations on Postgres v6.1 standard output format
@@ -147,6 +150,7 @@ INSERT INTO TIMESTAMPTZ_TBL VALUES ('19970710 173201 America/Does_not_exist');
 ERROR:  time zone "america/does_not_exist" not recognized
 LINE 1: INSERT INTO TIMESTAMPTZ_TBL VALUES ('19970710 173201 America...
                                             ^
+CONTEXT:  coercion failed for column "d1" of type timestamp with time zone
 SELECT '19970710 173201' AT TIME ZONE 'America/Does_not_exist';
 ERROR:  time zone "America/Does_not_exist" not recognized
 -- Daylight saving time for timestamps beyond 32-bit time_t range.
@@ -203,6 +207,7 @@ INSERT INTO TIMESTAMPTZ_TBL VALUES ('Feb 29 17:32:01 1997');
 ERROR:  date/time field value out of range: "Feb 29 17:32:01 1997"
 LINE 1: INSERT INTO TIMESTAMPTZ_TBL VALUES ('Feb 29 17:32:01 1997');
                                             ^
+CONTEXT:  coercion failed for column "d1" of type timestamp with time zone
 INSERT INTO TIMESTAMPTZ_TBL VALUES ('Mar 01 17:32:01 1997');
 INSERT INTO TIMESTAMPTZ_TBL VALUES ('Dec 30 17:32:01 1997');
 INSERT INTO TIMESTAMPTZ_TBL VALUES ('Dec 31 17:32:01 1997');
@@ -215,10 +220,12 @@ INSERT INTO TIMESTAMPTZ_TBL VALUES ('Feb 16 17:32:01 -0097');
 ERROR:  time zone displacement out of range: "Feb 16 17:32:01 -0097"
 LINE 1: INSERT INTO TIMESTAMPTZ_TBL VALUES ('Feb 16 17:32:01 -0097')...
                                             ^
+CONTEXT:  coercion failed for column "d1" of type timestamp with time zone
 INSERT INTO TIMESTAMPTZ_TBL VALUES ('Feb 16 17:32:01 5097 BC');
 ERROR:  timestamp out of range: "Feb 16 17:32:01 5097 BC"
 LINE 1: INSERT INTO TIMESTAMPTZ_TBL VALUES ('Feb 16 17:32:01 5097 BC...
                                             ^
+CONTEXT:  coercion failed for column "d1" of type timestamp with time zone
 -- Alternative field order that we've historically supported (sort of)
 -- with regular and POSIXy timezone specs
 SELECT 'Wed Jul 11 10:51:14 America/New_York 2001'::timestamptz;
diff --git a/src/test/regress/expected/timetz.out b/src/test/regress/expected/timetz.out
index 4391131..9b6e72e 100644
--- a/src/test/regress/expected/timetz.out
+++ b/src/test/regress/expected/timetz.out
@@ -19,6 +19,7 @@ INSERT INTO TIMETZ_TBL VALUES ('15:36:39 America/New_York');
 ERROR:  invalid input syntax for type time with time zone: "15:36:39 America/New_York"
 LINE 1: INSERT INTO TIMETZ_TBL VALUES ('15:36:39 America/New_York');
                                        ^
+CONTEXT:  coercion failed for column "f1" of type time with time zone
 SELECT f1 AS "Time TZ" FROM TIMETZ_TBL;
     Time TZ     
 ----------------
diff --git a/src/test/regress/expected/tinterval.out b/src/test/regress/expected/tinterval.out
index a018972..e910715 100644
--- a/src/test/regress/expected/tinterval.out
+++ b/src/test/regress/expected/tinterval.out
@@ -20,11 +20,13 @@ INSERT INTO TINTERVAL_TBL (f1)
 ERROR:  invalid input syntax for type abstime: "bad time specifications"
 LINE 2:    VALUES ('["bad time specifications" ""]');
                    ^
+CONTEXT:  coercion failed for column "f1" of type tinterval
 INSERT INTO TINTERVAL_TBL (f1)
    VALUES ('["" "infinity"]');
 ERROR:  invalid input syntax for type abstime: ""
 LINE 2:    VALUES ('["" "infinity"]');
                    ^
+CONTEXT:  coercion failed for column "f1" of type tinterval
 -- test tinterval operators
 SELECT '' AS five, * FROM TINTERVAL_TBL;
  five |                               f1                                
diff --git a/src/test/regress/expected/uuid.out b/src/test/regress/expected/uuid.out
index 59cb1e0..300211c 100644
--- a/src/test/regress/expected/uuid.out
+++ b/src/test/regress/expected/uuid.out
@@ -16,29 +16,35 @@ INSERT INTO guid1(guid_field) VALUES('11111111-1111-1111-1111-111111111111F');
 ERROR:  invalid input syntax for uuid: "11111111-1111-1111-1111-111111111111F"
 LINE 1: INSERT INTO guid1(guid_field) VALUES('11111111-1111-1111-111...
                                              ^
+CONTEXT:  coercion failed for column "guid_field" of type uuid
 -- too short
 INSERT INTO guid1(guid_field) VALUES('{11111111-1111-1111-1111-11111111111}');
 ERROR:  invalid input syntax for uuid: "{11111111-1111-1111-1111-11111111111}"
 LINE 1: INSERT INTO guid1(guid_field) VALUES('{11111111-1111-1111-11...
                                              ^
+CONTEXT:  coercion failed for column "guid_field" of type uuid
 -- valid data but invalid format
 INSERT INTO guid1(guid_field) VALUES('111-11111-1111-1111-1111-111111111111');
 ERROR:  invalid input syntax for uuid: "111-11111-1111-1111-1111-111111111111"
 LINE 1: INSERT INTO guid1(guid_field) VALUES('111-11111-1111-1111-11...
                                              ^
+CONTEXT:  coercion failed for column "guid_field" of type uuid
 INSERT INTO guid1(guid_field) VALUES('{22222222-2222-2222-2222-222222222222 ');
 ERROR:  invalid input syntax for uuid: "{22222222-2222-2222-2222-222222222222 "
 LINE 1: INSERT INTO guid1(guid_field) VALUES('{22222222-2222-2222-22...
                                              ^
+CONTEXT:  coercion failed for column "guid_field" of type uuid
 -- invalid data
 INSERT INTO guid1(guid_field) VALUES('11111111-1111-1111-G111-111111111111');
 ERROR:  invalid input syntax for uuid: "11111111-1111-1111-G111-111111111111"
 LINE 1: INSERT INTO guid1(guid_field) VALUES('11111111-1111-1111-G11...
                                              ^
+CONTEXT:  coercion failed for column "guid_field" of type uuid
 INSERT INTO guid1(guid_field) VALUES('11+11111-1111-1111-1111-111111111111');
 ERROR:  invalid input syntax for uuid: "11+11111-1111-1111-1111-111111111111"
 LINE 1: INSERT INTO guid1(guid_field) VALUES('11+11111-1111-1111-111...
                                              ^
+CONTEXT:  coercion failed for column "guid_field" of type uuid
 --inserting three input formats
 INSERT INTO guid1(guid_field) VALUES('11111111-1111-1111-1111-111111111111');
 INSERT INTO guid1(guid_field) VALUES('{22222222-2222-2222-2222-222222222222}');
diff --git a/src/test/regress/expected/xml_1.out b/src/test/regress/expected/xml_1.out
index d702703..e24f108 100644
--- a/src/test/regress/expected/xml_1.out
+++ b/src/test/regress/expected/xml_1.out
@@ -8,18 +8,21 @@ LINE 1: INSERT INTO xmltest VALUES (1, '<value>one</value>');
                                        ^
 DETAIL:  This functionality requires the server to be built with libxml support.
 HINT:  You need to rebuild PostgreSQL using --with-libxml.
+CONTEXT:  coercion failed for column "data" of type xml
 INSERT INTO xmltest VALUES (2, '<value>two</value>');
 ERROR:  unsupported XML feature
 LINE 1: INSERT INTO xmltest VALUES (2, '<value>two</value>');
                                        ^
 DETAIL:  This functionality requires the server to be built with libxml support.
 HINT:  You need to rebuild PostgreSQL using --with-libxml.
+CONTEXT:  coercion failed for column "data" of type xml
 INSERT INTO xmltest VALUES (3, '<wrong');
 ERROR:  unsupported XML feature
 LINE 1: INSERT INTO xmltest VALUES (3, '<wrong');
                                        ^
 DETAIL:  This functionality requires the server to be built with libxml support.
 HINT:  You need to rebuild PostgreSQL using --with-libxml.
+CONTEXT:  coercion failed for column "data" of type xml
 SELECT * FROM xmltest;
  id | data 
 ----+------
-- 
2.7.3

