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: Corey Huinker <corey.huinker@gmail.com>
Cc: Tom Lane <tgl@sss.pgh.pa.us>, Greg Stark <stark@mit.edu>,
Erik Rijkers <er@xs4all.nl>, Robert Haas <robertmhaas@gmail.com>,
Daniel Verite <daniel@manitou-mail.org>,
Jim Nasby <Jim.Nasby@bluetreble.com>,
PostgreSQL <pgsql-hackers@postgresql.org>,
pgsql-hackers-owner@postgresql.org
Date: 2017-02-24T06:53:04Z
Lists: pgsql-hackers
About v17:
Patch applies, "make check" & psql "make check" ok.
>> ... '@' [...] I noticed that it takes precedence over '!'. [...]
>
> My reasoning was this: if you're in a false block, and you're not connected
> to a db, the \c isn't going to work for you until you get out of the false
> block, so right now being in a false block is a bigger problem than not
> being connected to a db. [...]
Ok.
>> It could be nice to keep test cases that show what may happen?
>
> Restored. It looks weird now, but it fixes the unterminated quoted
> string.
Typo "unterminted".
I think I found an issue while testing in interactive:
calvin=# \if false
calvin@# \if false
calvin@# \echo false-false
command ignored, use \endif or Ctrl-C to exit current branch.
calvin@# \endif
calvin=# \echo in false
in false
The \if within the \if false branch is not tallied properly? Am I missing
something?
Maybe more test cases should be added to check that nesting checks do work
properly?
>> Maybe the documentation could add some kind of warning about that?
>
> I changed the paragraph to
> Lines within false branches are parsed normally, however, any completed
> queries are not sent to the server, and any completed commands other
> than conditionals (<command>\if</command>, <command>\elif</command>,
> <command>\else</command>, <command>\endif</command>) are ignored.
I'm not sure about the ", however, " commas, but I'm sure that I do not
know English punctuation rules:-)
Maybe the sentence could be cut in shorter pieces.
I think that the fact that "if" commands are checked for proper nesting
could be kept in the explanation.
> There's no mention that psql variables AREN'T expanded, so the user has
> every expectation that they are.
Ok.
--
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