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)

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..."
    calvin=(t)>  \else
    calvin=(f)>   whatever
    calvin=(f)>  \endif

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

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>

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.


Sent via pgsql-hackers mailing list (
To make changes to your subscription:

Reply via email to