Fix documentation of psql's ECHO all mode.
authorTom Lane <tgl@sss.pgh.pa.us>
Sat, 31 Jan 2015 23:35:13 +0000 (18:35 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Sat, 31 Jan 2015 23:35:13 +0000 (18:35 -0500)
"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.

doc/src/sgml/ref/psql-ref.sgml
src/bin/psql/mainloop.c

index bdfb67cd9a12862d1497ef839199e252551ea4f9..b92a1ea02b34dd1d6e6c417aa530b8c876621bfa 100644 (file)
@@ -53,8 +53,8 @@ PostgreSQL documentation
       <term><option>--echo-all</></term>
       <listitem>
       <para>
-      Print all input lines to standard output as they are read. This is more
-      useful for script processing than interactive mode. This is
+      Print all nonempty input lines to standard output as they are read.
+      (This does not apply to lines read interactively.) This is
       equivalent to setting the variable <varname>ECHO</varname> to
       <literal>all</literal>.
       </para>
@@ -2863,14 +2863,14 @@ bar
         <term><varname>ECHO</varname></term>
         <listitem>
         <para>
-        If set to <literal>all</literal>, all lines
-        entered from the keyboard or from a script are written to the standard output
-        before they are parsed or executed. To select this behavior on program
+        If set to <literal>all</literal>, all nonempty input lines are printed
+        to standard output as they are read.  (This does not apply to lines
+        read interactively.)  To select this behavior on program
         start-up, use the switch <option>-a</option>. If set to
         <literal>queries</literal>,
-        <application>psql</application> merely prints all queries as
-        they are sent to the server. The switch for this is
-        <option>-e</option>. If set to <literal>errors</literal> then only
+        <application>psql</application> prints each query to standard output
+        as it is sent to the server. The switch for this is
+        <option>-e</option>. If set to <literal>errors</literal>, then only
         failed queries are displayed on standard error output. The switch
         for this is <option>-b</option>. If unset, or if set to
         <literal>none</literal> (or any other value than those above) then
index d2267640abe5c43cf7ceaedec57e186d5981e951..b6cef94272c1646f367bd114c4b6c4e00f5352a4 100644 (file)
@@ -187,7 +187,7 @@ MainLoop(FILE *source)
            break;
        }
 
-       /* nothing left on line? then ignore */
+       /* no further processing of empty lines, unless within a literal */
        if (line[0] == '\0' && !psql_scan_in_quote(scan_state))
        {
            free(line);
@@ -211,10 +211,12 @@ MainLoop(FILE *source)
            continue;
        }
 
-       /* echo back if flag is set */
+       /* echo back if flag is set, unless interactive */
        if (pset.echo == PSQL_ECHO_ALL && !pset.cur_cmd_interactive)
+       {
            puts(line);
-       fflush(stdout);
+           fflush(stdout);
+       }
 
        /* insert newlines into query buffer between source lines */
        if (query_buf->len > 0)