From: | Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr> |
---|---|
To: | Corey Huinker <corey(dot)huinker(at)gmail(dot)com> |
Cc: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, PostgreSQL Developers <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: Undefined psql variables |
Date: | 2017-04-07 07:52:09 |
Message-ID: | alpine.DEB.2.20.1704070922550.4988@hendaye |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
Hello Corey,
>>> \if defined varname
>>> \if sql boolean expression to send to server
>>> \if compare value operator value
>>
>> I'm still thinking:-)
>>
>> Independently of the my aethetical complaint against having a pretty
>> unusual keyword prefix syntax, how would you envision a \set assignment
>> variant? Would \if have a different expression syntax somehow?
>
> Any further thoughts?
My current opinion:
- I'm fine if \set stays as it is, i.e. no expression.
- I agree that some client-side expressions are needed, along the
semantics suggested by Tom, i.e. definition and comparisons.
- I'm really against the prefix syntax suggested by Tom
I wish I could have an explanation about why the :?varname (or some other
variant) syntax I suggested has a "namespace" issue.
The advantage that I see is that although it is obviously ugly, it is ugly
in the continuity of the various :["'?]varname syntaxes already offered
and it allows to get rid of "defined varname" which does not look like
SQL. A second advantage is that with the "defined" proposal
\if defined var1 and defined var2 or defined var3 and sqlrt() >= ..
Would probably never work work, as it cannot be embedded in another
expression, while it would work with
\if :?var1 and :?var2 or :?var3 and ...
Moreover, I would like the condition syntax to be basically SQL & psql
variables, without explicit prefixes, with a transparent decision whether
it is evaluated client side or server side.
As client-side expressions are pretty simple, ISTM that some regex could
be used for this purpose, eg for integer and boolean comparisons:
^\s*\d+\s*(=|<>|!=|<|<=|>|>=)\s*\d+\s*$
^\s*(bool...)\s*(=|<>|!=)\s*(bool...)\s*$
^\s*(NOT\s*)?(bool...)\s*$
So that one could just write the expressions without having to tell where
it is executed, eg
\if :VERSION_NUM < 110000
Would lead to
\if 100000 < 110000
Caught by the first regex, and evaluated with a few lines of code.
--
Fabien.
From | Date | Subject | |
---|---|---|---|
Next Message | Fabien COELHO | 2017-04-07 07:55:28 | Re: pgbench - allow to store select results into variables |
Previous Message | Michael Paquier | 2017-04-07 07:38:53 | Re: Compiler warning in costsize.c |