Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 9BF50839848 for ; Tue, 8 Nov 2011 01:16:38 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 98207-04 for ; Tue, 8 Nov 2011 05:16:32 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.8.0-rc2 Received: from mailout-de.gmx.net (mailout-de.gmx.net [213.165.64.22]) by mail.postgresql.org (Postfix) with SMTP id 854EE839847 for ; Tue, 8 Nov 2011 01:16:31 -0400 (AST) Received: (qmail invoked by alias); 08 Nov 2011 05:16:29 -0000 Received: from a88-115-218-165.elisa-laajakaista.fi (EHLO [10.0.0.102]) [88.115.218.165] by mail.gmx.net (mp072) with SMTP; 08 Nov 2011 06:16:29 +0100 X-Authenticated: #495269 X-Provags-ID: V01U2FsdGVkX18Oztp3sIoO3n0j0K9jIp/6ValcbxTk9DzuEnJV4m dYTf+qLYEOx+wT Message-ID: <1320729388.31945.7.camel@vanquo.pezone.net> Subject: Re: the use of $$string$$ From: Peter Eisentraut To: Richard Huxton Cc: John Fabiani , pgsql-sql@postgresql.org Date: Tue, 08 Nov 2011 07:16:28 +0200 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> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.0.3-2 Content-Transfer-Encoding: 8bit Mime-Version: 1.0 X-Y-GMX-Trusted: 0 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-3.1 tagged_above=-5 required=5 tests=BAYES_00=-1.9, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RP_MATCHES_RCVD=-1.201 X-Spam-Level: X-Archive-Number: 201111/30 X-Sequence-Number: 36003 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''$$) > So - the $$ quoting is unnecessary here - just use the % placeholders. > > Incidentally, should it be %s for the numeric argument? Yes.