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

From Fabien COELHO
Subject Re: \if, \elseif, \else, \endif (was Re: PSQL commands:\quit_if, \quit_unless)
Date
Msg-id alpine.DEB.2.20.1703300843020.2076@lancre
Whole thread Raw
In response to Re: \if, \elseif, \else, \endif (was Re: PSQL commands: \quit_if, \quit_unless)  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: \if, \elseif, \else, \endif (was Re: PSQL commands: \quit_if, \quit_unless)  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
Hello Tom,

>> Patch applies cleanly. Make check ok. Feature still works!

Idem for v30.

> [...] Aside from cosmetic changes, I've made it behave reasonably for 
> cases where \if is used on portions of a query, for instance
>
> SELECT
> \if :something
>    var1
> \else
>    var2
> \endif
> FROM table;

This is commendable, but I would not have bothered, although it is more 
cpp-like with it.

A small issue I see is that I was planning to add such an if syntax to 
pgbench (well, at least if I succeed in getting boolean expressions and 
setting variables, which is just a maybe), but this kind of if in the 
middle of expression does not make much sense for a pgbench script where 
"if" must be evaluated at execution time, not parse time.

> which as I mentioned a long time ago is something that people will
> certainly expect to work.

I would not have expected it to work, but indeed other people could. 
Sometimes I try something with pg and it does not work as I hoped. That is 
life.

> I also cleaned up a lot of corner-case discrepancies between how much 
> text is consumed in active-branch and inactive-branch cases (OT_FILEPIPE 
> is a particularly nasty case in that regard :-()

Indeed.

> I plan to read this over again tomorrow and then push it, if there are
> not objections/corrections.

My small objection is that an eventual if in pgbench, with a separate 
parsing and execution, will not work in the middle of queries as this one. 
Do you think that such a discrepancy would be admissible.

-- 
Fabien.



pgsql-hackers by date:

Previous
From: "Ideriha, Takeshi"
Date:
Subject: Re: [WIP] RE: DECLARE STATEMENT setting up a connectionin ECPG
Next
From: Craig Ringer
Date:
Subject: Re: Logical decoding on standby