From: | Peter Eisentraut <peter_e(at)gmx(dot)net> |
---|---|
To: | Richard Huxton <dev(at)archonet(dot)com> |
Cc: | John Fabiani <johnf(at)jfcomputer(dot)com>, pgsql-sql(at)postgresql(dot)org |
Subject: | Re: the use of $$string$$ |
Date: | 2011-11-08 05:16:28 |
Message-ID: | 1320729388.31945.7.camel@vanquo.pezone.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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.
From | Date | Subject | |
---|---|---|---|
Next Message | Sylvain Mougenot | 2011-11-08 09:03:11 | Partitionning + Trigger and Execute not working as expected |
Previous Message | Robins Tharakan | 2011-11-08 04:27:08 | Re: GROUP and ORDER BY |