1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-07 19:06:32 +03:00

psql: Set variables from query result on failure when printing tuples

SetResultVariables() was not getting called when "printing" a result
that failed (see around PrintQueryResult), which would cause some
variables to not be set, like ROW_COUNT, SQLSTATE or ERROR.  This can be
confusing as a previous result would be retained.

This state could be reached when failing to process tuples in a few
commands, like \gset when it returns no tuples, or \crosstabview.  A
test is added, based on \gset.

This is arguably a bug fix, but no backpatch is done as there is a risk
of breaking scripts that rely on the previous behavior, even if they do
so accidentally.

Reported-by: amutu
Author: Japin Li
Reviewed-by: Tom Lane, Michael Paquier
Discussion: https://postgr.es/m/18134-87126d90cb4dd049@postgresql.org
This commit is contained in:
Michael Paquier
2023-10-02 11:05:05 +09:00
parent e1f95ec8cf
commit 2940f1c837
3 changed files with 12 additions and 3 deletions

View File

@@ -87,6 +87,10 @@ select 1 as var1, NULL as var2, 3 as var3 \gset
select 10 as test01, 20 as test02 from generate_series(1,3) \gset
select 10 as test01, 20 as test02 from generate_series(1,0) \gset
-- \gset returns no tuples
select a from generate_series(1, 10) as a where a = 11 \gset
\echo :ROW_COUNT
-- \gset should work in FETCH_COUNT mode too
\set FETCH_COUNT 1