psql -f and PAGER

From: Paul Jungwirth <pj(at)illuminatedcomputing(dot)com>
To: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: psql -f and PAGER
Date: 2022-03-30 01:30:46
Message-ID: db80016d-d0b6-a721-611b-21292a895af5@illuminatedcomputing.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello,

I noticed that this runs your pager:

psql -f <(echo 'select * from pg_class;')

but not this:

echo 'select * from pg_class;' | psql

A client encountered this when the psql command run from their deb's
.postinst file started to hang.

We can prevent it with PSQL_PAGER='', but it almost seems like a bug to
me, since I expect -f to be for non-interactive use. I'd at least call
it a footgun.

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)

> Using this option is subtly different from writing psql < filename.
In general, both will do what you expect, but using -f enables some nice
features such as error messages with line numbers. There is also a
slight chance that using this option will reduce the start-up overhead.
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?

Yours,

--
Paul ~{:-)
pj(at)illuminatedcomputing(dot)com

Responses

Browse pgsql-general by date

  From Date Subject
Next Message David G. Johnston 2022-03-30 02:08:44 Re: psql -f and PAGER
Previous Message Philip Semanchuk 2022-03-29 18:43:27 Re: Why is my function inlined only when STABLE?