Re: \if, \elseif, \else, \endif (was Re: PSQL commands: \quit_if, \quit_unless)
Fabien COELHO <coelho@cri.ensmp.fr>
From: Fabien COELHO <coelho@cri.ensmp.fr>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Corey Huinker <corey.huinker@gmail.com>,
Daniel Verite <daniel@manitou-mail.org>,
"David G. Johnston" <david.g.johnston@gmail.com>,
Greg Stark <stark@mit.edu>, Erik Rijkers <er@xs4all.nl>,
Robert Haas <robertmhaas@gmail.com>,
Jim Nasby <Jim.Nasby@bluetreble.com>,
PostgreSQL <pgsql-hackers@postgresql.org>
Date: 2017-03-30T07:20:39Z
Lists: 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.
Commits
-
Support \if ... \elif ... \else ... \endif in psql scripting.
- e984ef5861df 10.0 landed
-
Add a "void *" passthrough pointer for psqlscan.l's callback functions.
- 895e36bb3f36 10.0 landed