Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2940f1c

Browse files
committed
psql: Set variables from query result on failure when printing tuples
SetResultVariables() was not getting called when "printing" a resultthat failed (see around PrintQueryResult), which would cause somevariables to not be set, like ROW_COUNT, SQLSTATE or ERROR. This can beconfusing as a previous result would be retained.This state could be reached when failing to process tuples in a fewcommands, like \gset when it returns no tuples, or \crosstabview. Atest is added, based on \gset.This is arguably a bug fix, but no backpatch is done as there is a riskof breaking scripts that rely on the previous behavior, even if they doso accidentally.Reported-by: amutuAuthor: Japin LiReviewed-by: Tom Lane, Michael PaquierDiscussion:https://postgr.es/m/18134-87126d90cb4dd049@postgresql.org
1 parente1f95ec commit2940f1c

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

‎src/bin/psql/common.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1659,9 +1659,9 @@ ExecQueryAndProcessResults(const char *query,
16591659
tuples_fout,printQueryFout);
16601660
}
16611661

1662-
/* set variableson last result if all went well */
1663-
if (!is_watch&&last&&success)
1664-
SetResultVariables(result,true);
1662+
/* set variablesfrom last result */
1663+
if (!is_watch&&last)
1664+
SetResultVariables(result,success);
16651665

16661666
ClearOrSaveResult(result);
16671667
result=next_result;

‎src/test/regress/expected/psql.out

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,11 @@ select 10 as test01, 20 as test02 from generate_series(1,3) \gset
171171
more than one row returned for \gset
172172
select 10 as test01, 20 as test02 from generate_series(1,0) \gset
173173
no rows returned for \gset
174+
-- \gset returns no tuples
175+
select a from generate_series(1, 10) as a where a = 11 \gset
176+
no rows returned for \gset
177+
\echo :ROW_COUNT
178+
0
174179
-- \gset should work in FETCH_COUNT mode too
175180
\set FETCH_COUNT 1
176181
select 1 as x, 2 as y \gset pref01_ \\ \echo :pref01_x

‎src/test/regress/sql/psql.sql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ select 1 as var1, NULL as var2, 3 as var3 \gset
8787
select10as test01,20as test02from generate_series(1,3) \gset
8888
select10as test01,20as test02from generate_series(1,0) \gset
8989

90+
-- \gset returns no tuples
91+
select afrom generate_series(1,10)as awhere a=11 \gset
92+
\echo :ROW_COUNT
93+
9094
-- \gset should work in FETCH_COUNT mode too
9195
\set FETCH_COUNT1
9296

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp