Re: PSQL commands: \quit_if, \quit_unless

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Corey Huinker <corey(dot)huinker(at)gmail(dot)com>
Cc: Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>, PostgreSQL <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: PSQL commands: \quit_if, \quit_unless
Date: 2016-11-28 21:07:42
Message-ID: 27762.1480367262@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Corey Huinker <corey(dot)huinker(at)gmail(dot)com> writes:
> On Mon, Nov 28, 2016 at 2:03 PM, Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr> wrote:
>> I'm wondering if an simplistic interpreted \if \elsif/\else \fi would make
>> more sense:

> The problem is that \if \elsif \else \fi is anything but simplistic, and
> would be a vastly bigger change. Detecting nested if-thens, detecting
> un-matched if-thens, etc.

Yes, but... We've generally refrained from inventing any control flow
metacommands for psql, and TBH this does *not* seem like the place to
start. If we take this patch we are very likely to find that it doesn't
fit in at all whenever someone does show up with a proposal for control
flow features.

If we had an agreed-on sketch for what that feature set would look like,
I wouldn't necessarily object to implementing commands like these first.
But as it stands I think we'd be painting ourselves into a corner.
There's no reason to assume a-priori that this patch creates either naming
conventions or semantics (e.g. what is suitable as a boolean expression)
that we'd be happy with in a larger context.

As far as the original problem goes, I wonder whether what you really
want isn't a \quit command that lets you specify psql's exit code.
I'm not quite seeing how this proposal advances the problem of
communicating between psql and shell portions of a script; but I can
see how returning 0 (ok) vs 1 (error) vs 2 (some special case) would
help with that.

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Petr Jelinek 2016-11-28 21:20:04 Re: Logical Replication WIP
Previous Message Corey Huinker 2016-11-28 20:03:44 Re: PSQL commands: \quit_if, \quit_unless