Re: \if, \elseif, \else, \endif (was Re: [HACKERS] PSQL commands:\quit_if, \quit_unless) - Mailing list pgsql-hackers

From Fabien COELHO
Subject Re: \if, \elseif, \else, \endif (was Re: [HACKERS] PSQL commands:\quit_if, \quit_unless)
Date
Msg-id alpine.DEB.2.20.1702011407221.31128@lancre
Whole thread Raw
In response to Re: \if, \elseif, \else, \endif (was Re: [HACKERS] PSQL commands:\quit_if, \quit_unless)  (Corey Huinker <corey.huinker@gmail.com>)
Responses Re: \if, \elseif, \else, \endif (was Re: [HACKERS] PSQL commands:\quit_if, \quit_unless)
List pgsql-hackers
> Good find. I'll have to bulk up the help text.

Yes.

> This raises a question: in interactive mode, should we give some feedback
> as to the result of an \if or \elif test? (see below)

Obviously \if makes more sense for scripting.

However I would say yes, it should provide some feedback... This means 
probably adding a new prompt substitution "%<something>". In the worst 
case, the prompt should reflect the current stack, or at least the top of 
the task...

Maybe use "%?" which could be substituted by:
    empty stack   -> ""    ignore state  -> "." or "(i)"    *_true state  -> "t" or "(t)"    *_false state -> "f" or
"(f)"
    calvin=>   \if true    calvin=(t)>  \echo "running..."      running...    calvin=(t)>  \else    calvin=(f)>
whatever   calvin=(f)>  \endif    calvin=>
 


>> 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.
> So I don't think we can do that. At least not in non-interactive mode.

Yep.

> 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.

I think that ctrl-c should abandon current command, which is what the user 
expect when things go wrong. I would suggest to pop the stack on ctrl-C on 
an empty input, eg:
  calvin=> \if true  calvin=(t)> SELECT  calvin-(t)>   <ctrl-C>  calvin=(t)> <ctrl-C>  calvin=>

>> 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.

See above.

Adding a state indicator is probably ok, the key question is whether the 
default prompt is changed.

-- 
Fabien.



pgsql-hackers by date:

Previous
From: Amit Kapila
Date:
Subject: Re: [HACKERS] Parallel Index Scans
Next
From: "REIX, Tony"
Date:
Subject: Re: [HACKERS] Deadlock in XLogInsert at AIX