Re: \if, \elseif, \else, \endif (was Re: PSQL commands: \quit_if, \quit_unless)
Daniel Verite <daniel@manitou-mail.org>
From: "Daniel Verite" <daniel@manitou-mail.org>
To: "Tom Lane" <tgl@sss.pgh.pa.us>
Cc: "Corey Huinker" <corey.huinker@gmail.com>,"Fabien COELHO"
<coelho@cri.ensmp.fr>,"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>,pgsql-hackers-owner@postgresql.org
Date: 2017-02-23T15:28:43Z
Lists: pgsql-hackers
Tom Lane 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. Are we sold on the idea that conditionals should be implemented by meta-commands, rather than for example terminal symbols of a new grammar on top of the existing? To recall the context, psql variables are really macros that may contain meta-commands, and when they do they're essentially injected and executed at the point of interpolation. That's more or less what started this thread: demo'ing how we could exit conditionally by injecting '\q' or nothing into a variable, and saying that even if doable it was pretty weird, and it would be better to have real conditional structures instead. But when conditional structures are implemented as meta-commands, there's the problem that this structure can be generated on the fly too, which in a way is no less weird. While I think that the introduction of conditionals in psql is great, I'm getting doubtful about that part. Are there popular script languages or preprocessors that accept variables/macros instead of symbols to structure the flow of instructions? I can't think of any myself. Best regards, -- Daniel Vérité PostgreSQL-powered mailer: http://www.manitou-mail.org Twitter: @DanielVerite
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