Re: psql -f and PAGER - Mailing list pgsql-general

From Peter J. Holzer
Subject Re: psql -f and PAGER
Date
Msg-id 20220330065752.rykgxuzjdzbms5gw@hjp.at
Whole thread Raw
In response to Re: psql -f and PAGER  ("David G. Johnston" <david.g.johnston@gmail.com>)
List pgsql-general
On 2022-03-29 19:08:44 -0700, David G. Johnston wrote:
> On Tue, Mar 29, 2022 at 6:30 PM Paul Jungwirth <pj@illuminatedcomputing.com>
> wrote:
>
>     I noticed that this runs your pager:
>
>          psql -f <(echo 'select * from pg_class;')
>
>     but not this:
>
>          echo 'select * from pg_class;' | psql
[...]
>
> For both examples:
> pager defaults to on
> the output of the psql session is a terminal
> the full contents of pg_class are not going to fit on one terminal screen
> ergo, the output of select * from pg_class; should be piped to the pager in
> both cases

This is incomplete in the docs. The pager is also not called if stdin is
not a terminal (which makes sense - you couldn't control the pager).

So
    echo 'select * from pg_class;' | psql
doesn't call the pager. Neither do:
    psql -f <(echo 'select * from pg_class;') < /dev/null
    psql -f <(echo 'select * from pg_class;') > /dev/null

But
    psql -f <(echo 'select * from pg_class;')
does, since both stdin and stdout are a terminal.

        hp

--
   _  | Peter J. Holzer    | Story must make more sense than reality.
|_|_) |                    |
| |   | hjp@hjp.at         |    -- Charles Stross, "Creative writing
__/   | http://www.hjp.at/ |       challenge!"

Attachment

pgsql-general by date:

Previous
From: Sai Ch
Date:
Subject: Reg: User creation script/List of privileges
Next
From: Tomas Pospisek
Date:
Subject: Re: Reg: User creation script/List of privileges