Re: Odd quoting behavior from \set

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: Jim Nasby <Jim(dot)Nasby(at)bluetreble(dot)com>
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: Odd quoting behavior from \set
Date: 2016-01-19 21:14:38
Message-ID: CAKFQuwbuWTB5So=i5E96Po-kBkwvL3F30-S26Pb=2nZ0ti486A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tue, Jan 19, 2016 at 1:39 PM, Jim Nasby <Jim(dot)Nasby(at)bluetreble(dot)com> wrote:

> Is this odd quoting behavior expected? (Note difference between "'a':1"
> and "'b':'a'")
>
> ~(at)decina(dot)local/53896# \set df
>> pd.DataFrame.from_dict([{'a':1,'b':'a'},{'a':2,'b':'b'}])
>> ~(at)decina(dot)local/53896# \echo :df
>> pd.DataFrame.from_dict([{a:1,b:'a'},{a:2,b:'b'}])
>> ~(at)decina(dot)local/53896#
>
>
​Yeah, something odds is going one here, testing on 9.3.10 Ubuntu 14.04

\set df ' " d ' " "
select :'df' => " d " "

Removing the last double-quote results in an "unterminated quoted string"
error

​Apparently the quoting rules for \set need to first be discovered and then
added to the documentation.​

\set df alpha'beta'delta => alphabetadelta
\set df "alpha'beta'delta" => "alpha'beta'delta"

So adding double-quotes causes the rest of the content to be considered
literally but unfortunately the double-quotes themselves become part of the
value. Single-quotes by themselves get paired up and removed.

​[testing some more]

*Got It!*

Its the colon that is allowing the single-quotes around the "value" to
remain. PostgreSQL read " :'a' " and sees a variable that it might need to
resolve - and when it cannot it simply leaves the variable name reference​
in place.

​If not for the colon all of the single-quotes would have been removed as
delimiters.

I still think some improvement and or outright fixes could be made here but
am going to leave it here for now.

David J.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Adrian Klaver 2016-01-19 21:28:03 Re: Building 9.4 rpm for Red Hat 5
Previous Message Adrian Klaver 2016-01-19 20:56:50 Re: Building 9.4 rpm for Red Hat 5