Skip to content

Commit 3a51306

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. Author: Fabien COELHO <[email protected]> Reviewed-by: "Iwata, Aya" <[email protected]> Reviewed-by: Daniel Verite <[email protected]> Reviewed-by: Peter Eisentraut <[email protected]> Reviewed-by: Kyotaro Horiguchi <[email protected]> Reviewed-by: vignesh C <[email protected]> Discussion: https://www.postgresql.org/message-id/flat/alpine.DEB.2.21.1904132231510.8961@lancre
1 parent 518442c commit 3a51306

File tree

13 files changed

+603
-299
lines changed

13 files changed

+603
-299
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>
@@ -3527,10 +3520,6 @@ select 1\; select 2\; select 3;
35273520
commands included in the string to divide it into multiple
35283521
transactions. (See <xref linkend="protocol-flow-multi-statement"/>
35293522
for more details about how the server handles multi-query strings.)
3530-
<application>psql</application> prints only the last query result
3531-
it receives for each request; in this example, although all
3532-
three <command>SELECT</command>s are indeed executed, <application>psql</application>
3533-
only prints the <literal>3</literal>.
35343523
</para>
35353524
</listitem>
35363525
</varlistentry>
@@ -4117,6 +4106,18 @@ bar
41174106
</varlistentry>
41184107

41194108
<varlistentry>
4109+
<term><varname>SHOW_ALL_RESULTS</varname></term>
4110+
<listitem>
4111+
<para>
4112+
When this variable is set to <literal>off</literal>, only the last
4113+
result of a combined query (<literal>\;</literal>) is shown instead of
4114+
all of them. The default is <literal>on</literal>. The off behavior
4115+
is for compatibility with older versions of psql.
4116+
</para>
4117+
</listitem>
4118+
</varlistentry>
4119+
4120+
<varlistentry>
41204121
<term><varname>SHOW_CONTEXT</varname></term>
41214122
<listitem>
41224123
<para>

0 commit comments

Comments
 (0)