summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/src/sgml/ref/psql-ref.sgml31
-rw-r--r--src/bin/psql/command.c14
2 files changed, 26 insertions, 19 deletions
diff --git a/doc/src/sgml/ref/psql-ref.sgml b/doc/src/sgml/ref/psql-ref.sgml
index dc422373d6..de760f9990 100644
--- a/doc/src/sgml/ref/psql-ref.sgml
+++ b/doc/src/sgml/ref/psql-ref.sgml
@@ -3120,8 +3120,21 @@ lo_import 152801
<listitem>
<para>
Controls use of a pager program for query and <application>psql</application>
- help output. If the environment variable <envar>PSQL_PAGER</envar>
- or <envar>PAGER</envar> is set, the output is piped to the
+ help output.
+ When the <literal>pager</literal> option is <literal>off</literal>, the pager
+ program is not used. When the <literal>pager</literal> option is
+ <literal>on</literal>, the pager is used when appropriate, i.e., when the
+ output is to a terminal and will not fit on the screen.
+ The <literal>pager</literal> option can also be set to <literal>always</literal>,
+ which causes the pager to be used for all terminal output regardless
+ of whether it fits on the screen. <literal>\pset pager</literal>
+ without a <replaceable class="parameter">value</replaceable>
+ toggles pager use on and off.
+ </para>
+
+ <para>
+ If the environment variable <envar>PSQL_PAGER</envar>
+ or <envar>PAGER</envar> is set, output to be paged is piped to the
specified program. Otherwise a platform-dependent default program
(such as <filename>more</filename>) is used.
</para>
@@ -3135,18 +3148,6 @@ lo_import 152801
<application>psql</application>'s output format (such as
<filename>pspg --stream</filename>).
</para>
-
- <para>
- When the <literal>pager</literal> option is <literal>off</literal>, the pager
- program is not used. When the <literal>pager</literal> option is
- <literal>on</literal>, the pager is used when appropriate, i.e., when the
- output is to a terminal and will not fit on the screen.
- The <literal>pager</literal> option can also be set to <literal>always</literal>,
- which causes the pager to be used for all terminal output regardless
- of whether it fits on the screen. <literal>\pset pager</literal>
- without a <replaceable class="parameter">value</replaceable>
- toggles pager use on and off.
- </para>
</listitem>
</varlistentry>
@@ -4898,7 +4899,7 @@ PSQL_EDITOR_LINENUMBER_ARG='--line '
pager-related options of the <command>\pset</command> command.
These variables are examined in the order listed;
the first that is set is used.
- If none of them is set, the default is to use <literal>more</literal> on most
+ If neither of them is set, the default is to use <literal>more</literal> on most
platforms, but <literal>less</literal> on Cygwin.
</para>
diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c
index 97f7d97220..607a57715a 100644
--- a/src/bin/psql/command.c
+++ b/src/bin/psql/command.c
@@ -5197,14 +5197,20 @@ do_watch(PQExpBuffer query_buf, double sleep, int iter)
/*
* For \watch, we ignore the size of the result and always use the pager
- * if PSQL_WATCH_PAGER is set. We also ignore the regular PSQL_PAGER or
- * PAGER environment variables, because traditional pagers probably won't
- * be very useful for showing a stream of results.
+ * as long as we're talking to a terminal and "\pset pager" is enabled.
+ * However, we'll only use the pager identified by PSQL_WATCH_PAGER. We
+ * ignore the regular PSQL_PAGER or PAGER environment variables, because
+ * traditional pagers probably won't be very useful for showing a stream
+ * of results.
*/
#ifndef WIN32
pagerprog = getenv("PSQL_WATCH_PAGER");
+ /* if variable is empty or all-white-space, don't use pager */
+ if (pagerprog && strspn(pagerprog, " \t\r\n") == strlen(pagerprog))
+ pagerprog = NULL;
#endif
- if (pagerprog && myopt.topt.pager)
+ if (pagerprog && myopt.topt.pager &&
+ isatty(fileno(stdin)) && isatty(fileno(stdout)))
{
fflush(NULL);
disable_sigpipe_trap();