Re: [HACKERS] Undefined psql variables - Mailing list pgsql-hackers
From | Robert Haas |
---|---|
Subject | Re: [HACKERS] Undefined psql variables |
Date | |
Msg-id | CA+TgmoazgHzEkRC_=YPE08t6SW=RUDBV_ORn-hW5L4qnrGEHgg@mail.gmail.com Whole thread Raw |
In response to | [HACKERS] Undefined psql variables (Corey Huinker <corey.huinker@gmail.com>) |
Responses |
Re: [HACKERS] Undefined psql variables
Re: [HACKERS] Undefined psql variables |
List | pgsql-hackers |
On Sun, Apr 2, 2017 at 3:56 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote: > So my view of this is that "send the expression to the server" ought > to be just one option for \if, not the only way to do it. I heartily agree. There should be some kind of client-side expression language, and one thing it should allow is calling out to the server. Then people who only want to call out to the server can do that, but people who want to do something else have the option. Insisting that this facility isn't allowed to do anything other than consult the server is (1) inconsistent with what we've already got in v10 and (2) boxing ourselves into a corner for no very good reason. Now, the optimal shape for that client-side expression language is not very clear to me. Do we want to invent our own language, or maybe consider using something that already exists? It's been previously suggested that we should somehow embed Lua, and this might not be a bad place to consider doing something like that. That might be a way to add a lot of power without having to invent an entirely new programming language one bit at a time. If we want to invent our own expression language, what kind of syntax should it use? Upon what kind of design principles should it be based? There's likely to be vigorous debate on these topics, and probably also complaints that the good designs are too much work and the easy-to-implement designs are too limiting. (Regular readers of this mailing list will likely be able to guess which side of those debates I'll be on, but we need to have them all the same.) Regarding the ostensible topic of this thread, one thought I had while reading through these various responses is that the original need would be well-served by the (somewhat dubious) syntax that bash uses for variable substitution. Obviously, we aren't going to change the interpolate-this-variable character from : to $, but bash has ${parameter:-word} to substitute a default for an unset parameter, ${parameter:=word} to substitute a default for an unset parameter and also set the parameter to that value, ${parameter:?word} to error out with word as the error mesage if parameter is not set, and so forth. If we decide to roll our own, we might consider taking inspiration from those constructs. I think that one of the general problems of language design is, as Larry Wall once said, that a good language should make simple things simple and complex things possible. But simple is not an absolute; it depends on context. The things which a language needs to make simple are those things which will be done frequently *in that language*. So for example in this case, out-calls to SQL need to be very easy to write. Maybe the empty-parameter thing needs to be easy; not sure. Coming up with a good solution here will involve understanding what people typically want to do with a language of this type and then making sure that stuff can be done succinctly - and ideally also making sure that other stuff is also possible if you're willing to put in more legwork. -- Robert Haas EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company
pgsql-hackers by date: