else
result = PQgetResult(pset.db);
+ /*
+ * Get current timing measure in case an error occurs
+ */
+ if (timing)
+ {
+ INSTR_TIME_SET_CURRENT(after);
+ INSTR_TIME_SUBTRACT(after, before);
+ *elapsed_msec = INSTR_TIME_GET_MILLISEC(after);
+ }
+
continue;
}
else if (svpt_gone_p && !*svpt_gone_p)
last = (next_result == NULL);
/*
- * Get timing measure before printing the last result.
+ * Update current timing measure.
*
* It will include the display of previous results, if any. This
* cannot be helped because the server goes on processing further
* With combined queries, timing must be understood as an upper bound
* of the time spent processing them.
*/
- if (last && timing)
+ if (timing)
{
INSTR_TIME_SET_CURRENT(after);
INSTR_TIME_SUBTRACT(after, before);
'\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