1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-28 23:42:10 +03:00

psql: Update \timing also in case of an error

The changes to show all query results (7844c9918) broke \timing output
in case of an error; it didn't update the timing result and showed
0.000 ms.

Fix by updating the timing result also in the error case.  Also, for
robustness, update the timing result any time a result is obtained,
not only for the last, so a sensible value is always available.

Reported-by: Tom Lane <tgl@sss.pgh.pa.us>
Author: Richard Guo <guofenglinux@gmail.com>
Author: Fabien COELHO <coelho@cri.ensmp.fr>
Discussion: https://www.postgresql.org/message-id/3813350.1652111765%40sss.pgh.pa.us
This commit is contained in:
Peter Eisentraut
2022-05-23 10:07:36 +02:00
parent 6e647ef0e7
commit 9520f8d92a
2 changed files with 22 additions and 4 deletions

View File

@ -85,8 +85,16 @@ psql_like(
'\timing on
SELECT 1',
qr/^1$
^Time: \d+.\d\d\d ms/m,
'\timing');
^Time: \d+\.\d\d\d ms/m,
'\timing with successful query');
# test \timing with query that fails
{
my ($ret, $stdout, $stderr) = $node->psql('postgres', "\\timing on\nSELECT error");
isnt($ret, 0, '\timing with query error: query failed');
like($stdout, qr/^Time: \d+\.\d\d\d ms/m, '\timing with query error: timing output appears');
unlike($stdout, qr/^Time: 0\.000 ms/m, '\timing with query error: timing was updated');
}
# test that ENCODING variable is set and that it is updated when
# client encoding is changed