Skip site navigation (1) Skip section navigation (2)

Re: A couple of issues with psql variable substitution

From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Andrew Dunstan <andrew(at)dunslane(dot)net>, Alvaro Herrera <alvherre(at)commandprompt(dot)com>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: A couple of issues with psql variable substitution
Date: 2011-08-25 21:18:18
Message-ID: CA+TgmoY0_Oa2_UifDDn-kni_E+kVw57UOpXOOkFCZK84u3ZkJw@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-hackers
On Thu, Aug 25, 2011 at 5:12 PM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> While I'm looking at this ... the current implementation has got a
> number of very inconsistent behaviors with respect to when it will
> expand a variable reference within a psql meta-command argument.
> Observe:
>
> regression=# \set foo 'value of foo'
> regression=# \set bar 'value of bar'
> regression=# \echo :foo
> value of foo
> regression=# \echo :foo(at)bar
> value of foo @bar
>
> (there shouldn't be a space before the @, IMO --- there is because this
> gets treated as two separate arguments, which seems bizarre)
>
> regression=# \echo :foo:bar
> value of foo value of bar
>
> (again, why is this two arguments not one?)
>
> regression=# \echo :foo@:bar
> value of foo @:bar
>
> (why isn't :bar expanded here, when it is in the previous case?)
>
> regression=# \echo foo:foo@:bar
> foo:foo@:bar
>
> (and now neither one gets expanded)
>
> ISTM the general rule ought to be that we attempt to substitute for a
> colon-construct regardless of where it appears within an argument, as
> long as it's not within quotes.
>
> Thoughts?

My main thought is that I remember this code being pretty awful -
especially with respect to error handling - when I looked at it.  A
lot of dubious behaviors were more or less compelled by the
impossibility of bailing out at an arbitrary point a la ereport().  At
least, barring a drastic refactoring of the code, which might not be a
bad idea either.

No objection if you want to clean some of it up, but you may find it's
a larger sinkhole than you anticipate.

-- 
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

In response to

Responses

pgsql-hackers by date

Next:From: Andrew DunstanDate: 2011-08-25 21:29:54
Subject: Re: A couple of issues with psql variable substitution
Previous:From: Tom LaneDate: 2011-08-25 21:12:59
Subject: Re: A couple of issues with psql variable substitution

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group