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

From Corey Huinker
Subject Re: [HACKERS] \if, \elseif, \else, \endif (was Re: PSQL commands:\quit_if, \quit_unless)
Date
Msg-id CADkLM=d3dYe-Uma-0Z+3F7ERDYC+_CFFmamAA8nHP5KSoEaD7g@mail.gmail.com
Whole thread Raw
In response to Re: [HACKERS] \if, \elseif, \else, \endif (was Re: PSQL commands:\quit_if, \quit_unless)  (Corey Huinker <corey.huinker@gmail.com>)
Responses Re: [HACKERS] \if, \elseif, \else, \endif (was Re: PSQL commands:\quit_if, \quit_unless)  (Fabien COELHO <coelho@cri.ensmp.fr>)
List pgsql-hackers
On Wed, Feb 22, 2017 at 6:15 PM, Corey Huinker <corey.huinker@gmail.com> wrote:
On Wed, Feb 22, 2017 at 5:59 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
Ah, I see why *that* wants to know about it ... I think.  I suppose you're
arguing that variable expansion shouldn't be able to insert, say, an \else
in a non-active branch?  Maybe, but if it can insert an \else in an active
branch, then why not non-active too?  Seems a bit inconsistent.

The major reason was avoiding situations like what Daniel showed: where value of a variable that is meaningless/undefined in the current false-block context gets expanded anyway, and thus code inside a false block has effects outside of that block. Granted, his example was contrived. I'm open to removing that feature and seeing what breaks in the test cases.


Welcome to v15, highlights:
- all conditional data structure management moved to conditional.h and conditional.c
- conditional state lives in mainloop.c and is passed to HandleSlashCommands, exec_command and get_prompt as needed
- no more pset.active_branch, uses conditional_active(conditional_stack) instead
- PsqlScanState no longer has branching state
- Implements the %R '@' prompt on false branches.
- Variable expansion is never suppressed even in false blocks, regression test edited to reflect this.
- ConditionalStack could morph into PsqlFileState without too much work.
Attachment

pgsql-hackers by date:

Previous
From: Amit Langote
Date:
Subject: Re: [HACKERS] tablesample with partitioned tables
Next
From: Amit Langote
Date:
Subject: Re: [HACKERS] Partitioned tables and relfilenode