Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 73BFBB5DCFA for ; Fri, 4 Nov 2011 15:06:45 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 38556-08 for ; Fri, 4 Nov 2011 18:06:39 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.8.0-rc2 Received: from mail.archonet.com (84-51-143-99.archon037.adsl.metronet.co.uk [84.51.143.99]) by mail.postgresql.org (Postfix) with ESMTP id 06B23B5DC74 for ; Fri, 4 Nov 2011 15:06:38 -0300 (ADT) Received: from [192.168.1.36] (dell36.office.archonet.com [192.168.1.36]) by mail.archonet.com (Postfix) with ESMTP id C619B7C08B; Fri, 4 Nov 2011 18:06:36 +0000 (GMT) Message-ID: <4EB429AD.3030607@archonet.com> Date: Fri, 04 Nov 2011 18:06:37 +0000 From: Richard Huxton User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.23) Gecko/20110921 Lightning/1.0b2 Thunderbird/3.1.15 MIME-Version: 1.0 To: John Fabiani CC: pgsql-sql@postgresql.org Subject: Re: the use of $$string$$ References: <201111040738.29303.johnf@jfcomputer.com> <201111040826.16177.johnf@jfcomputer.com> In-Reply-To: <201111040826.16177.johnf@jfcomputer.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-0.918 tagged_above=-5 required=5 tests=BAYES_00=-1.9, RDNS_DYNAMIC=0.982 X-Spam-Level: X-Archive-Number: 201111/19 X-Sequence-Number: 35992 On 04/11/11 15:26, John Fabiani wrote: > On Friday, November 04, 2011 07:38:29 am John Fabiani wrote: >> Hi, >> I just discovered that I can use $$string$$ to account for the problem of >> single quotes in the string (or other strange char's). However, I noticed >> that the table field contained E'string'. I actually tried to find info on >> this but I did not find anything. >> >> Could someone explain what it means or better provide a web link for me to >> discover the info. > Thank you both for the quick replies and the links. > > What I still do not understand (I'm a little slow) is the fact that pgadmin3 > showed the data as E'string'. So I'm wondering if the data is now different > in the sense that I need use the 'E' in the field. I think you're missing some bit of the puzzle here. There's the universal problem of how to deal with quote marks inside quotes. The SQL standard says you double the quote. SELECT length('ab''de'); length -------- 5 Traditionally, PostgreSQL let you use backslash escapes too, not just for single quotes but for some other common C-style idioms. SELECT length(E'ab\'de'); length -------- 5 For the last few years, this has been moved into its own quoting style so standard strings are always well, standard. SELECT length('ab\nde'); length -------- 6 SELECT length(E'ab\nde'); length -------- 5 The [E'] is an opening quote - both characters. It isn't part of the value at all. If a field contains "E'" then you put it there, possibly by quoting something in pgadmin that was already quoted. Likewise you can use $$..$$ to quote strings (actually $$whatever$$). That gives you sql-standard escaping apart from single quotes. It's especially useful for function bodies which tend to contain their own string literals. SELECT length($$ab\nde$$); length -------- 6 None of this should matter from an application however, since its database access library should do all the quoting for you. HTH -- Richard Huxton Archonet Ltd