Re: the use of $$string$$ - Mailing list pgsql-sql

From Peter Eisentraut
Subject Re: the use of $$string$$
Date
Msg-id 1320729388.31945.7.camel@vanquo.pezone.net
Whole thread Raw
In response to Re: the use of $$string$$  (Richard Huxton <dev@archonet.com>)
List pgsql-sql
On mån, 2011-11-07 at 08:44 +0000, Richard Huxton wrote:
> > myvarString = "long string that contains single quotes"
> > cusor.execute("insert into table (pkid, myfield) values (%s, $$%s
> $$)",(123,
> > myvarString))
> >
> > When I execute the above I'm seeing:
> > E'long string that contains single quotes' in the field.  When I do
> a "select
> > * from table"   I get E'long string that contains single quotes'.
> 
> OK, so it seems psycopg is quoting your strings for you (as you'd 
> expect). It's presumably turning your query into:
>      ... values (E'123', $$E'<long string>'$$)
> So - the $$ quoting is unnecessary here - just use the % placeholders.
> 
> Incidentally, should it be %s for the numeric argument?

Yes.




pgsql-sql by date:

Previous
From: Robins Tharakan
Date:
Subject: Re: GROUP and ORDER BY
Next
From: Jasen Betts
Date:
Subject: Re: Number timestamped rows