Re: psql -f and PAGER

From: "Peter J(dot) Holzer" <hjp-pgsql(at)hjp(dot)at>
To: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: psql -f and PAGER
Date: 2022-03-30 06:57:52
Message-ID: 20220330065752.rykgxuzjdzbms5gw@hjp.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)illuminatedcomputing(dot)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(at)hjp(dot)at | -- Charles Stross, "Creative writing
__/ | http://www.hjp.at/ | challenge!"

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tomas Pospisek 2022-03-30 16:19:59 Re: Reg: User creation script/List of privileges
Previous Message Sai Ch 2022-03-30 03:09:18 Reg: User creation script/List of privileges