Re: psql -1 -f - busted

From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Peter Eisentraut <peter_e(at)gmx(dot)net>, Stephen Frost <sfrost(at)snowman(dot)net>, pgsql-bugs(at)postgresql(dot)org
Subject: Re: psql -1 -f - busted
Date: 2009-11-30 13:59:13
Message-ID: 200911301359.nAUDxDj19992@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Robert Haas wrote:
> On Fri, Nov 27, 2009 at 1:42 AM, Peter Eisentraut <peter_e(at)gmx(dot)net> wrote:
> > On tor, 2009-11-26 at 22:59 -0500, Robert Haas wrote:
> >> ISTM that if you run psql with "-f -", you shouldn't expect to get an
> >> interactive shell. ?Rather, you should expect psql to do whatever it
> >> normally does when given -f somefilename, except using stdin rather
> >> than the file. ?After all, you could have left out -f altogether if
> >> you'd wanted the interactive behavior. ?But then IJWH.
> >
> > But by that logic, psql < file should also set interactive mode.
>
> Those two cases are not symmetrical. If you're reading from something
> other than a terminal, you certainly don't want interactive mode. If
> you ARE reading from a terminal, you might nevertheless want
> non-interactive mode. And you CERTAINLY might want -1 when reading a
> pipe, as when you do this:
>
> ssh otherhost pg_dump | psql -1 -f -
>
> Currently, this silently fails to deliver the expected behavior.

You are right --- there is definitely something wrong with that code. I
tried to find out why it was coded that way but that code hasn't changed
since 2000 or 2001. My guess is that is was OK then, but when we added
"-1" we didn't think about its placement.

I think the proper, consistent fix is to check for "-" inside
process_file(), rather than earlier. The attached patch accomplishes
this. The code still goes into interactive mode, though:

$ psql -f - test
test=>

Should that prompt not appear? Seems OK to me.

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +

Attachment Content-Type Size
/pgpatches/psql-f text/x-diff 1.4 KB

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message jef peeraer 2009-11-30 14:36:29 BUG #5220: regexp fails on punctuation characters
Previous Message Kenaniah Cerny 2009-11-29 22:41:20 Re: BUG #5219: Segfault in to_tsvector