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=f3_Sf2EHNBFgLWUA-1PRSJ-qVmyVqFuHjXEgLPWjaJtw@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>)
Re: \if, \elseif, \else, \endif (was Re: PSQL commands:\quit_if, \quit_unless)  (Fabien COELHO <coelho@cri.ensmp.fr>)
List pgsql-hackers
On Fri, Mar 17, 2017 at 2:18 PM, Corey Huinker <corey.huinker@gmail.com> wrote:

> \set x 'arg1 arg2'

> \if false
>     \cmd_that_takes_exactly_two_args :x
> \endif

Yeah, throwing errors for bad arguments would also need to be suppressed.

                        regards, tom lane

Ok, barring other feedback, I'm going to take my marching orders as "make each slash command active-aware". To keep that sane, I'm probably going to break out each slash command family into it's own static function.

...and here it is.

v24 highlights:

- finally using git format-patch
- all conditional slash commands broken out into their own functions (exec_command_$NAME) , each one tests if it's in an active branch, and if it's not it consumes the same number of parameters, but discards them. comments for each slash-command family were left as-is, may need to be bulked up.
- TAP tests discarded in favor of one ON_EROR_STOP test for invalid \elif placement
- documentation recommending ON_ERROR_STOP removed, because invalid expressions no longer throw off if-endif balance 
- documentation updated to reflex that contextually-correct-but-invalid boolean expressions are treated as false
- psql_get_variable has a passthrough void pointer now, but I ended up not needing it. Instead, all slash commands in false blocks either fetch OT_NO_EVAL or OT_WHOLE_LINE options. If I'm missing something, let me know.

Attachment

pgsql-hackers by date:

Previous
From: Robert Haas
Date:
Subject: Re: [HACKERS] background sessions
Next
From: Robert Haas
Date:
Subject: Re: [HACKERS] createlang/droplang deprecated