From 1b92850e7b8811a1e1114a18359d01d33089c0bf Mon Sep 17 00:00:00 2001
From: Nathan Bossart <nathandbossart@gmail.com>
Date: Thu, 23 Feb 2023 10:31:24 -0800
Subject: [PATCH v2 1/1] add details to pg_input_error_message

---
 contrib/cube/expected/cube.out                |  6 +-
 contrib/hstore/expected/hstore.out            | 12 +--
 contrib/intarray/expected/_int.out            | 10 +--
 contrib/isn/expected/isn.out                  | 10 +--
 contrib/ltree/expected/ltree.out              | 20 ++---
 contrib/seg/expected/seg.out                  | 16 ++--
 doc/src/sgml/func.sgml                        | 29 ++++---
 src/backend/utils/adt/misc.c                  | 38 +++++++--
 src/include/catalog/pg_proc.dat               | 10 ++-
 src/test/regress/expected/arrays.out          |  6 +-
 src/test/regress/expected/bit.out             | 30 +++----
 src/test/regress/expected/boolean.out         |  6 +-
 src/test/regress/expected/box.out             | 12 +--
 src/test/regress/expected/char_1.out          |  6 +-
 src/test/regress/expected/date.out            | 12 +--
 src/test/regress/expected/domain.out          | 24 +++---
 src/test/regress/expected/enum.out            | 12 +--
 src/test/regress/expected/float4.out          |  6 +-
 src/test/regress/expected/float8.out          |  6 +-
 src/test/regress/expected/geometry.out        | 12 +--
 src/test/regress/expected/inet.out            | 18 ++---
 src/test/regress/expected/int2.out            | 18 ++---
 src/test/regress/expected/int4.out            |  6 +-
 src/test/regress/expected/int8.out            |  6 +-
 src/test/regress/expected/interval.out        | 12 +--
 src/test/regress/expected/json.out            |  6 +-
 src/test/regress/expected/json_encoding.out   |  2 +-
 src/test/regress/expected/jsonb.out           | 12 +--
 src/test/regress/expected/jsonpath.out        | 14 ++--
 src/test/regress/expected/line.out            | 30 +++----
 src/test/regress/expected/lseg.out            |  6 +-
 src/test/regress/expected/macaddr.out         | 12 +--
 src/test/regress/expected/macaddr8.out        | 12 +--
 src/test/regress/expected/money.out           | 12 +--
 src/test/regress/expected/multirangetypes.out | 12 +--
 src/test/regress/expected/numeric.out         | 18 ++---
 src/test/regress/expected/oid.out             | 24 +++---
 src/test/regress/expected/path.out            | 12 +--
 src/test/regress/expected/pg_lsn.out          |  6 +-
 src/test/regress/expected/point.out           |  6 +-
 src/test/regress/expected/polygon.out         | 12 +--
 src/test/regress/expected/privileges.out      | 18 ++---
 src/test/regress/expected/rangetypes.out      | 30 +++----
 src/test/regress/expected/regproc.out         | 78 +++++++++----------
 src/test/regress/expected/rowtypes.out        | 12 +--
 src/test/regress/expected/strings.out         | 18 ++---
 src/test/regress/expected/tid.out             | 12 +--
 src/test/regress/expected/time.out            | 12 +--
 src/test/regress/expected/timestamp.out       | 12 +--
 src/test/regress/expected/timestamptz.out     | 12 +--
 src/test/regress/expected/timetz.out          | 12 +--
 src/test/regress/expected/tstypes.out         | 18 ++---
 src/test/regress/expected/uuid.out            |  6 +-
 src/test/regress/expected/varchar_1.out       |  6 +-
 src/test/regress/expected/xid.out             | 24 +++---
 src/test/regress/expected/xml.out             | 20 +++--
 56 files changed, 438 insertions(+), 391 deletions(-)

diff --git a/contrib/cube/expected/cube.out b/contrib/cube/expected/cube.out
index dc23e5ccc0..3bb42b063b 100644
--- a/contrib/cube/expected/cube.out
+++ b/contrib/cube/expected/cube.out
@@ -345,9 +345,9 @@ SELECT pg_input_is_valid('-1e-700', 'cube');
 (1 row)
 
 SELECT pg_input_error_message('-1e-700', 'cube');
-               pg_input_error_message                
------------------------------------------------------
- "-1e-700" is out of range for type double precision
+                      pg_input_error_message                       
+-------------------------------------------------------------------
+ ("""-1e-700"" is out of range for type double precision",,,22003)
 (1 row)
 
 --
diff --git a/contrib/hstore/expected/hstore.out b/contrib/hstore/expected/hstore.out
index d6faa91867..d58fee585e 100644
--- a/contrib/hstore/expected/hstore.out
+++ b/contrib/hstore/expected/hstore.out
@@ -266,15 +266,15 @@ select pg_input_is_valid('a=b', 'hstore');
 (1 row)
 
 select pg_input_error_message('a=b', 'hstore');
-             pg_input_error_message             
-------------------------------------------------
- syntax error in hstore, near "b" at position 2
+                    pg_input_error_message                    
+--------------------------------------------------------------
+ ("syntax error in hstore, near ""b"" at position 2",,,42601)
 (1 row)
 
 select pg_input_error_message(' =>b', 'hstore');
-             pg_input_error_message             
-------------------------------------------------
- syntax error in hstore, near "=" at position 1
+                    pg_input_error_message                    
+--------------------------------------------------------------
+ ("syntax error in hstore, near ""="" at position 1",,,42601)
 (1 row)
 
 -- -> operator
diff --git a/contrib/intarray/expected/_int.out b/contrib/intarray/expected/_int.out
index c953065a5c..73dfea605a 100644
--- a/contrib/intarray/expected/_int.out
+++ b/contrib/intarray/expected/_int.out
@@ -406,11 +406,11 @@ FROM (VALUES ('1&(2&(4&(5|6)))'),
              ('1#(2&(4&(5&6)))'),
              ('foo'))
       AS a(str);
-    query_int    | ok |    errmsg    
------------------+----+--------------
- 1&(2&(4&(5|6))) | t  | 
- 1#(2&(4&(5&6))) | f  | syntax error
- foo             | f  | syntax error
+    query_int    | ok |          errmsg          
+-----------------+----+--------------------------
+ 1&(2&(4&(5|6))) | t  | (,,,)
+ 1#(2&(4&(5&6))) | f  | ("syntax error",,,42601)
+ foo             | f  | ("syntax error",,,42601)
 (3 rows)
 
 CREATE TABLE test__int( a int[] );
diff --git a/contrib/isn/expected/isn.out b/contrib/isn/expected/isn.out
index 72171b2790..cbe4166fd0 100644
--- a/contrib/isn/expected/isn.out
+++ b/contrib/isn/expected/isn.out
@@ -268,11 +268,11 @@ FROM (VALUES ('9780123456786', 'UPC'),
              ('postgresql...','EAN13'),
              ('9771234567003','ISSN'))
       AS a(str,typ);
-      isn      | type  | ok |                         errmsg                         
----------------+-------+----+--------------------------------------------------------
- 9780123456786 | UPC   | f  | cannot cast ISBN to UPC for number: "9780123456786"
- postgresql... | EAN13 | f  | invalid input syntax for EAN13 number: "postgresql..."
- 9771234567003 | ISSN  | t  | 
+      isn      | type  | ok |                                errmsg                                
+---------------+-------+----+----------------------------------------------------------------------
+ 9780123456786 | UPC   | f  | ("cannot cast ISBN to UPC for number: ""9780123456786""",,,22P02)
+ postgresql... | EAN13 | f  | ("invalid input syntax for EAN13 number: ""postgresql...""",,,22P02)
+ 9771234567003 | ISSN  | t  | (,,,)
 (3 rows)
 
 --
diff --git a/contrib/ltree/expected/ltree.out b/contrib/ltree/expected/ltree.out
index d2a53b9f0c..cf925b2469 100644
--- a/contrib/ltree/expected/ltree.out
+++ b/contrib/ltree/expected/ltree.out
@@ -8111,15 +8111,15 @@ FROM (VALUES ('.2.3', 'ltree'),
              ('$tree & aWdf@*','ltxtquery'),
              ('!tree & aWdf@*','ltxtquery'))
       AS a(str,typ);
-     value      |   type    | ok |               errmsg               
-----------------+-----------+----+------------------------------------
- .2.3           | ltree     | f  | ltree syntax error at character 1
- 1.2.           | ltree     | f  | ltree syntax error
- 1.2.3          | ltree     | t  | 
- @.2.3          | lquery    | f  | lquery syntax error at character 1
-  2.3           | lquery    | f  | lquery syntax error at character 1
- 1.2.3          | lquery    | t  | 
- $tree & aWdf@* | ltxtquery | f  | operand syntax error
- !tree & aWdf@* | ltxtquery | t  | 
+     value      |   type    | ok |                          errmsg                          
+----------------+-----------+----+----------------------------------------------------------
+ .2.3           | ltree     | f  | ("ltree syntax error at character 1",,,42601)
+ 1.2.           | ltree     | f  | ("ltree syntax error","Unexpected end of input.",,42601)
+ 1.2.3          | ltree     | t  | (,,,)
+ @.2.3          | lquery    | f  | ("lquery syntax error at character 1",,,42601)
+  2.3           | lquery    | f  | ("lquery syntax error at character 1",,,42601)
+ 1.2.3          | lquery    | t  | (,,,)
+ $tree & aWdf@* | ltxtquery | f  | ("operand syntax error",,,42601)
+ !tree & aWdf@* | ltxtquery | t  | (,,,)
 (8 rows)
 
diff --git a/contrib/seg/expected/seg.out b/contrib/seg/expected/seg.out
index 7a06113ed8..4b09bd1d4f 100644
--- a/contrib/seg/expected/seg.out
+++ b/contrib/seg/expected/seg.out
@@ -1283,13 +1283,13 @@ FROM unnest(ARRAY['-1 .. 1'::text,
                   'ABC',
                   '1 e7',
                   '1e700']) str;
