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

From Corey Huinker
Subject Re: \if, \elseif, \else, \endif (was Re: [HACKERS] PSQL commands:\quit_if, \quit_unless)
Date
Msg-id CADkLM=dXgQTRDsyjCUZCh9LGKbNAnxM2weVq9uO4E7LfJg5P2Q@mail.gmail.com
Whole thread Raw
In response to Re: \if, \elseif, \else, \endif (was Re: [HACKERS] PSQL commands:\quit_if, \quit_unless)  (Fabien COELHO <coelho@cri.ensmp.fr>)
Responses Re: \if, \elseif, \else, \endif (was Re: [HACKERS] PSQL commands:\quit_if, \quit_unless)
List pgsql-hackers
Shouldn't there be some documentation changes to reflect the behavior on errors? A precise paragraph about that would be welcome, IMHO.

Oddly enough, the documentation I wrote hadn't addressed invalid booleans, only the error messages did that.

The new behavior certainly warrants a mention, and I'll add that.
 
Given that there is no more barking, then having some prompt indication that the code is inside a conditional branch becomes more important, so ISTM that there should be some plan to add it.

Yeah, prompting just got more important. I see a few ways to go about this:

1. Add a new prompt type, either %T for true (heh, pun) or %Y for branching. It would print a string of chained 't' (branch is true), 'f' (branch is false), 'z' (branch already had its true section). The depth traversal would have a limit, say 3 levels deep, and if the tree goes more than that deep, then '...' would be printed in the stead of any deeper values. So the prompt would change through a  session like: 

command       prompt is now
-----------   ---------------------------------------
\echo bob     ''   = initial state, no branch going on at all
\if yes       't' = inside a true branch
\if no        'tf' = false inside a true
\endif        't' = back to just the true branch
\if yes       'tt'
\if yes       'ttt'
\if yes       '...ttt' = only show the last 3, but let it be known that there's at least one more'
\else         '...ttz' = past the point of a true bit of this branch

2. The printing of #1 could be integrated into %R only in PROMPT_READY cases, either prepended or appended to the !/=/^, possibly separated by a :
3. Like #2, but prepended/appended in all circumstances
4. Keep %T (or %Y), and reflect the state of pset.active_branch within %R, a single t/f/z
5. Like #4, but also printing the if-stack depth if > 1 

pgsql-hackers by date:

Previous
From: Andres Freund
Date:
Subject: Re: [HACKERS] WIP: About CMake v2
Next
From: Masahiko Sawada
Date:
Subject: Re: [HACKERS] DROP SUBSCRIPTION and ROLLBACK