psql:<stdin>:2: fatal: connection to server was lost',
'server crash: error message');
+# test \errverbose
+#
+# (This is not in the regular regression tests because the output
+# contains the source code location and we don't want to have to
+# update that every time it changes.)
+
+psql_like(
+ $node,
+ 'SELECT 1;
+\errverbose',
+ qr/^1\nThere is no previous error\.$/,
+ '\errverbose with no previous error');
+
+# There are three main ways to run a query that might affect
+# \errverbose: The normal way, using a cursor by setting FETCH_COUNT,
+# and using \gdesc. Test them all.
+
+like(($node->psql('postgres', "SELECT error;\n\\errverbose", on_error_stop => 0))[2],
+ qr/\A^psql:<stdin>:1: ERROR: .*$
+^LINE 1: SELECT error;$
+^ *^.*$
+^psql:<stdin>:2: error: ERROR: [0-9A-Z]{5}: .*$
+^LINE 1: SELECT error;$
+^ *^.*$
+^LOCATION: .*$/m,
+ '\errverbose after normal query with error');
+
+like(($node->psql('postgres', "\\set FETCH_COUNT 1\nSELECT error;\n\\errverbose", on_error_stop => 0))[2],
+ qr/\A^psql:<stdin>:2: ERROR: .*$
+^LINE 2: SELECT error;$
+^ *^.*$
+^psql:<stdin>:3: error: ERROR: [0-9A-Z]{5}: .*$
+^LINE 2: SELECT error;$
+^ *^.*$
+^LOCATION: .*$/m,
+ '\errverbose after FETCH_COUNT query with error');
+
+like(($node->psql('postgres', "SELECT error\\gdesc\n\\errverbose", on_error_stop => 0))[2],
+ qr/\A^psql:<stdin>:1: ERROR: .*$
+^LINE 1: SELECT error$
+^ *^.*$
+^psql:<stdin>:2: error: ERROR: [0-9A-Z]{5}: .*$
+^LINE 1: SELECT error$
+^ *^.*$
+^LOCATION: .*$/m,
+ '\errverbose after \gdesc with error');
+
done_testing();