-   seg    | ok |                errmsg                 
-----------+----+---------------------------------------
- -1 .. 1  | t  | 
- 100(+-)1 | t  | 
-          | f  | bad seg representation
- ABC      | f  | bad seg representation
- 1 e7     | f  | bad seg representation
- 1e700    | f  | "1e700" is out of range for type real
+   seg    | ok |                              errmsg                               
+----------+----+-------------------------------------------------------------------
+ -1 .. 1  | t  | (,,,)
+ 100(+-)1 | t  | (,,,)
+          | f  | ("bad seg representation","syntax error at end of input",,42601)
+ ABC      | f  | ("bad seg representation","syntax error at or near ""A""",,42601)
+ 1 e7     | f  | ("bad seg representation","syntax error at or near ""e""",,42601)
+ 1e700    | f  | ("""1e700"" is out of range for type real",,,22003)
 (6 rows)
 
diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml
index 0cbdf63632..76dade49db 100644
--- a/doc/src/sgml/func.sgml
+++ b/doc/src/sgml/func.sgml
@@ -24781,13 +24781,17 @@ SELECT collation for ('foo' COLLATE "de_DE");
           <parameter>string</parameter> <type>text</type>,
           <parameter>type</parameter> <type>text</type>
         )
-        <returnvalue>text</returnvalue>
+        <returnvalue>record</returnvalue>
+        ( <parameter>message</parameter> <type>text</type>,
+        <parameter>detail</parameter> <type>text</type>,
+        <parameter>hint</parameter> <type>text</type>,
+        <parameter>sql_error_code</parameter> <type>text</type> )
        </para>
        <para>
         Tests whether the given <parameter>string</parameter> is valid
-        input for the specified data type; if not, return the error
-        message that would have been thrown.  If the input is valid, the
-        result is NULL.  The inputs are the same as
+        input for the specified data type; if not, return the details of
+        the error would have been thrown.  If the input is valid, the
+        results are NULL.  The inputs are the same as
         for <function>pg_input_is_valid</function>.
        </para>
        <para>
@@ -24798,12 +24802,17 @@ SELECT collation for ('foo' COLLATE "de_DE");
         directly.
         </para>
         <para>
-         <literal>pg_input_error_message('42000000000', 'integer')</literal>
-         <returnvalue>value "42000000000" is out of range for type integer</returnvalue>
-        </para>
-        <para>
-         <literal>pg_input_error_message('1234.567', 'numeric(7,4)')</literal>
-         <returnvalue>numeric field overflow</returnvalue>
+<programlisting>
+SELECT * FROM pg_input_error_message('42000000000', 'integer');
+                       message                        | detail | hint | sql_error_code
+------------------------------------------------------+--------+------+----------------
+ value "42000000000" is out of range for type integer |        |      | 22003
+
+SELECT * FROM pg_input_error_message('1234.567', 'numeric(7,4)');
+        message         |                                      detail                                       | hint | sql_error_code
+------------------------+-----------------------------------------------------------------------------------+------+----------------
+ numeric field overflow | A field with precision 7, scale 4 must round to an absolute value less than 10^3. |      | 22003
+</programlisting>
        </para></entry>
       </row>
      </tbody>
diff --git a/src/backend/utils/adt/misc.c b/src/backend/utils/adt/misc.c
index f95256efd3..a4f4b7fb90 100644
--- a/src/backend/utils/adt/misc.c
+++ b/src/backend/utils/adt/misc.c
@@ -662,7 +662,8 @@ pg_input_is_valid(PG_FUNCTION_ARGS)
 /*
  * pg_input_error_message - test whether string is valid input for datatype.
  *
- * Returns NULL if OK, else the primary message string from the error.
+ * Returns NULL if OK, else the primary message, detail message, hint message,
+ * and sql error code from the error.
  *
  * This will only work usefully if the datatype's input function has been
  * updated to return "soft" errors via errsave/ereturn.
@@ -673,19 +674,44 @@ pg_input_error_message(PG_FUNCTION_ARGS)
 	text	   *txt = PG_GETARG_TEXT_PP(0);
 	text	   *typname = PG_GETARG_TEXT_PP(1);
 	ErrorSaveContext escontext = {T_ErrorSaveContext};
+	TupleDesc   tupdesc;
+	Datum       values[4];
+	bool        isnull[4];
+
+	if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
+		elog(ERROR, "return type must be a row type");
 
 	/* Enable details_wanted */
 	escontext.details_wanted = true;
 
 	if (pg_input_is_valid_common(fcinfo, txt, typname,
 								 &escontext))
-		PG_RETURN_NULL();
+		memset(isnull, true, sizeof(isnull));
+	else
+	{
+		Assert(escontext.error_occurred);
+		Assert(escontext.error_data != NULL);
+		Assert(escontext.error_data->message != NULL);
+
+		memset(isnull, false, sizeof(isnull));
+
+		values[0] = CStringGetTextDatum(escontext.error_data->message);
 
-	Assert(escontext.error_occurred);
-	Assert(escontext.error_data != NULL);
-	Assert(escontext.error_data->message != NULL);
+		if (escontext.error_data->detail != NULL)
+			values[1] = CStringGetTextDatum(escontext.error_data->detail);
+		else
+			isnull[1] = true;
+
+		if (escontext.error_data->hint != NULL)
+			values[2] = CStringGetTextDatum(escontext.error_data->hint);
+		else
+			isnull[2] = true;
+
+		values[3] = CStringGetTextDatum(
+			unpack_sql_state(escontext.error_data->sqlerrcode));
+	}
 
-	PG_RETURN_TEXT_P(cstring_to_text(escontext.error_data->message));
+	return HeapTupleGetDatum(heap_form_tuple(tupdesc, values, isnull));
 }
 
 /* Common subroutine for the above */
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index e2a7642a2b..ecb5df2e53 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -7118,9 +7118,13 @@
   proname => 'pg_input_is_valid', provolatile => 's', prorettype => 'bool',
   proargtypes => 'text text', prosrc => 'pg_input_is_valid' },
 { oid => '8051',
-  descr => 'get error message if string is not valid input for data type',
-  proname => 'pg_input_error_message', provolatile => 's', prorettype => 'text',
-  proargtypes => 'text text', prosrc => 'pg_input_error_message' },
+  descr => 'get error details if string is not valid input for data type',
+  proname => 'pg_input_error_message', provolatile => 's', prorettype => 'record',
+  proargtypes => 'text text',
+  proallargtypes => '{text,text,text,text,text,text}',
+  proargmodes => '{i,i,o,o,o,o}',
+  proargnames => '{value,type_name,message,detail,hint,sql_error_code}',
+  prosrc => 'pg_input_error_message' },
 
 { oid => '1268',
   descr => 'parse qualified identifier to array of identifiers',
diff --git a/src/test/regress/expected/arrays.out b/src/test/regress/expected/arrays.out
index a2f9d7ed16..0e6a50dbca 100644
--- a/src/test/regress/expected/arrays.out
+++ b/src/test/regress/expected/arrays.out
@@ -202,9 +202,9 @@ SELECT pg_input_is_valid('{1,zed}', 'integer[]');
 (1 row)
 
 SELECT pg_input_error_message('{1,zed}', 'integer[]');
-            pg_input_error_message            
-----------------------------------------------
- invalid input syntax for type integer: "zed"
+                   pg_input_error_message                   
+------------------------------------------------------------
+ ("invalid input syntax for type integer: ""zed""",,,22P02)
 (1 row)
 
 -- test mixed slice/scalar subscripting
diff --git a/src/test/regress/expected/bit.out b/src/test/regress/expected/bit.out
index 209044713c..1b88327cb6 100644
--- a/src/test/regress/expected/bit.out
+++ b/src/test/regress/expected/bit.out
@@ -754,9 +754,9 @@ SELECT pg_input_is_valid('01010001', 'bit(10)');
 (1 row)
 
 SELECT pg_input_error_message('01010001', 'bit(10)');
-             pg_input_error_message              
--------------------------------------------------
- bit string length 8 does not match type bit(10)
+                   pg_input_error_message                    
+-------------------------------------------------------------
+ ("bit string length 8 does not match type bit(10)",,,22026)
 (1 row)
 
 SELECT pg_input_is_valid('01010Z01', 'bit(8)');
@@ -766,9 +766,9 @@ SELECT pg_input_is_valid('01010Z01', 'bit(8)');
 (1 row)
 
 SELECT pg_input_error_message('01010Z01', 'bit(8)');
