Re: [HACKERS] Variable substitution in psql backtick expansion

Поиск
Список
Период
Сортировка
От Greg Stark
Тема Re: [HACKERS] Variable substitution in psql backtick expansion
Дата
Msg-id CAM-w4HMq2RoVg2L=GPGR3xYXKQJMsc2noCPdZjt=5eWRnmoEVQ@mail.gmail.com
обсуждение исходный текст
Ответы Re: [HACKERS] Variable substitution in psql backtick expansion
Re: [HACKERS] Variable substitution in psql backtick expansion
Список pgsql-hackers
On 2 April 2017 at 07:53, Fabien COELHO <coelho@cri.ensmp.fr> wrote:
> Note that this is already available indirectly, as show in the
> documentation.
>
>   SELECT some-boolean-expression AS okay \gset
>   \if :okay
>     \echo boolean expression was true
>   \else
>     \echo boolean expression was false
>   \endif


Am I the only one who thinks that even if \if got the ability to
evaluate arbitrary SQL queries I would probably still always write
things as above? I think putting arbitrary SQL expressions (let alone
queries) would make scripts just a total mess and impossible for
humans to parse.

Whereas storing the results in psql variables and then using those
variables in \if makes even fairly complex queries and nested \if
structures straightforward.  It would also make it far clearer in what
order the queries will be evaluated and under which set of conditions.

I don't think taking a simple command line execution environment like
psql and trying to embed a complete complex language parser in it is
going to result in a sensible programming environment. Having a simple
\if <single variable> is already pushing it. If someone wanted
anything more complex I would strongly recommend switching to perl or
python before trying to code up nesting arbitrary sql in nested
expressions.

-- 
greg



В списке pgsql-hackers по дате отправления:

Предыдущее
От: Heikki Linnakangas
Дата:
Сообщение: Re: [HACKERS] Some thoughts about SCRAM implementation
Следующее
От: Robert Haas
Дата:
Сообщение: Re: [HACKERS] Proposal: Local indexes for partitioned table