Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 7844c99

Browse files
committed
psql: Show all query results by default
Previously, psql printed only the last result if a command string returned multiple result sets. Now it prints all of them. The previous behavior can be obtained by setting the psql variable SHOW_ALL_RESULTS to off. This is a significantly enhanced version of 3a51306 (that was later reverted). There is also much more test coverage for various psql features now. Author: Fabien COELHO <coelho@cri.ensmp.fr> Reviewed-by: Peter Eisentraut <peter.eisentraut@enterprisedb.com> Reviewed-by: "Iwata, Aya" <iwata.aya@jp.fujitsu.com> (earlier version) Reviewed-by: Daniel Verite <daniel@manitou-mail.org> (earlier version) Reviewed-by: Kyotaro Horiguchi <horikyota.ntt@gmail.com> (earlier version) Reviewed-by: vignesh C <vignesh21@gmail.com> (earlier version) Discussion: https://www.postgresql.org/message-id/flat/alpine.DEB.2.21.1904132231510.8961@lancre
1 parent cbf4177 commit 7844c99

File tree

14 files changed

+801
-255
lines changed

14 files changed

+801
-255
lines changed

contrib/pg_stat_statements/expected/pg_stat_statements.out

+25
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,28 @@ BEGIN \;
5050
SELECT 2.0 AS "float" \;
5151
SELECT 'world' AS "text" \;
5252
COMMIT;
53+
float
54+
-------
55+
2.0
56+
(1 row)
57+
58+
text
59+
-------
60+
world
61+
(1 row)
62+
5363
-- compound with empty statements and spurious leading spacing
5464
\;\; SELECT 3 + 3 \;\;\; SELECT ' ' || ' !' \;\; SELECT 1 + 4 \;;
65+
?column?
66+
----------
67+
6
68+
(1 row)
69+
70+
?column?
71+
----------
72+
!
73+
(1 row)
74+
5575
?column?
5676
----------
5777
5
@@ -61,6 +81,11 @@ COMMIT;
6181
SELECT 1 + 1 + 1 AS "add" \gset
6282
SELECT :add + 1 + 1 AS "add" \;
6383
SELECT :add + 1 + 1 AS "add" \gset
84+
add
85+
-----
86+
5
87+
(1 row)
88+
6489
-- set operator
6590
SELECT 1 AS i UNION SELECT 2 ORDER BY i;
6691
i

doc/src/sgml/ref/psql-ref.sgml

+15-14
Original file line numberDiff line numberDiff line change
@@ -127,18 +127,11 @@ echo '\x \\ SELECT * FROM foo;' | psql
127127
commands included in the string to divide it into multiple
128128
transactions. (See <xref linkend="protocol-flow-multi-statement"/>
129129
for more details about how the server handles multi-query strings.)
130-
Also, <application>psql</application> only prints the
131-
result of the last <acronym>SQL</acronym> command in the string.
132-
This is different from the behavior when the same string is read from
133-
a file or fed to <application>psql</application>'s standard input,
134-
because then <application>psql</application> sends
135-
each <acronym>SQL</acronym> command separately.
136130
</para>
137131
<para>
138-
Because of this behavior, putting more than one SQL command in a
139-
single <option>-c</option> string often has unexpected results.
140-
It's better to use repeated <option>-c</option> commands or feed
141-
multiple commands to <application>psql</application>'s standard input,
132+
If having several commands executed in one transaction is not desired,
133+
use repeated <option>-c</option> commands or feed multiple commands to
134+
<application>psql</application>'s standard input,
142135
either using <application>echo</application> as illustrated above, or
143136
via a shell here-document, for example:
144137
<programlisting>
@@ -3570,10 +3563,6 @@ select 1\; select 2\; select 3;
35703563
commands included in the string to divide it into multiple
35713564
transactions. (See <xref linkend="protocol-flow-multi-statement"/>
35723565
for more details about how the server handles multi-query strings.)
3573-
<application>psql</application> prints only the last query result
3574-
it receives for each request; in this example, although all
3575-
three <command>SELECT</command>s are indeed executed, <application>psql</application>
3576-
only prints the <literal>3</literal>.
35773566
</para>
35783567
</listitem>
35793568
</varlistentry>
@@ -4160,6 +4149,18 @@ bar
41604149
</varlistentry>
41614150

41624151
<varlistentry>
4152+
<term><varname>SHOW_ALL_RESULTS</varname></term>
4153+
<listitem>
4154+
<para>
4155+
When this variable is set to <literal>off</literal>, only the last
4156+
result of a combined query (<literal>\;</literal>) is shown instead of
4157+
all of them. The default is <literal>on</literal>. The off behavior
4158+
is for compatibility with older versions of psql.
4159+
</para>
4160+
</listitem>
4161+
</varlistentry>
4162+
4163+
<varlistentry>
41634164
<term><varname>SHOW_CONTEXT</varname></term>
41644165
<listitem>
41654166
<para>

0 commit comments

Comments
 (0)