-     pg_input_error_message      
----------------------------------
- "Z" is not a valid binary digit
+            pg_input_error_message             
+-----------------------------------------------
+ ("""Z"" is not a valid binary digit",,,22P02)
 (1 row)
 
 SELECT pg_input_is_valid('x01010Z01', 'bit(32)');
@@ -778,9 +778,9 @@ SELECT pg_input_is_valid('x01010Z01', 'bit(32)');
 (1 row)
 
 SELECT pg_input_error_message('x01010Z01', 'bit(32)');
-        pg_input_error_message        
---------------------------------------
- "Z" is not a valid hexadecimal digit
+               pg_input_error_message               
+----------------------------------------------------
+ ("""Z"" is not a valid hexadecimal digit",,,22P02)
 (1 row)
 
 SELECT pg_input_is_valid('01010Z01', 'varbit');
@@ -790,9 +790,9 @@ SELECT pg_input_is_valid('01010Z01', 'varbit');
 (1 row)
 
 SELECT pg_input_error_message('01010Z01', 'varbit');
-     pg_input_error_message      
----------------------------------
- "Z" is not a valid binary digit
+            pg_input_error_message             
+-----------------------------------------------
+ ("""Z"" is not a valid binary digit",,,22P02)
 (1 row)
 
 SELECT pg_input_is_valid('x01010Z01', 'varbit');
@@ -802,8 +802,8 @@ SELECT pg_input_is_valid('x01010Z01', 'varbit');
 (1 row)
 
 SELECT pg_input_error_message('x01010Z01', 'varbit');
-        pg_input_error_message        
---------------------------------------
- "Z" is not a valid hexadecimal digit
+               pg_input_error_message               
+----------------------------------------------------
+ ("""Z"" is not a valid hexadecimal digit",,,22P02)
 (1 row)
 
diff --git a/src/test/regress/expected/boolean.out b/src/test/regress/expected/boolean.out
index 977124b20b..331a8d2890 100644
--- a/src/test/regress/expected/boolean.out
+++ b/src/test/regress/expected/boolean.out
@@ -156,9 +156,9 @@ SELECT pg_input_is_valid('asdf', 'bool');
 (1 row)
 
 SELECT pg_input_error_message('junk', 'bool');
-            pg_input_error_message             
------------------------------------------------
- invalid input syntax for type boolean: "junk"
+                   pg_input_error_message                    
+-------------------------------------------------------------
+ ("invalid input syntax for type boolean: ""junk""",,,22P02)
 (1 row)
 
 -- and, or, not in qualifications
diff --git a/src/test/regress/expected/box.out b/src/test/regress/expected/box.out
index 0d70194def..7e7cbfee9c 100644
--- a/src/test/regress/expected/box.out
+++ b/src/test/regress/expected/box.out
@@ -647,9 +647,9 @@ SELECT pg_input_is_valid('200', 'box');
 (1 row)
 
 SELECT pg_input_error_message('200', 'box');
-          pg_input_error_message          
-------------------------------------------
- invalid input syntax for type box: "200"
+                 pg_input_error_message                 
+--------------------------------------------------------
+ ("invalid input syntax for type box: ""200""",,,22P02)
 (1 row)
 
 SELECT pg_input_is_valid('((200,300),(500, xyz))', 'box');
@@ -659,8 +659,8 @@ SELECT pg_input_is_valid('((200,300),(500, xyz))', 'box');
 (1 row)
 
 SELECT pg_input_error_message('((200,300),(500, xyz))', 'box');
-                   pg_input_error_message                    
--------------------------------------------------------------
- invalid input syntax for type box: "((200,300),(500, xyz))"
+                          pg_input_error_message                           
+---------------------------------------------------------------------------
+ ("invalid input syntax for type box: ""((200,300),(500, xyz))""",,,22P02)
 (1 row)
 
diff --git a/src/test/regress/expected/char_1.out b/src/test/regress/expected/char_1.out
index 3dcb0daa0d..32e4b28f6c 100644
--- a/src/test/regress/expected/char_1.out
+++ b/src/test/regress/expected/char_1.out
@@ -133,9 +133,9 @@ SELECT pg_input_is_valid('abcde', 'char(4)');
 (1 row)
 
 SELECT pg_input_error_message('abcde', 'char(4)');
-        pg_input_error_message        
---------------------------------------
- value too long for type character(4)
+              pg_input_error_message              
+--------------------------------------------------
+ ("value too long for type character(4)",,,22001)
 (1 row)
 
 --
diff --git a/src/test/regress/expected/date.out b/src/test/regress/expected/date.out
index c0dec448e1..d3fca737eb 100644
--- a/src/test/regress/expected/date.out
+++ b/src/test/regress/expected/date.out
@@ -860,15 +860,15 @@ SELECT pg_input_is_valid('6874898-01-01', 'date');
 (1 row)
 
 SELECT pg_input_error_message('garbage', 'date');
-            pg_input_error_message             
------------------------------------------------
- invalid input syntax for type date: "garbage"
+                   pg_input_error_message                    
+-------------------------------------------------------------
+ ("invalid input syntax for type date: ""garbage""",,,22007)
 (1 row)
 
 SELECT pg_input_error_message('6874898-01-01', 'date');
-       pg_input_error_message       
-------------------------------------
- date out of range: "6874898-01-01"
+              pg_input_error_message              
+--------------------------------------------------
+ ("date out of range: ""6874898-01-01""",,,22008)
 (1 row)
 
 RESET datestyle;
diff --git a/src/test/regress/expected/domain.out b/src/test/regress/expected/domain.out
index 25f6bb9e1f..c4adce88c1 100644
--- a/src/test/regress/expected/domain.out
+++ b/src/test/regress/expected/domain.out
@@ -109,27 +109,27 @@ select pg_input_is_valid('-1', 'positiveint');
 (1 row)
 
 select pg_input_error_message('junk', 'positiveint');
-            pg_input_error_message             
------------------------------------------------
- invalid input syntax for type integer: "junk"
+                   pg_input_error_message                    
+-------------------------------------------------------------
+ ("invalid input syntax for type integer: ""junk""",,,22P02)
 (1 row)
 
 select pg_input_error_message('-1', 'positiveint');
-                           pg_input_error_message                           
-----------------------------------------------------------------------------
- value for domain positiveint violates check constraint "positiveint_check"
+                                  pg_input_error_message                                  
+------------------------------------------------------------------------------------------
+ ("value for domain positiveint violates check constraint ""positiveint_check""",,,23514)
 (1 row)
 
 select pg_input_error_message('junk', 'weirdfloat');
-                 pg_input_error_message                 
---------------------------------------------------------
- invalid input syntax for type double precision: "junk"
+                        pg_input_error_message                        
+----------------------------------------------------------------------
+ ("invalid input syntax for type double precision: ""junk""",,,22P02)
 (1 row)
 
 select pg_input_error_message('0.01', 'weirdfloat');
-                          pg_input_error_message                          
---------------------------------------------------------------------------
- value for domain weirdfloat violates check constraint "weirdfloat_check"
+                                 pg_input_error_message                                 
+----------------------------------------------------------------------------------------
+ ("value for domain weirdfloat violates check constraint ""weirdfloat_check""",,,23514)
 (1 row)
 
 -- We currently can't trap errors raised in the CHECK expression itself
diff --git a/src/test/regress/expected/enum.out b/src/test/regress/expected/enum.out
index 4b45fcf8f0..c3cf9625b4 100644
--- a/src/test/regress/expected/enum.out
+++ b/src/test/regress/expected/enum.out
@@ -38,15 +38,15 @@ SELECT pg_input_is_valid('mauve', 'rainbow');
 (1 row)
 
 SELECT pg_input_error_message('mauve', 'rainbow');
-            pg_input_error_message             
------------------------------------------------
- invalid input value for enum rainbow: "mauve"
+                   pg_input_error_message                    
+-------------------------------------------------------------
+ ("invalid input value for enum rainbow: ""mauve""",,,22P02)
 (1 row)
 
 SELECT pg_input_error_message(repeat('too_long', 32), 'rainbow');
-                                                                                                                                          pg_input_error_message                                                                                                                                          
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
- invalid input value for enum rainbow: "too_longtoo_longtoo_longtoo_longtoo_longtoo_longtoo_longtoo_longtoo_longtoo_longtoo_longtoo_longtoo_longtoo_longtoo_longtoo_longtoo_longtoo_longtoo_longtoo_longtoo_longtoo_longtoo_longtoo_longtoo_longtoo_longtoo_longtoo_longtoo_longtoo_longtoo_longtoo_long"
+                                                                                                                                                 pg_input_error_message                                                                                                                                                 
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ ("invalid input value for enum rainbow: ""too_longtoo_longtoo_longtoo_longtoo_longtoo_longtoo_longtoo_longtoo_longtoo_longtoo_longtoo_longtoo_longtoo_longtoo_longtoo_longtoo_longtoo_longtoo_longtoo_longtoo_longtoo_longtoo_longtoo_longtoo_longtoo_longtoo_longtoo_longtoo_longtoo_longtoo_longtoo_long""",,,22P02)
 (1 row)
 
 --
diff --git a/src/test/regress/expected/float4.out b/src/test/regress/expected/float4.out
index 1d7090a90d..7b0f71a23d 100644
--- a/src/test/regress/expected/float4.out
+++ b/src/test/regress/expected/float4.out
@@ -101,9 +101,9 @@ SELECT pg_input_is_valid('1e400', 'float4');
 (1 row)
 
 SELECT pg_input_error_message('1e400', 'float4');
-        pg_input_error_message         
----------------------------------------
- "1e400" is out of range for type real
+               pg_input_error_message                
+-----------------------------------------------------
+ ("""1e400"" is out of range for type real",,,22003)
 (1 row)
 
 -- special inputs
diff --git a/src/test/regress/expected/float8.out b/src/test/regress/expected/float8.out
index 2b25784f7f..f6c8941438 100644
--- a/src/test/regress/expected/float8.out
+++ b/src/test/regress/expected/float8.out
@@ -88,9 +88,9 @@ SELECT pg_input_is_valid('1e4000', 'float8');
 (1 row)
 
 SELECT pg_input_error_message('1e4000', 'float8');
-               pg_input_error_message               
-----------------------------------------------------
- "1e4000" is out of range for type double precision
+                      pg_input_error_message                      
+------------------------------------------------------------------
+ ("""1e4000"" is out of range for type double precision",,,22003)
 (1 row)
 
 -- special inputs
diff --git a/src/test/regress/expected/geometry.out b/src/test/regress/expected/geometry.out
index 291cacdf4f..54bc17a6d7 100644
--- a/src/test/regress/expected/geometry.out
+++ b/src/test/regress/expected/geometry.out
@@ -5303,9 +5303,9 @@ SELECT pg_input_is_valid('(1', 'circle');
 (1 row)
 
 SELECT pg_input_error_message('1,', 'circle');
-           pg_input_error_message           
---------------------------------------------
- invalid input syntax for type circle: "1,"
+                  pg_input_error_message                  
+----------------------------------------------------------
+ ("invalid input syntax for type circle: ""1,""",,,22P02)
 (1 row)
 
 SELECT pg_input_is_valid('(1,2),-1', 'circle');
@@ -5315,8 +5315,8 @@ SELECT pg_input_is_valid('(1,2),-1', 'circle');
 (1 row)
 
 SELECT pg_input_error_message('(1,2),-1', 'circle');
-              pg_input_error_message              
---------------------------------------------------
- invalid input syntax for type circle: "(1,2),-1"
+                     pg_input_error_message                     
+----------------------------------------------------------------
+ ("invalid input syntax for type circle: ""(1,2),-1""",,,22P02)
 (1 row)
 
diff --git a/src/test/regress/expected/inet.out b/src/test/regress/expected/inet.out
index c9f466ac1d..957c0003fc 100644
--- a/src/test/regress/expected/inet.out
+++ b/src/test/regress/expected/inet.out
@@ -1064,9 +1064,9 @@ SELECT pg_input_is_valid('1234', 'cidr');
 (1 row)
 
 SELECT pg_input_error_message('1234', 'cidr');
-           pg_input_error_message           
---------------------------------------------
- invalid input syntax for type cidr: "1234"
+                  pg_input_error_message                  
+----------------------------------------------------------
+ ("invalid input syntax for type cidr: ""1234""",,,22P02)
 (1 row)
 
 SELECT pg_input_is_valid('192.168.198.200/24', 'cidr');
@@ -1076,9 +1076,9 @@ SELECT pg_input_is_valid('192.168.198.200/24', 'cidr');
 (1 row)
 
 SELECT pg_input_error_message('192.168.198.200/24', 'cidr');
-          pg_input_error_message          
-------------------------------------------
- invalid cidr value: "192.168.198.200/24"
+                                    pg_input_error_message                                    
+----------------------------------------------------------------------------------------------
+ ("invalid cidr value: ""192.168.198.200/24""","Value has bits set to right of mask.",,22P02)
 (1 row)
 
 SELECT pg_input_is_valid('1234', 'inet');
@@ -1088,8 +1088,8 @@ SELECT pg_input_is_valid('1234', 'inet');
 (1 row)
 
 SELECT pg_input_error_message('1234', 'inet');
-           pg_input_error_message           
---------------------------------------------
- invalid input syntax for type inet: "1234"
+                  pg_input_error_message                  
+----------------------------------------------------------
+ ("invalid input syntax for type inet: ""1234""",,,22P02)
 (1 row)
 
diff --git a/src/test/regress/expected/int2.out b/src/test/regress/expected/int2.out
index 73b4ee023c..d42b15c423 100644
--- a/src/test/regress/expected/int2.out
+++ b/src/test/regress/expected/int2.out
@@ -65,9 +65,9 @@ SELECT pg_input_is_valid('50000', 'int2');
 (1 row)
 
 SELECT pg_input_error_message('50000', 'int2');
-             pg_input_error_message              
--------------------------------------------------
- value "50000" is out of range for type smallint
+                    pg_input_error_message                     
+---------------------------------------------------------------
+ ("value ""50000"" is out of range for type smallint",,,22003)
 (1 row)
 
 -- While we're here, check int2vector as well
@@ -78,15 +78,15 @@ SELECT pg_input_is_valid(' 1 3  5 ', 'int2vector');
 (1 row)
 
 SELECT pg_input_error_message('1 asdf', 'int2vector');
-             pg_input_error_message             
-------------------------------------------------
- invalid input syntax for type smallint: "asdf"
+                    pg_input_error_message                    
+--------------------------------------------------------------
+ ("invalid input syntax for type smallint: ""asdf""",,,22P02)
 (1 row)
 
 SELECT pg_input_error_message('50000', 'int2vector');
-             pg_input_error_message              
--------------------------------------------------
- value "50000" is out of range for type smallint
+                    pg_input_error_message                     
+---------------------------------------------------------------
+ ("value ""50000"" is out of range for type smallint",,,22003)
 (1 row)
 
 SELECT * FROM INT2_TBL AS f(a, b);
diff --git a/src/test/regress/expected/int4.out b/src/test/regress/expected/int4.out
index 9c20574ca5..683415a948 100644
--- a/src/test/regress/expected/int4.out
+++ b/src/test/regress/expected/int4.out
@@ -65,9 +65,9 @@ SELECT pg_input_is_valid('1000000000000', 'int4');
 (1 row)
 
 SELECT pg_input_error_message('1000000000000', 'int4');
-                 pg_input_error_message                 
---------------------------------------------------------
- value "1000000000000" is out of range for type integer
+                        pg_input_error_message                        
+----------------------------------------------------------------------
+ ("value ""1000000000000"" is out of range for type integer",,,22003)
 (1 row)
 
 SELECT i.* FROM INT4_TBL i WHERE i.f1 <> int2 '0';
diff --git a/src/test/regress/expected/int8.out b/src/test/regress/expected/int8.out
index d9dca64e88..e081cb6b00 100644
--- a/src/test/regress/expected/int8.out
+++ b/src/test/regress/expected/int8.out
@@ -62,9 +62,9 @@ SELECT pg_input_is_valid('10000000000000000000', 'int8');
 (1 row)
 
 SELECT pg_input_error_message('10000000000000000000', 'int8');
-                    pg_input_error_message                    
---------------------------------------------------------------
- value "10000000000000000000" is out of range for type bigint
+                           pg_input_error_message                           
+----------------------------------------------------------------------------
+ ("value ""10000000000000000000"" is out of range for type bigint",,,22003)
 (1 row)
 
 -- int8/int8 cmp
diff --git a/src/test/regress/expected/interval.out b/src/test/regress/expected/interval.out
index a154840c85..2a7b49c36c 100644
--- a/src/test/regress/expected/interval.out
+++ b/src/test/regress/expected/interval.out
@@ -92,15 +92,15 @@ SELECT pg_input_is_valid('@ 30 eons ago', 'interval');
 (1 row)
 
 SELECT pg_input_error_message('garbage', 'interval');
-              pg_input_error_message               
----------------------------------------------------
- invalid input syntax for type interval: "garbage"
+                     pg_input_error_message                      
+-----------------------------------------------------------------
+ ("invalid input syntax for type interval: ""garbage""",,,22007)
 (1 row)
 
 SELECT pg_input_error_message('@ 30 eons ago', 'interval');
-                 pg_input_error_message                  
----------------------------------------------------------
- invalid input syntax for type interval: "@ 30 eons ago"
+                        pg_input_error_message                         
+-----------------------------------------------------------------------
+ ("invalid input syntax for type interval: ""@ 30 eons ago""",,,22007)
 (1 row)
 
 -- test interval operators
diff --git a/src/test/regress/expected/json.out b/src/test/regress/expected/json.out
index af96ce4180..a3096c2c2e 100644
--- a/src/test/regress/expected/json.out
+++ b/src/test/regress/expected/json.out
@@ -334,9 +334,9 @@ select pg_input_is_valid('{"a":true', 'json');
 (1 row)
 
 select pg_input_error_message('{"a":true', 'json');
-       pg_input_error_message       
-------------------------------------
- invalid input syntax for type json
+                                pg_input_error_message                                
+--------------------------------------------------------------------------------------
+ ("invalid input syntax for type json","The input string ended unexpectedly.",,22P02)
 (1 row)
 
 --constructors
diff --git a/src/test/regress/expected/json_encoding.out b/src/test/regress/expected/json_encoding.out
index 083621fb21..54a5bb75f5 100644
--- a/src/test/regress/expected/json_encoding.out
+++ b/src/test/regress/expected/json_encoding.out
@@ -264,6 +264,6 @@ SELECT jsonb '{ "a":  "null \\u0000 escape" }' ->> 'a' as not_an_escape;
 select pg_input_error_message('{ "a":  "\ud83d\ude04\ud83d\udc36" }', 'jsonb');
  pg_input_error_message 
 ------------------------
- 
+ (,,,)
 (1 row)
 
diff --git a/src/test/regress/expected/jsonb.out b/src/test/regress/expected/jsonb.out
index d3248aa0fd..dc125b1b56 100644
--- a/src/test/regress/expected/jsonb.out
+++ b/src/test/regress/expected/jsonb.out
@@ -324,15 +324,15 @@ select pg_input_is_valid('{"a":true', 'jsonb');
 (1 row)
 
 select pg_input_error_message('{"a":true', 'jsonb');
-       pg_input_error_message       
-------------------------------------
- invalid input syntax for type json
+                                pg_input_error_message                                
+--------------------------------------------------------------------------------------
+ ("invalid input syntax for type json","The input string ended unexpectedly.",,22P02)
 (1 row)
 
 select pg_input_error_message('{"a":1e1000000}', 'jsonb');
-     pg_input_error_message     
---------------------------------
- value overflows numeric format
+           pg_input_error_message           
+--------------------------------------------
+ ("value overflows numeric format",,,22003)
 (1 row)
 
 -- make sure jsonb is passed through json generators without being escaped
diff --git a/src/test/regress/expected/jsonpath.out b/src/test/regress/expected/jsonpath.out
index ca0cdf1ab2..87a4141f3a 100644
--- a/src/test/regress/expected/jsonpath.out
+++ b/src/test/regress/expected/jsonpath.out
@@ -1041,12 +1041,12 @@ FROM unnest(ARRAY['$ ? (@ like_regex "pattern" flag "smixq")'::text,
                   '@ + 1',
                   '00',
                   '1a']) str;
-                 jsonpath                  | ok |                                errmsg                                 
--------------------------------------------+----+-----------------------------------------------------------------------
- $ ? (@ like_regex "pattern" flag "smixq") | t  | 
- $ ? (@ like_regex "pattern" flag "a")     | f  | invalid input syntax for type jsonpath
- @ + 1                                     | f  | @ is not allowed in root expressions
- 00                                        | f  | trailing junk after numeric literal at or near "00" of jsonpath input
- 1a                                        | f  | trailing junk after numeric literal at or near "1a" of jsonpath input
+                 jsonpath                  | ok |                                                     errmsg                                                     
+-------------------------------------------+----+----------------------------------------------------------------------------------------------------------------
+ $ ? (@ like_regex "pattern" flag "smixq") | t  | (,,,)
+ $ ? (@ like_regex "pattern" flag "a")     | f  | ("invalid input syntax for type jsonpath","Unrecognized flag character ""a"" in LIKE_REGEX predicate.",,42601)
+ @ + 1                                     | f  | ("@ is not allowed in root expressions",,,42601)
+ 00                                        | f  | ("trailing junk after numeric literal at or near ""00"" of jsonpath input",,,42601)
+ 1a                                        | f  | ("trailing junk after numeric literal at or near ""1a"" of jsonpath input",,,42601)
 (5 rows)
 
diff --git a/src/test/regress/expected/line.out b/src/test/regress/expected/line.out
index 6baea8fdbd..4f67aee728 100644
--- a/src/test/regress/expected/line.out
+++ b/src/test/regress/expected/line.out
@@ -93,9 +93,9 @@ SELECT pg_input_is_valid('{1, 1}', 'line');
 (1 row)
 
 SELECT pg_input_error_message('{1, 1}', 'line');
-            pg_input_error_message            
-----------------------------------------------
- invalid input syntax for type line: "{1, 1}"
+                   pg_input_error_message                   
+------------------------------------------------------------
+ ("invalid input syntax for type line: ""{1, 1}""",,,22P02)
 (1 row)
 
 SELECT pg_input_is_valid('{0, 0, 0}', 'line');
@@ -105,9 +105,9 @@ SELECT pg_input_is_valid('{0, 0, 0}', 'line');
 (1 row)
 
 SELECT pg_input_error_message('{0, 0, 0}', 'line');
-                 pg_input_error_message                  
----------------------------------------------------------
- invalid line specification: A and B cannot both be zero
+                       pg_input_error_message                        
+---------------------------------------------------------------------
+ ("invalid line specification: A and B cannot both be zero",,,22P02)
 (1 row)
 
 SELECT pg_input_is_valid('{1, 1, a}', 'line');
@@ -117,9 +117,9 @@ SELECT pg_input_is_valid('{1, 1, a}', 'line');
 (1 row)
 
 SELECT pg_input_error_message('{1, 1, a}', 'line');
-             pg_input_error_message              
--------------------------------------------------
- invalid input syntax for type line: "{1, 1, a}"
+                    pg_input_error_message                     
+---------------------------------------------------------------
+ ("invalid input syntax for type line: ""{1, 1, a}""",,,22P02)
 (1 row)
 
 SELECT pg_input_is_valid('{1, 1, 1e400}', 'line');
@@ -129,9 +129,9 @@ SELECT pg_input_is_valid('{1, 1, 1e400}', 'line');
 (1 row)
 
 SELECT pg_input_error_message('{1, 1, 1e400}', 'line');
-              pg_input_error_message               
----------------------------------------------------
- "1e400" is out of range for type double precision
+                     pg_input_error_message                      
+-----------------------------------------------------------------
+ ("""1e400"" is out of range for type double precision",,,22003)
 (1 row)
 
 SELECT pg_input_is_valid('(1, 1), (1, 1e400)', 'line');
@@ -141,8 +141,8 @@ SELECT pg_input_is_valid('(1, 1), (1, 1e400)', 'line');
 (1 row)
 
 SELECT pg_input_error_message('(1, 1), (1, 1e400)', 'line');
-              pg_input_error_message               
----------------------------------------------------
- "1e400" is out of range for type double precision
+                     pg_input_error_message                      
+-----------------------------------------------------------------
+ ("""1e400"" is out of range for type double precision",,,22003)
 (1 row)
 
diff --git a/src/test/regress/expected/lseg.out b/src/test/regress/expected/lseg.out
index afb323fe04..14e4f73ed1 100644
--- a/src/test/regress/expected/lseg.out
+++ b/src/test/regress/expected/lseg.out
@@ -50,8 +50,8 @@ SELECT pg_input_is_valid('[(1,2),(3)]', 'lseg');
 (1 row)
 
 SELECT pg_input_error_message('[(1,2),(3)]', 'lseg');
-              pg_input_error_message               
----------------------------------------------------
- invalid input syntax for type lseg: "[(1,2),(3)]"
+                     pg_input_error_message                      
+-----------------------------------------------------------------
+ ("invalid input syntax for type lseg: ""[(1,2),(3)]""",,,22P02)
 (1 row)
 
diff --git a/src/test/regress/expected/macaddr.out b/src/test/regress/expected/macaddr.out
index cb646af79b..ca7c5f71ef 100644
--- a/src/test/regress/expected/macaddr.out
+++ b/src/test/regress/expected/macaddr.out
@@ -166,9 +166,9 @@ SELECT pg_input_is_valid('08:00:2b:01:02:ZZ', 'macaddr');
 (1 row)
 
 SELECT pg_input_error_message('08:00:2b:01:02:ZZ', 'macaddr');
-                   pg_input_error_message                   
-------------------------------------------------------------
- invalid input syntax for type macaddr: "08:00:2b:01:02:ZZ"
+                          pg_input_error_message                          
+--------------------------------------------------------------------------
+ ("invalid input syntax for type macaddr: ""08:00:2b:01:02:ZZ""",,,22P02)
 (1 row)
 
 SELECT pg_input_is_valid('08:00:2b:01:02:', 'macaddr');
@@ -178,8 +178,8 @@ SELECT pg_input_is_valid('08:00:2b:01:02:', 'macaddr');
 (1 row)
 
 SELECT pg_input_error_message('08:00:2b:01:02:', 'macaddr');
-                  pg_input_error_message                  
-----------------------------------------------------------
- invalid input syntax for type macaddr: "08:00:2b:01:02:"
+                         pg_input_error_message                         
+------------------------------------------------------------------------
+ ("invalid input syntax for type macaddr: ""08:00:2b:01:02:""",,,22P02)
 (1 row)
 
diff --git a/src/test/regress/expected/macaddr8.out b/src/test/regress/expected/macaddr8.out
index bf681988f8..fa5308bb1f 100644
--- a/src/test/regress/expected/macaddr8.out
+++ b/src/test/regress/expected/macaddr8.out
@@ -360,9 +360,9 @@ SELECT pg_input_is_valid('08:00:2b:01:02:03:04:ZZ', 'macaddr8');
 (1 row)
 
 SELECT pg_input_error_message('08:00:2b:01:02:03:04:ZZ', 'macaddr8');
-                      pg_input_error_message                       
--------------------------------------------------------------------
- invalid input syntax for type macaddr8: "08:00:2b:01:02:03:04:ZZ"
+                             pg_input_error_message                              
+---------------------------------------------------------------------------------
+ ("invalid input syntax for type macaddr8: ""08:00:2b:01:02:03:04:ZZ""",,,22P02)
 (1 row)
 
 SELECT pg_input_is_valid('08:00:2b:01:02:03:04:', 'macaddr8');
@@ -372,8 +372,8 @@ SELECT pg_input_is_valid('08:00:2b:01:02:03:04:', 'macaddr8');
 (1 row)
 
 SELECT pg_input_error_message('08:00:2b:01:02:03:04:', 'macaddr8');
-                     pg_input_error_message                      
------------------------------------------------------------------
- invalid input syntax for type macaddr8: "08:00:2b:01:02:03:04:"
+                            pg_input_error_message                             
+-------------------------------------------------------------------------------
+ ("invalid input syntax for type macaddr8: ""08:00:2b:01:02:03:04:""",,,22P02)
 (1 row)
 
diff --git a/src/test/regress/expected/money.out b/src/test/regress/expected/money.out
index 46b2eab51a..574cbd17a5 100644
--- a/src/test/regress/expected/money.out
+++ b/src/test/regress/expected/money.out
@@ -339,9 +339,9 @@ SELECT pg_input_is_valid('\x0001', 'money');
 (1 row)
 
 SELECT pg_input_error_message('\x0001', 'money');
-            pg_input_error_message             
------------------------------------------------
- invalid input syntax for type money: "\x0001"
+                    pg_input_error_message                    
+--------------------------------------------------------------
+ ("invalid input syntax for type money: ""\\x0001""",,,22P02)
 (1 row)
 
 SELECT pg_input_is_valid('192233720368547758.07', 'money');
@@ -351,9 +351,9 @@ SELECT pg_input_is_valid('192233720368547758.07', 'money');
 (1 row)
 
 SELECT pg_input_error_message('192233720368547758.07', 'money');
-                    pg_input_error_message                    
---------------------------------------------------------------
- value "192233720368547758.07" is out of range for type money
+                           pg_input_error_message                           
+----------------------------------------------------------------------------
+ ("value ""192233720368547758.07"" is out of range for type money",,,22003)
 (1 row)
 
 -- documented minimums and maximums
diff --git a/src/test/regress/expected/multirangetypes.out b/src/test/regress/expected/multirangetypes.out
index e70896b754..79137d14bb 100644
--- a/src/test/regress/expected/multirangetypes.out
+++ b/src/test/regress/expected/multirangetypes.out
@@ -288,9 +288,9 @@ select pg_input_is_valid('{[1,2], [4,5]', 'int4multirange');
 (1 row)
 
 select pg_input_error_message('{[1,2], [4,5]', 'int4multirange');
-            pg_input_error_message             
------------------------------------------------
- malformed multirange literal: "{[1,2], [4,5]"
+                                pg_input_error_message                                 
+---------------------------------------------------------------------------------------
+ ("malformed multirange literal: ""{[1,2], [4,5]""","Unexpected end of input.",,22P02)
 (1 row)
 
 select pg_input_is_valid('{[1,2], [4,zed]}', 'int4multirange');
@@ -300,9 +300,9 @@ select pg_input_is_valid('{[1,2], [4,zed]}', 'int4multirange');
 (1 row)
 
 select pg_input_error_message('{[1,2], [4,zed]}', 'int4multirange');
-            pg_input_error_message            
-----------------------------------------------
- invalid input syntax for type integer: "zed"
+                   pg_input_error_message                   
+------------------------------------------------------------
+ ("invalid input syntax for type integer: ""zed""",,,22P02)
 (1 row)
 
 --
diff --git a/src/test/regress/expected/numeric.out b/src/test/regress/expected/numeric.out
index 56a3f3630a..cee8603dad 100644
--- a/src/test/regress/expected/numeric.out
+++ b/src/test/regress/expected/numeric.out
@@ -2313,9 +2313,9 @@ SELECT pg_input_is_valid('1e400000', 'numeric');
 (1 row)
 
 SELECT pg_input_error_message('1e400000', 'numeric');
-     pg_input_error_message     
---------------------------------
- value overflows numeric format
+           pg_input_error_message           
+--------------------------------------------
+ ("value overflows numeric format",,,22003)
 (1 row)
 
 SELECT pg_input_is_valid('1234.567', 'numeric(8,4)');
@@ -2331,15 +2331,15 @@ SELECT pg_input_is_valid('1234.567', 'numeric(7,4)');
 (1 row)
 
 SELECT pg_input_error_message('1234.567', 'numeric(7,4)');
- pg_input_error_message 
-------------------------
- numeric field overflow
+                                                pg_input_error_message                                                 
+-----------------------------------------------------------------------------------------------------------------------
+ ("numeric field overflow","A field with precision 7, scale 4 must round to an absolute value less than 10^3.",,22003)
 (1 row)
 
 SELECT pg_input_error_message('0x1234.567', 'numeric');
-               pg_input_error_message                
------------------------------------------------------
- invalid input syntax for type numeric: "0x1234.567"
+                      pg_input_error_message                       
+-------------------------------------------------------------------
+ ("invalid input syntax for type numeric: ""0x1234.567""",,,22P02)
 (1 row)
 
 --
diff --git a/src/test/regress/expected/oid.out b/src/test/regress/expected/oid.out
index b664bab5f9..2a4c3b08df 100644
--- a/src/test/regress/expected/oid.out
+++ b/src/test/regress/expected/oid.out
@@ -79,9 +79,9 @@ SELECT pg_input_is_valid('01XYZ', 'oid');
 (1 row)
 
 SELECT pg_input_error_message('01XYZ', 'oid');
-           pg_input_error_message           
---------------------------------------------
- invalid input syntax for type oid: "01XYZ"
+                  pg_input_error_message                  
+----------------------------------------------------------
+ ("invalid input syntax for type oid: ""01XYZ""",,,22P02)
 (1 row)
 
 SELECT pg_input_is_valid('9999999999', 'oid');
@@ -91,9 +91,9 @@ SELECT pg_input_is_valid('9999999999', 'oid');
 (1 row)
 
 SELECT pg_input_error_message('9999999999', 'oid');
-             pg_input_error_message              
--------------------------------------------------
- value "9999999999" is out of range for type oid
+                    pg_input_error_message                     
+---------------------------------------------------------------
+ ("value ""9999999999"" is out of range for type oid",,,22003)
 (1 row)
 
 -- While we're here, check oidvector as well
@@ -110,9 +110,9 @@ SELECT pg_input_is_valid('01 01XYZ', 'oidvector');
 (1 row)
 
 SELECT pg_input_error_message('01 01XYZ', 'oidvector');
-          pg_input_error_message          
-------------------------------------------
- invalid input syntax for type oid: "XYZ"
+                 pg_input_error_message                 
+--------------------------------------------------------
+ ("invalid input syntax for type oid: ""XYZ""",,,22P02)
 (1 row)
 
 SELECT pg_input_is_valid('01 9999999999', 'oidvector');
@@ -122,9 +122,9 @@ SELECT pg_input_is_valid('01 9999999999', 'oidvector');
 (1 row)
 
 SELECT pg_input_error_message('01 9999999999', 'oidvector');
-             pg_input_error_message              
--------------------------------------------------
- value "9999999999" is out of range for type oid
+                    pg_input_error_message                     
+---------------------------------------------------------------
+ ("value ""9999999999"" is out of range for type oid",,,22003)
 (1 row)
 
 SELECT o.* FROM OID_TBL o WHERE o.f1 = 1234;
diff --git a/src/test/regress/expected/path.out b/src/test/regress/expected/path.out
index 529a5e6fc2..2886091675 100644
--- a/src/test/regress/expected/path.out
+++ b/src/test/regress/expected/path.out
@@ -88,9 +88,9 @@ SELECT pg_input_is_valid('[(1,2),(3)]', 'path');
 (1 row)
 
 SELECT pg_input_error_message('[(1,2),(3)]', 'path');
-              pg_input_error_message               
----------------------------------------------------
- invalid input syntax for type path: "[(1,2),(3)]"
+                     pg_input_error_message                      
+-----------------------------------------------------------------
+ ("invalid input syntax for type path: ""[(1,2),(3)]""",,,22P02)
 (1 row)
 
 SELECT pg_input_is_valid('[(1,2,6),(3,4,6)]', 'path');
@@ -100,8 +100,8 @@ SELECT pg_input_is_valid('[(1,2,6),(3,4,6)]', 'path');
 (1 row)
 
 SELECT pg_input_error_message('[(1,2,6),(3,4,6)]', 'path');
-                 pg_input_error_message                  
----------------------------------------------------------
- invalid input syntax for type path: "[(1,2,6),(3,4,6)]"
+                        pg_input_error_message                         
+-----------------------------------------------------------------------
+ ("invalid input syntax for type path: ""[(1,2,6),(3,4,6)]""",,,22P02)
 (1 row)
 
diff --git a/src/test/regress/expected/pg_lsn.out b/src/test/regress/expected/pg_lsn.out
index 01501f8c9b..7dfa0bae8b 100644
--- a/src/test/regress/expected/pg_lsn.out
+++ b/src/test/regress/expected/pg_lsn.out
@@ -34,9 +34,9 @@ SELECT pg_input_is_valid('16AE7F7', 'pg_lsn');
 (1 row)
 
 SELECT pg_input_error_message('16AE7F7', 'pg_lsn');
-             pg_input_error_message              
--------------------------------------------------
- invalid input syntax for type pg_lsn: "16AE7F7"
+                    pg_input_error_message                     
+---------------------------------------------------------------
+ ("invalid input syntax for type pg_lsn: ""16AE7F7""",,,22P02)
 (1 row)
 
 -- Min/Max aggregation
diff --git a/src/test/regress/expected/point.out b/src/test/regress/expected/point.out
index a716ceb881..5a5b1ac4ef 100644
--- a/src/test/regress/expected/point.out
+++ b/src/test/regress/expected/point.out
@@ -471,8 +471,8 @@ SELECT pg_input_is_valid('1,y', 'point');
 (1 row)
 
 SELECT pg_input_error_message('1,y', 'point');
-           pg_input_error_message           
---------------------------------------------
- invalid input syntax for type point: "1,y"
+                  pg_input_error_message                  
+----------------------------------------------------------
+ ("invalid input syntax for type point: ""1,y""",,,22P02)
 (1 row)
 
diff --git a/src/test/regress/expected/polygon.out b/src/test/regress/expected/polygon.out
index c7d565ad53..ef31e4c631 100644
--- a/src/test/regress/expected/polygon.out
+++ b/src/test/regress/expected/polygon.out
@@ -314,9 +314,9 @@ SELECT pg_input_is_valid('(2.0,0.8,0.1)', 'polygon');
 (1 row)
 
 SELECT pg_input_error_message('(2.0,0.8,0.1)', 'polygon');
-                 pg_input_error_message                 
---------------------------------------------------------
- invalid input syntax for type polygon: "(2.0,0.8,0.1)"
+                        pg_input_error_message                        
+----------------------------------------------------------------------
+ ("invalid input syntax for type polygon: ""(2.0,0.8,0.1)""",,,22P02)
 (1 row)
 
 SELECT pg_input_is_valid('(2.0,xyz)', 'polygon');
@@ -326,8 +326,8 @@ SELECT pg_input_is_valid('(2.0,xyz)', 'polygon');
 (1 row)
 
 SELECT pg_input_error_message('(2.0,xyz)', 'polygon');
-               pg_input_error_message               
-----------------------------------------------------
- invalid input syntax for type polygon: "(2.0,xyz)"
+                      pg_input_error_message                      
+------------------------------------------------------------------
+ ("invalid input syntax for type polygon: ""(2.0,xyz)""",,,22P02)
 (1 row)
 
diff --git a/src/test/regress/expected/privileges.out b/src/test/regress/expected/privileges.out
index 95d1e5515f..c2e82f39e7 100644
--- a/src/test/regress/expected/privileges.out
+++ b/src/test/regress/expected/privileges.out
@@ -2247,9 +2247,9 @@ SELECT pg_input_is_valid('regress_priv_user1=r/', 'aclitem');
 (1 row)
 
 SELECT pg_input_error_message('regress_priv_user1=r/', 'aclitem');
-     pg_input_error_message      
----------------------------------
- a name must follow the "/" sign
+            pg_input_error_message             
+-----------------------------------------------
+ ("a name must follow the ""/"" sign",,,22P02)
 (1 row)
 
 SELECT pg_input_is_valid('regress_priv_user1=r/regress_no_such_user', 'aclitem');
@@ -2259,9 +2259,9 @@ SELECT pg_input_is_valid('regress_priv_user1=r/regress_no_such_user', 'aclitem')
 (1 row)
 
 SELECT pg_input_error_message('regress_priv_user1=r/regress_no_such_user', 'aclitem');
-           pg_input_error_message           
---------------------------------------------
- role "regress_no_such_user" does not exist
+                  pg_input_error_message                  
+----------------------------------------------------------
+ ("role ""regress_no_such_user"" does not exist",,,42704)
 (1 row)
 
 SELECT pg_input_is_valid('regress_priv_user1=rY', 'aclitem');
@@ -2271,9 +2271,9 @@ SELECT pg_input_is_valid('regress_priv_user1=rY', 'aclitem');
 (1 row)
 
 SELECT pg_input_error_message('regress_priv_user1=rY', 'aclitem');
-                  pg_input_error_message                  
-----------------------------------------------------------
- invalid mode character: must be one of "arwdDxtXUCTcsAm"
+                         pg_input_error_message                         
+------------------------------------------------------------------------
+ ("invalid mode character: must be one of ""arwdDxtXUCTcsAm""",,,22P02)
 (1 row)
 
 --
diff --git a/src/test/regress/expected/rangetypes.out b/src/test/regress/expected/rangetypes.out
index a3e9e447af..e3f1029555 100644
--- a/src/test/regress/expected/rangetypes.out
+++ b/src/test/regress/expected/rangetypes.out
@@ -189,9 +189,9 @@ select pg_input_is_valid('(1,4', 'int4range');
 (1 row)
 
 select pg_input_error_message('(1,4', 'int4range');
-     pg_input_error_message      
----------------------------------
- malformed range literal: "(1,4"
+                         pg_input_error_message                          
+-------------------------------------------------------------------------
+ ("malformed range literal: ""(1,4""","Unexpected end of input.",,22P02)
 (1 row)
 
 select pg_input_is_valid('(4,1)', 'int4range');
@@ -201,9 +201,9 @@ select pg_input_is_valid('(4,1)', 'int4range');
 (1 row)
 
 select pg_input_error_message('(4,1)', 'int4range');
-                      pg_input_error_message                       
--------------------------------------------------------------------
- range lower bound must be less than or equal to range upper bound
+                            pg_input_error_message                             
+-------------------------------------------------------------------------------
+ ("range lower bound must be less than or equal to range upper bound",,,22000)
 (1 row)
 
 select pg_input_is_valid('(4,zed)', 'int4range');
@@ -213,9 +213,9 @@ select pg_input_is_valid('(4,zed)', 'int4range');
 (1 row)
 
 select pg_input_error_message('(4,zed)', 'int4range');
-            pg_input_error_message            
-----------------------------------------------
- invalid input syntax for type integer: "zed"
+                   pg_input_error_message                   
+------------------------------------------------------------
+ ("invalid input syntax for type integer: ""zed""",,,22P02)
 (1 row)
 
 select pg_input_is_valid('[1,2147483647]', 'int4range');
@@ -225,9 +225,9 @@ select pg_input_is_valid('[1,2147483647]', 'int4range');
 (1 row)
 
 select pg_input_error_message('[1,2147483647]', 'int4range');
- pg_input_error_message 
-------------------------
- integer out of range
+      pg_input_error_message      
+----------------------------------
+ ("integer out of range",,,22003)
 (1 row)
 
 select pg_input_is_valid('[2000-01-01,5874897-12-31]', 'daterange');
@@ -237,9 +237,9 @@ select pg_input_is_valid('[2000-01-01,5874897-12-31]', 'daterange');
 (1 row)
 
 select pg_input_error_message('[2000-01-01,5874897-12-31]', 'daterange');
- pg_input_error_message 
-------------------------
- date out of range
+    pg_input_error_message     
+-------------------------------
+ ("date out of range",,,22008)
 (1 row)
 
 --
diff --git a/src/test/regress/expected/regproc.out b/src/test/regress/expected/regproc.out
index a034fbb346..cd1d79bad7 100644
--- a/src/test/regress/expected/regproc.out
+++ b/src/test/regress/expected/regproc.out
@@ -449,9 +449,9 @@ SELECT to_regnamespace('foo.bar');
 
 -- Test soft-error API
 SELECT pg_input_error_message('ng_catalog.pg_class', 'regclass');
-            pg_input_error_message             
------------------------------------------------
- relation "ng_catalog.pg_class" does not exist
+                   pg_input_error_message                    
+-------------------------------------------------------------
+ ("relation ""ng_catalog.pg_class"" does not exist",,,42P01)
 (1 row)
 
 SELECT pg_input_is_valid('ng_catalog."POSIX"', 'regcollation');
@@ -461,75 +461,75 @@ SELECT pg_input_is_valid('ng_catalog."POSIX"', 'regcollation');
 (1 row)
 
 SELECT pg_input_error_message('no_such_config', 'regconfig');
-                  pg_input_error_message                   
------------------------------------------------------------
- text search configuration "no_such_config" does not exist
+                         pg_input_error_message                          
+-------------------------------------------------------------------------
+ ("text search configuration ""no_such_config"" does not exist",,,42704)
 (1 row)
 
 SELECT pg_input_error_message('no_such_dictionary', 'regdictionary');
-                   pg_input_error_message                   
-------------------------------------------------------------
- text search dictionary "no_such_dictionary" does not exist
+                          pg_input_error_message                          
+--------------------------------------------------------------------------
+ ("text search dictionary ""no_such_dictionary"" does not exist",,,42704)
 (1 row)
 
 SELECT pg_input_error_message('Nonexistent', 'regnamespace');
-       pg_input_error_message        
--------------------------------------
- schema "nonexistent" does not exist
+              pg_input_error_message               
+---------------------------------------------------
+ ("schema ""nonexistent"" does not exist",,,3F000)
 (1 row)
 
 SELECT pg_input_error_message('ng_catalog.||/', 'regoper');
-         pg_input_error_message          
------------------------------------------
- operator does not exist: ng_catalog.||/
+               pg_input_error_message                
+-----------------------------------------------------
+ ("operator does not exist: ng_catalog.||/",,,42883)
 (1 row)
 
 SELECT pg_input_error_message('-', 'regoper');
-     pg_input_error_message     
---------------------------------
- more than one operator named -
+           pg_input_error_message           
+--------------------------------------------
+ ("more than one operator named -",,,42725)
 (1 row)
 
 SELECT pg_input_error_message('ng_catalog.+(int4,int4)', 'regoperator');
-              pg_input_error_message              
---------------------------------------------------
- operator does not exist: ng_catalog.+(int4,int4)
+                    pg_input_error_message                    
+--------------------------------------------------------------
+ ("operator does not exist: ng_catalog.+(int4,int4)",,,42883)
 (1 row)
 
 SELECT pg_input_error_message('-', 'regoperator');
-   pg_input_error_message    
------------------------------
- expected a left parenthesis
+         pg_input_error_message          
+-----------------------------------------
+ ("expected a left parenthesis",,,22P02)
 (1 row)
 
 SELECT pg_input_error_message('ng_catalog.now', 'regproc');
-          pg_input_error_message          
-------------------------------------------
- function "ng_catalog.now" does not exist
+                 pg_input_error_message                 
+--------------------------------------------------------
+ ("function ""ng_catalog.now"" does not exist",,,42883)
 (1 row)
 
 SELECT pg_input_error_message('ng_catalog.abs(numeric)', 'regprocedure');
-              pg_input_error_message               
----------------------------------------------------
- function "ng_catalog.abs(numeric)" does not exist
+                     pg_input_error_message                      
+-----------------------------------------------------------------
+ ("function ""ng_catalog.abs(numeric)"" does not exist",,,42883)
 (1 row)
 
 SELECT pg_input_error_message('ng_catalog.abs(numeric', 'regprocedure');
-    pg_input_error_message    
-------------------------------
- expected a right parenthesis
+          pg_input_error_message          
+------------------------------------------
+ ("expected a right parenthesis",,,22P02)
 (1 row)
 
 SELECT pg_input_error_message('regress_regrole_test', 'regrole');
-           pg_input_error_message           
---------------------------------------------
- role "regress_regrole_test" does not exist
+                  pg_input_error_message                  
+----------------------------------------------------------
+ ("role ""regress_regrole_test"" does not exist",,,42704)
 (1 row)
 
 SELECT pg_input_error_message('no_such_type', 'regtype');
-       pg_input_error_message       
-------------------------------------
- type "no_such_type" does not exist
+              pg_input_error_message              
+--------------------------------------------------
+ ("type ""no_such_type"" does not exist",,,42704)
 (1 row)
 
 -- Some cases that should be soft errors, but are not yet
diff --git a/src/test/regress/expected/rowtypes.out b/src/test/regress/expected/rowtypes.out
index 801d9e556b..a9fb5320e3 100644
--- a/src/test/regress/expected/rowtypes.out
+++ b/src/test/regress/expected/rowtypes.out
@@ -89,15 +89,15 @@ SELECT pg_input_is_valid('(1,zed)', 'complex');
 (1 row)
 
 SELECT pg_input_error_message('(1,zed)', 'complex');
-                pg_input_error_message                 
--------------------------------------------------------
- invalid input syntax for type double precision: "zed"
+                       pg_input_error_message                        
+---------------------------------------------------------------------
+ ("invalid input syntax for type double precision: ""zed""",,,22P02)
 (1 row)
 
 SELECT pg_input_error_message('(1,1e400)', 'complex');
-              pg_input_error_message               
----------------------------------------------------
- "1e400" is out of range for type double precision
+                     pg_input_error_message                      
+-----------------------------------------------------------------
+ ("""1e400"" is out of range for type double precision",,,22003)
 (1 row)
 
 create temp table quadtable(f1 int, q quad);
diff --git a/src/test/regress/expected/strings.out b/src/test/regress/expected/strings.out
index f028c1f10f..28c78c960b 100644
--- a/src/test/regress/expected/strings.out
+++ b/src/test/regress/expected/strings.out
@@ -281,21 +281,21 @@ SELECT pg_input_is_valid(E'\\xDeAdBeE', 'bytea');
 (1 row)
 
 SELECT pg_input_error_message(E'\\xDeAdBeE', 'bytea');
-             pg_input_error_message             
-------------------------------------------------
- invalid hexadecimal data: odd number of digits
+                   pg_input_error_message                   
+------------------------------------------------------------
+ ("invalid hexadecimal data: odd number of digits",,,22023)
 (1 row)
 
 SELECT pg_input_error_message(E'\\xDeAdBeEx', 'bytea');
-     pg_input_error_message     
---------------------------------
- invalid hexadecimal digit: "x"
+            pg_input_error_message            
+----------------------------------------------
+ ("invalid hexadecimal digit: ""x""",,,22023)
 (1 row)
 
 SELECT pg_input_error_message(E'foo\\99bar', 'bytea');
-       pg_input_error_message        
--------------------------------------
- invalid input syntax for type bytea
+             pg_input_error_message              
+-------------------------------------------------
+ ("invalid input syntax for type bytea",,,22P02)
 (1 row)
 
 --
diff --git a/src/test/regress/expected/tid.out b/src/test/regress/expected/tid.out
index ff67ed43f0..7ee891cc1a 100644
--- a/src/test/regress/expected/tid.out
+++ b/src/test/regress/expected/tid.out
@@ -25,9 +25,9 @@ SELECT pg_input_is_valid('(0)', 'tid');
 (1 row)
 
 SELECT pg_input_error_message('(0)', 'tid');
-          pg_input_error_message          
-------------------------------------------
- invalid input syntax for type tid: "(0)"
+                 pg_input_error_message                 
+--------------------------------------------------------
+ ("invalid input syntax for type tid: ""(0)""",,,22P02)
 (1 row)
 
 SELECT pg_input_is_valid('(0,-1)', 'tid');
@@ -37,9 +37,9 @@ SELECT pg_input_is_valid('(0,-1)', 'tid');
 (1 row)
 
 SELECT pg_input_error_message('(0,-1)', 'tid');
-           pg_input_error_message            
----------------------------------------------
- invalid input syntax for type tid: "(0,-1)"
+                  pg_input_error_message                   
+-----------------------------------------------------------
+ ("invalid input syntax for type tid: ""(0,-1)""",,,22P02)
 (1 row)
 
 -- tests for functions related to TID handling
diff --git a/src/test/regress/expected/time.out b/src/test/regress/expected/time.out
index a44caededd..79de9377db 100644
--- a/src/test/regress/expected/time.out
+++ b/src/test/regress/expected/time.out
@@ -134,15 +134,15 @@ SELECT pg_input_is_valid('15:36:39 America/New_York', 'time');
 (1 row)
 
 SELECT pg_input_error_message('25:00:00', 'time');
-             pg_input_error_message             
-------------------------------------------------
- date/time field value out of range: "25:00:00"
+                    pg_input_error_message                    
+--------------------------------------------------------------
+ ("date/time field value out of range: ""25:00:00""",,,22008)
 (1 row)
 
 SELECT pg_input_error_message('15:36:39 America/New_York', 'time');
-                     pg_input_error_message                      
------------------------------------------------------------------
- invalid input syntax for type time: "15:36:39 America/New_York"
+                            pg_input_error_message                             
+-------------------------------------------------------------------------------
+ ("invalid input syntax for type time: ""15:36:39 America/New_York""",,,22007)
 (1 row)
 
 --
diff --git a/src/test/regress/expected/timestamp.out b/src/test/regress/expected/timestamp.out
index eef2f7001c..eafccc38ac 100644
--- a/src/test/regress/expected/timestamp.out
+++ b/src/test/regress/expected/timestamp.out
@@ -145,15 +145,15 @@ SELECT pg_input_is_valid('2001-01-01 00:00 Nehwon/Lankhmar', 'timestamp');
 (1 row)
 
 SELECT pg_input_error_message('garbage', 'timestamp');
-               pg_input_error_message               
-----------------------------------------------------
- invalid input syntax for type timestamp: "garbage"
+                      pg_input_error_message                      
+------------------------------------------------------------------
+ ("invalid input syntax for type timestamp: ""garbage""",,,22007)
 (1 row)
 
 SELECT pg_input_error_message('2001-01-01 00:00 Nehwon/Lankhmar', 'timestamp');
-           pg_input_error_message           
---------------------------------------------
- time zone "nehwon/lankhmar" not recognized
+                  pg_input_error_message                  
+----------------------------------------------------------
+ ("time zone ""nehwon/lankhmar"" not recognized",,,22023)
 (1 row)
 
 -- Check date conversion and date arithmetic
diff --git a/src/test/regress/expected/timestamptz.out b/src/test/regress/expected/timestamptz.out
index b85a93a3c2..73c7d70455 100644
--- a/src/test/regress/expected/timestamptz.out
+++ b/src/test/regress/expected/timestamptz.out
@@ -196,15 +196,15 @@ SELECT pg_input_is_valid('2001-01-01 00:00 Nehwon/Lankhmar', 'timestamptz');
 (1 row)
 
 SELECT pg_input_error_message('garbage', 'timestamptz');
-                      pg_input_error_message                       
--------------------------------------------------------------------
- invalid input syntax for type timestamp with time zone: "garbage"
+                             pg_input_error_message                              
+---------------------------------------------------------------------------------
+ ("invalid input syntax for type timestamp with time zone: ""garbage""",,,22007)
 (1 row)
 
 SELECT pg_input_error_message('2001-01-01 00:00 Nehwon/Lankhmar', 'timestamptz');
-           pg_input_error_message           
---------------------------------------------
- time zone "nehwon/lankhmar" not recognized
+                  pg_input_error_message                  
+----------------------------------------------------------
+ ("time zone ""nehwon/lankhmar"" not recognized",,,22023)
 (1 row)
 
 -- Check date conversion and date arithmetic
diff --git a/src/test/regress/expected/timetz.out b/src/test/regress/expected/timetz.out
index 984285663b..665fa4495c 100644
--- a/src/test/regress/expected/timetz.out
+++ b/src/test/regress/expected/timetz.out
@@ -151,15 +151,15 @@ SELECT pg_input_is_valid('15:36:39 America/New_York', 'timetz');
 (1 row)
 
 SELECT pg_input_error_message('25:00:00 PDT', 'timetz');
-               pg_input_error_message               
-----------------------------------------------------
- date/time field value out of range: "25:00:00 PDT"
+                      pg_input_error_message                      
+------------------------------------------------------------------
+ ("date/time field value out of range: ""25:00:00 PDT""",,,22008)
 (1 row)
 
 SELECT pg_input_error_message('15:36:39 America/New_York', 'timetz');
-                             pg_input_error_message                             
---------------------------------------------------------------------------------
- invalid input syntax for type time with time zone: "15:36:39 America/New_York"
+                                    pg_input_error_message                                    
+----------------------------------------------------------------------------------------------
+ ("invalid input syntax for type time with time zone: ""15:36:39 America/New_York""",,,22007)
 (1 row)
 
 --
diff --git a/src/test/regress/expected/tstypes.out b/src/test/regress/expected/tstypes.out
index a8785cd708..35b19814c4 100644
--- a/src/test/regress/expected/tstypes.out
+++ b/src/test/regress/expected/tstypes.out
@@ -103,9 +103,9 @@ SELECT pg_input_is_valid($$''$$, 'tsvector');
 (1 row)
 
 SELECT pg_input_error_message($$''$$, 'tsvector');
-     pg_input_error_message     
---------------------------------
- syntax error in tsvector: "''"
+            pg_input_error_message            
+----------------------------------------------
+ ("syntax error in tsvector: ""''""",,,42601)
 (1 row)
 
 --Base tsquery test
@@ -405,15 +405,15 @@ SELECT pg_input_is_valid('foo!', 'tsquery');
 (1 row)
 
 SELECT pg_input_error_message('foo!', 'tsquery');
-     pg_input_error_message      
----------------------------------
- syntax error in tsquery: "foo!"
+            pg_input_error_message             
+-----------------------------------------------
+ ("syntax error in tsquery: ""foo!""",,,42601)
 (1 row)
 
 SELECT pg_input_error_message('a <100000> b', 'tsquery');
-                                pg_input_error_message                                 
----------------------------------------------------------------------------------------
- distance in phrase operator must be an integer value between zero and 16384 inclusive
+                                      pg_input_error_message                                       
+---------------------------------------------------------------------------------------------------
+ ("distance in phrase operator must be an integer value between zero and 16384 inclusive",,,22023)
 (1 row)
 
 --comparisons
diff --git a/src/test/regress/expected/uuid.out b/src/test/regress/expected/uuid.out
index 0f47232009..3934626dda 100644
--- a/src/test/regress/expected/uuid.out
+++ b/src/test/regress/expected/uuid.out
@@ -47,9 +47,9 @@ SELECT pg_input_is_valid('11', 'uuid');
 (1 row)
 
 SELECT pg_input_error_message('11', 'uuid');
-          pg_input_error_message          
-------------------------------------------
- invalid input syntax for type uuid: "11"
+                 pg_input_error_message                 
+--------------------------------------------------------
+ ("invalid input syntax for type uuid: ""11""",,,22P02)
 (1 row)
 
 --inserting three input formats
diff --git a/src/test/regress/expected/varchar_1.out b/src/test/regress/expected/varchar_1.out
index 6690f81c0b..ee0e920e84 100644
--- a/src/test/regress/expected/varchar_1.out
+++ b/src/test/regress/expected/varchar_1.out
@@ -125,8 +125,8 @@ SELECT pg_input_is_valid('abcde', 'varchar(4)');
 (1 row)
 
 SELECT pg_input_error_message('abcde', 'varchar(4)');
-            pg_input_error_message            
-----------------------------------------------
- value too long for type character varying(4)
+                  pg_input_error_message                  
+----------------------------------------------------------
+ ("value too long for type character varying(4)",,,22001)
 (1 row)
 
diff --git a/src/test/regress/expected/xid.out b/src/test/regress/expected/xid.out
index e62f701943..754ff6b725 100644
--- a/src/test/regress/expected/xid.out
+++ b/src/test/regress/expected/xid.out
@@ -44,9 +44,9 @@ SELECT pg_input_is_valid('asdf', 'xid');
 (1 row)
 
 SELECT pg_input_error_message('0xffffffffff', 'xid');
-              pg_input_error_message               
----------------------------------------------------
- value "0xffffffffff" is out of range for type xid
+                     pg_input_error_message                      
+-----------------------------------------------------------------
+ ("value ""0xffffffffff"" is out of range for type xid",,,22003)
 (1 row)
 
 SELECT pg_input_is_valid('42', 'xid8');
@@ -62,9 +62,9 @@ SELECT pg_input_is_valid('asdf', 'xid8');
 (1 row)
 
 SELECT pg_input_error_message('0xffffffffffffffffffff', 'xid8');
-                    pg_input_error_message                    
---------------------------------------------------------------
- value "0xffffffffffffffffffff" is out of range for type xid8
+                           pg_input_error_message                           
+----------------------------------------------------------------------------
+ ("value ""0xffffffffffffffffffff"" is out of range for type xid8",,,22003)
 (1 row)
 
 -- equality
@@ -224,9 +224,9 @@ select pg_input_is_valid('31:12:', 'pg_snapshot');
 (1 row)
 
 select pg_input_error_message('31:12:', 'pg_snapshot');
-               pg_input_error_message                
------------------------------------------------------
- invalid input syntax for type pg_snapshot: "31:12:"
+                      pg_input_error_message                       
+-------------------------------------------------------------------
+ ("invalid input syntax for type pg_snapshot: ""31:12:""",,,22P02)
 (1 row)
 
 select pg_input_is_valid('12:16:14,13', 'pg_snapshot');
@@ -236,9 +236,9 @@ select pg_input_is_valid('12:16:14,13', 'pg_snapshot');
 (1 row)
 
 select pg_input_error_message('12:16:14,13', 'pg_snapshot');
-                  pg_input_error_message                  
-----------------------------------------------------------
- invalid input syntax for type pg_snapshot: "12:16:14,13"
+                         pg_input_error_message                         
+------------------------------------------------------------------------
+ ("invalid input syntax for type pg_snapshot: ""12:16:14,13""",,,22P02)
 (1 row)
 
 create temp table snapshot_test (
diff --git a/src/test/regress/expected/xml.out b/src/test/regress/expected/xml.out
index 3c357a9c7e..e1a8f09a42 100644
--- a/src/test/regress/expected/xml.out
+++ b/src/test/regress/expected/xml.out
@@ -32,9 +32,17 @@ SELECT pg_input_is_valid('<value>one</', 'xml');
 (1 row)
 
 SELECT pg_input_error_message('<value>one</', 'xml');
- pg_input_error_message 
-------------------------
- invalid XML content
+                        pg_input_error_message                         
+-----------------------------------------------------------------------
+ ("invalid XML content","line 1: expected '>'                         +
+ <value>one</                                                         +
+             ^                                                        +
+ line 1: Opening and ending tag mismatch: value line 1 and unparseable+
+ <value>one</                                                         +
+             ^                                                        +
+ line 1: chunk is not well balanced                                   +
+ <value>one</                                                         +
+             ^",,2200N)
 (1 row)
 
 SELECT pg_input_is_valid('<?xml version="1.0" standalone="y"?><foo/>', 'xml');
@@ -44,9 +52,9 @@ SELECT pg_input_is_valid('<?xml version="1.0" standalone="y"?><foo/>', 'xml');
 (1 row)
 
 SELECT pg_input_error_message('<?xml version="1.0" standalone="y"?><foo/>', 'xml');
-            pg_input_error_message            
-----------------------------------------------
- invalid XML content: invalid XML declaration
+                                      pg_input_error_message                                      
+--------------------------------------------------------------------------------------------------
+ ("invalid XML content: invalid XML declaration","standalone accepts only 'yes' or 'no'.",,2200N)
 (1 row)
 
 SELECT xmlcomment('test');
-- 
2.25.1

