pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Peter Eisentraut <peter_e@gmx.net>
To: Richard Huxton <dev@archonet.com>
Cc: John Fabiani <johnf@jfcomputer.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: the use of $$string$$
Date: Tue, 08 Nov 2011 07:16:28 +0200
Message-ID: <1320729388.31945.7.camel@vanquo.pezone.net> (raw)
In-Reply-To: <4EB79A86.1090005@archonet.com>
References: <201111040738.29303.johnf@jfcomputer.com>
	<201111040826.16177.johnf@jfcomputer.com>
	<4EB429AD.3030607@archonet.com>
	<201111041712.09607.johnf@jfcomputer.com>
	<4EB79A86.1090005@archonet.com>

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.





view thread (11+ messages)  latest in thread

Message-ID: <1320729388.31945.7.camel@vanquo.pezone.net>
Permalink:  ../1320729388.31945.7.camel@vanquo.pezone.net/
Also on:    postgresql.org/message-id/1320729388.31945.7.camel@vanquo.pezone.net

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: peter_e@gmx.net, dev@archonet.com, johnf@jfcomputer.com
  Subject: Re: the use of $$string$$
  In-Reply-To: <1320729388.31945.7.camel@vanquo.pezone.net>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox