Re: psql -f and PAGER

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: Paul Jungwirth <pj(at)illuminatedcomputing(dot)com>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: psql -f and PAGER
Date: 2022-03-30 02:08:44
Message-ID: CAKFQuwaAB4S=ACPK+Ghairm50S2__eDy2DQDhwzrkjKfKqOujg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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
>
> Indeed running the pager for -f but not stdin seems opposite of the last
> line of these docs (https://www.postgresql.org/docs/14/app-psql.html)
>
> On the other hand, the variant using the shell's input redirection is
> (in theory) guaranteed to yield exactly the same output you would have
> received had you entered everything by hand.
>
> Does it seem wrong to anyone else to run the pager from -f? Is it
> something the community would accept patches to change?
>
>
If anything the behavior of the echo is contrary to the documentation
(though I get your point about "yield exactly the same output").

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

I'd be on board with having the documentation better match reality (if we
can figure out why echo-pipe is different and it's something we control)
but I'm against changing the longstanding behavior to an only subjectively
different one.

Seems like both setting pager to off and ON_ERROR_STOP to on should be the
first things people do in their psql non-interactive automations (or run
them through the "tee" command...). It would be nice to not have to change
the pager but I also don't see messing with the default.

David J.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Sai Ch 2022-03-30 03:09:18 Reg: User creation script/List of privileges
Previous Message Paul Jungwirth 2022-03-30 01:30:46 psql -f and PAGER