Re: Variable substitution in psql backtick expansion

From: Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Corey Huinker <corey(dot)huinker(at)gmail(dot)com>, Greg Stark <stark(at)mit(dot)edu>, Daniel Verite <daniel(at)manitou-mail(dot)org>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, PostgreSQL Developers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Variable substitution in psql backtick expansion
Date: 2017-04-17 08:58:07
Message-ID: alpine.DEB.2.20.1704171734150.4025@lancre
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers


> I don't think so :?xxx is good idea, because for me :xxx is related to
> content, not to metadata

Hmmm. Indeed it is not. I do not see it as an issue, but it is a good
point.

Consider perl "defined $x" or "exists $f{k}". $x/$f{k} should be contents,
but it is not, the dereferencing is suspended by "defined/exists" Yuk,
but simple and effective.

Also with CPP: "#define x 1, #ifdef x", somehow "x" should be the value,
not the name, but yet again it is not dereferenced.

Now consider python: "if 'varname' in locals():" at least it is
consistent, but I cannot say it looks better in the end:-)

So playing around with a value vs metadata is a frequent trick to keep the
syntax simple, even if the logic is not all there as you point out.

> and Robert's tip of using bash syntax is more logical for me (to have
> syntax for default and custom message).

There is no way to simply test for definition in bash, which is exactly
what is needed...

A second issue with sh-like proposal is that it needs a boundary thing,
i.e. bash uses braces ${name<operator>value}. If it was the beginning of
psql I would suggest to consider ${name} stuff, but now I'm not sure that
such a thing can be introduced like ":{xxx}" ? Maybe that can be done.

However it does not change the issue that sh does not allow to test
whether a variable is defined, which is the thought for feature. Providing
a default value or erroring out is not the same thing.

Another question to address: how do you handle ' and " escaping? Pg
:'name' and :"name" solutions are somewhat horrible, but they are there
which show that it was needed. I'm not sure how to translate that with
braces in pg. Maybe :{'name'} and :{"name"}? Hmmm...
Or ":{name}", but then what happens if I write ':{n} x :{m}', should the
lexer interpolate and escape them inside the strings? That is the sh
solution, but I'm not sure it should be done now in psql.

> I understand well so it is subjective - and more, don't think so this
> point is significant.

Well, depending on the syntax things can be done or not, eg test the
variable definition server-side, not only client side. Hence the
discussion:-)

> We should to have this functionality.

Yes.

--
Fabien.

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Masahiko Sawada 2017-04-17 09:02:57 Re: some review comments on logical rep code
Previous Message Yugo Nagata 2017-04-17 08:50:42 Re: [POC] hash partitioning