Re: Odd quoting behavior from \set - Mailing list pgsql-general

From David G. Johnston
Subject Re: Odd quoting behavior from \set
Date
Msg-id CAKFQuwbuWTB5So=i5E96Po-kBkwvL3F30-S26Pb=2nZ0ti486A@mail.gmail.com
Whole thread Raw
In response to Odd quoting behavior from \set  (Jim Nasby <Jim.Nasby@BlueTreble.com>)
List pgsql-general
On Tue, Jan 19, 2016 at 1:39 PM, Jim Nasby <Jim.Nasby@bluetreble.com> wrote:
Is this odd quoting behavior expected? (Note difference between "'a':1" and "'b':'a'")

~@decina.local/53896# \set df pd.DataFrame.from_dict([{'a':1,'b':'a'},{'a':2,'b':'b'}])
~@decina.local/53896# \echo :df
pd.DataFrame.from_dict([{a:1,b:'a'},{a:2,b:'b'}])
~@decina.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.



pgsql-general by date:

Previous
From: Adrian Klaver
Date:
Subject: Re: Building 9.4 rpm for Red Hat 5
Next
From: Adrian Klaver
Date:
Subject: Re: Building 9.4 rpm for Red Hat 5