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

From: Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>
To: Daniel Verite <daniel(at)manitou-mail(dot)org>
Cc: Corey Huinker <corey(dot)huinker(at)gmail(dot)com>, PostgreSQL <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: \if, \elseif, \else, \endif (was Re: PSQL commands: \quit_if, \quit_unless)
Date: 2017-01-26 20:55:13
Message-ID: alpine.DEB.2.20.1701262143090.26793@lancre
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers


Hello Daniel,

> A comment about control flow and variables: in branches that are not
> taken, variables are expanded nonetheless, in a way that can be
> surprising. Case in point:
>
> \set var 'ab''cd'
> -- select :var;
> \if false
> select :var ;
> \else
> select 1;
> \endif
>
> To avoid that kind of trouble, would it make sense not to expand
> variables in untaken branches?

Hmmm. This case is somehow contrived (for a string, :'var' could be used,
in which case escaping would avoid the hazard), but I think that what you
suggest is a better behavior, if easy to implement.

--
Fabien.

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Corey Huinker 2017-01-26 21:06:22 Re: \if, \elseif, \else, \endif (was Re: PSQL commands: \quit_if, \quit_unless)
Previous Message Alvaro Herrera 2017-01-26 20:50:52 Re: Failure in commit_ts tap tests