Re: Variable substitution in psql backtick expansion

From: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Variable substitution in psql backtick expansion
Date: 2017-03-31 03:28:40
Message-ID: CAB7nPqThy7hLGVnJ3=eA74SQcAgRpQLnVP7ak6TbV5saBDLqtQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Fri, Mar 31, 2017 at 2:33 AM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> Awhile back in the discussion about the \if feature for psql,
> I'd pointed out that you shouldn't really need very much in
> the way of boolean-expression evaluation smarts, because you
> ought to be able to use a backtick shell escape:
>
> \if `expr :foo \> :bar`
> \echo :foo is greater than :bar
> \endif
>
> Now that the basic feature is in, I went to play around with this,
> and was disappointed to find out that it doesn't work. The reason
> is not far to seek: we do not do variable substitution within the
> text between backticks. psqlscanslash.l already foresaw that some
> day we'd want to do that:
>
> /*
> * backticked text: copy everything until next backquote, then evaluate.
> *
> * XXX Possible future behavioral change: substitute for :VARIABLE?
> */
>
> I think today is that day, because it's going to make a material
> difference to the usability of this feature.
>
> I propose extending backtick processing so that
>
> 1. :VARIABLE is replaced by the contents of the variable
>
> 2. :'VARIABLE' is replaced by the contents of the variable,
> single-quoted according to Unix shell conventions. (So the
> processing would be a bit different from what it is for the
> same notation in SQL contexts.)
>
> This doesn't look like it would take very much new code to do.
>
> Thoughts?

In short, +1.
--
Michael

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Etsuro Fujita 2017-03-31 03:32:39 Re: Something broken around FDW connection close
Previous Message Bruce Momjian 2017-03-31 03:16:47 Re: release notes for v10