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

Commit b7d254c

Browse files
committed
Fix documentation of psql's ECHO all mode.
"ECHO all" is ignored for interactive input, and has been for a very long time, though possibly not for as long as the documentation has claimed the opposite. Fix that, and also note that empty lines aren't echoed, which while dubious is another longstanding behavior (it's embedded in our regression test files for one thing). Per bug #12721 from Hans Ginzel. In HEAD, also improve the code comments in this area, and suppress an unnecessary fflush(stdout) when we're not echoing. That would likely be safe to back-patch, but I'll not risk it mere hours before a release wrap.
1 parent 77e9125 commit b7d254c

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

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

+8-8
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ PostgreSQL documentation
5353
<term><option>--echo-all</></term>
5454
<listitem>
5555
<para>
56-
Print all input lines to standard output as they are read. This is more
57-
useful for script processing than interactive mode. This is
56+
Print all nonempty input lines to standard output as they are read.
57+
(This does not apply to lines read interactively.) This is
5858
equivalent to setting the variable <varname>ECHO</varname> to
5959
<literal>all</literal>.
6060
</para>
@@ -2863,14 +2863,14 @@ bar
28632863
<term><varname>ECHO</varname></term>
28642864
<listitem>
28652865
<para>
2866-
If set to <literal>all</literal>, all lines
2867-
entered from the keyboard or from a script are written to the standard output
2868-
before they are parsed or executed. To select this behavior on program
2866+
If set to <literal>all</literal>, all nonempty input lines are printed
2867+
to standard output as they are read. (This does not apply to lines
2868+
read interactively.) To select this behavior on program
28692869
start-up, use the switch <option>-a</option>. If set to
28702870
<literal>queries</literal>,
2871-
<application>psql</application> merely prints all queries as
2872-
they are sent to the server. The switch for this is
2873-
<option>-e</option>. If set to <literal>errors</literal> then only
2871+
<application>psql</application> prints each query to standard output
2872+
as it is sent to the server. The switch for this is
2873+
<option>-e</option>. If set to <literal>errors</literal>, then only
28742874
failed queries are displayed on standard error output. The switch
28752875
for this is <option>-b</option>. If unset, or if set to
28762876
<literal>none</literal> (or any other value than those above) then

src/bin/psql/mainloop.c

+5-3
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ MainLoop(FILE *source)
187187
break;
188188
}
189189

190-
/* nothing left on line? then ignore */
190+
/* no further processing of empty lines, unless within a literal */
191191
if (line[0] == '\0' && !psql_scan_in_quote(scan_state))
192192
{
193193
free(line);
@@ -211,10 +211,12 @@ MainLoop(FILE *source)
211211
continue;
212212
}
213213

214-
/* echo back if flag is set */
214+
/* echo back if flag is set, unless interactive */
215215
if (pset.echo == PSQL_ECHO_ALL && !pset.cur_cmd_interactive)
216+
{
216217
puts(line);
217-
fflush(stdout);
218+
fflush(stdout);
219+
}
218220

219221
/* insert newlines into query buffer between source lines */
220222
if (query_buf->len > 0)

0 commit comments

Comments
 (0)