Re: \if, \elseif, \else, \endif (was Re: PSQL commands: \quit_if, \quit_unless)

From: "Daniel Verite" <daniel(at)manitou-mail(dot)org>
To: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: "Corey Huinker" <corey(dot)huinker(at)gmail(dot)com>,"David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>,"Fabien COELHO" <coelho(at)cri(dot)ensmp(dot)fr>,"Greg Stark" <stark(at)mit(dot)edu>,"Erik Rijkers" <er(at)xs4all(dot)nl>,"Robert Haas" <robertmhaas(at)gmail(dot)com>,"Jim Nasby" <Jim(dot)Nasby(at)bluetreble(dot)com>,"PostgreSQL" <pgsql-hackers(at)postgresql(dot)org>,pgsql-hackers-owner(at)postgresql(dot)org
Subject: Re: \if, \elseif, \else, \endif (was Re: PSQL commands: \quit_if, \quit_unless)
Date: 2017-03-17 11:33:54
Message-ID: 9cdc09f7-8e5c-43c9-9c00-2e3bbb69b9ef@manitou-mail.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Tom Lane wrote:

> OT_WHOLE_LINE is not what you want because that results in verbatim
> copying, without variable expansion or anything

But if we want to implement "\if defined :foo" in the future
isn't it just what we need?

Also we could leave open the option to accept an SQL expression
here. I expect people will need SQL as the evaluator in a lot of cases.
So far we need to do that:

SELECT sql_expr ... AS varname \gset
\if :varname
...
\endif

Surely users will wonder right away why they can't write it like this
instead:

\if (sql_expr)
...
\endif

There's a precedent with \copy accepting a query inside parentheses,
using OT_WHOLE_LINE.

Best regards,
--
Daniel Vérité
PostgreSQL-powered mailer: http://www.manitou-mail.org
Twitter: @DanielVerite

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Michael Paquier 2017-03-17 11:42:46 Re: Authentication tests, and plain 'password' authentication with a SCRAM verifier
Previous Message Masahiko Sawada 2017-03-17 11:04:38 Re: Two phase commit in ECPG