From: | Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr> |
---|---|
To: | Corey Huinker <corey(dot)huinker(at)gmail(dot)com> |
Cc: | Erik Rijkers <er(at)xs4all(dot)nl>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, 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:25:20 |
Message-ID: | alpine.DEB.2.20.1702011407221.31128@lancre |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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.
From | Date | Subject | |
---|---|---|---|
Next Message | REIX, Tony | 2017-02-01 13:29:33 | Re: Deadlock in XLogInsert at AIX |
Previous Message | Amit Kapila | 2017-02-01 13:20:29 | Re: Parallel Index Scans |