Re: \prompt for psql - Mailing list pgsql-patches

From Tom Lane
Subject Re: \prompt for psql
Date
Msg-id 20367.1171735163@sss.pgh.pa.us
Whole thread Raw
In response to Re: \prompt for psql  ("Chad Wagner" <chad.wagner@gmail.com>)
Responses Re: \prompt for psql
List pgsql-patches
"Chad Wagner" <chad.wagner@gmail.com> writes:
> Would it make sense to say:
> 1. if pset.notty is set and '-f' switch is not set then use simple_prompt
> 2. else then use gets_fromFile(stdin) <or some other alternative?>

Actually, there's another issue, which is where to send the prompt.
If we're using /dev/tty the answer is clear, but if we're proposing to
read from stdin then it's not necessarily the case that stdout (or even
stderr) is appropriate.

Arguably a prompt is useless except to a human user, so maybe the rule
is "if stdin is a tty according to pset.notty, then prompt to /dev/tty;
otherwise suppress the prompt altogether".  Or we could prompt to stderr
instead of /dev/tty in this case.  I'm not sure if there are plausible
use-cases where stdin leads to the terminal and stderr doesn't.

Surely there are precedents for this sort of thing in existing programs;
can anyone point to any programs that seem to get it right (or wrong)?

            regards, tom lane

pgsql-patches by date:

Previous
From: Peter Eisentraut
Date:
Subject: Re: patch adding new regexp functions
Next
From: "Chad Wagner"
Date:
Subject: Re: \prompt for psql