Re: \if, \elseif, \else, \endif (was Re: PSQL commands: \quit_if, \quit_unless)

From: Corey Huinker <corey(dot)huinker(at)gmail(dot)com>
To: Erik Rijkers <er(at)xs4all(dot)nl>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>, Daniel Verite <daniel(at)manitou-mail(dot)org>, PostgreSQL <pgsql-hackers(at)postgresql(dot)org>, pgsql-hackers-owner(at)postgresql(dot)org
Subject: Re: \if, \elseif, \else, \endif (was Re: PSQL commands: \quit_if, \quit_unless)
Date: 2017-02-01 13:03:18
Message-ID: CADkLM=e1_=iSxP72MP7WOAgyrFC6emO_7yAJDGeeC4tHkYjfcQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Wed, Feb 1, 2017 at 6:31 AM, Erik Rijkers <er(at)xs4all(dot)nl> wrote:

> On 2017-02-01 09:27, Corey Huinker wrote:
>
>> 0001.if_endif.v4.diff
>>
>
> A few thoughts after a quick try:
>
> I dislike the ease with which one gets stuck inside an \if block, in
> interactive mode.
>
> (for instance, in my very first session, I tried '\? \if' to see if
> there is more info in that help-screen, but it only displays the normal
> help screen. But after that one cannot exit with \q anymore, and there
> is no feedback of any kind (prompt?) in which black hole one has ended up.
> Only a \endif provides rescue.)
>

Good find. I'll have to bulk up the help text.
This raises a question: in interactive mode, should we give some feedback
as to the result of an \if or \elif test? (see below)

>
> Therefore making it possible to break out of \if-mode with Ctrl-C would be
> an improvement, I think.
> I would even prefer it when \q would exit psql always, even from within
> \if-mode.
>

This whole thing got started with a \quit_if <expr> command, and it was
pointed out that

\if :condition
\q
\endif

SELECT ... FROM ...

would be preferable. So I don't think we can do that. At least not in
non-interactive mode.

As for CTRL-C, I've never looked into what psql does with CTRL-C, so I
don't know if it's possible, let alone desirable.

>
> Also, shouldn't the prompt change inside an \if block?
>

That's a good question. I could see us finding ways to print the t/f of
whether a branch is active or not, but I'd like to hear from more people
before diving into something like that.

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Corey Huinker 2017-02-01 13:18:24 Re: \if, \elseif, \else, \endif (was Re: PSQL commands: \quit_if, \quit_unless)
Previous Message Stephen Frost 2017-02-01 13:02:09 Re: Reporting planning time with EXPLAIN