Received: from localhost (maia-3.hub.org [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id 4F4AC9FB2B9 for ; Tue, 3 Jul 2007 12:49:41 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 54372-01 for ; Tue, 3 Jul 2007 12:49:35 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from smtp125.iad.emailsrvr.com (smtp125.iad.emailsrvr.com [207.97.245.125]) by postgresql.org (Postfix) with ESMTP id 5FFF09FB204 for ; Tue, 3 Jul 2007 12:49:35 -0300 (ADT) Received: by relay2.r2.iad.emailsrvr.com (Authenticated sender: erik-AT-myemma.com) with ESMTP id 8EC7944CE7F; Tue, 3 Jul 2007 11:49:32 -0400 (EDT) In-Reply-To: References: <46898000.7030601@autoledgers.com.au> Mime-Version: 1.0 (Apple Message framework v752.3) Content-Type: text/plain; charset=ISO-8859-1; delsp=yes; format=flowed Message-Id: Cc: Paul Lambert , pgsql-sql@postgresql.org Content-Transfer-Encoding: quoted-printable From: Erik Jones Subject: Re: Using escape strings in an insert statement. Date: Tue, 3 Jul 2007 10:49:26 -0500 To: Michael Glaesemann X-Mailer: Apple Mail (2.752.3) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200707/18 X-Sequence-Number: 28753 On Jul 2, 2007, at 6:11 PM, Michael Glaesemann wrote: > > On Jul 2, 2007, at 17:45 , Paul Lambert wrote: > >> tester=3D# insert into testing (test_text) values ('abcE'\\'123'); > > This should be > INSERT INTO testing (test_text) values (E'abc\123'); No, that will leave him with the string 'abc23' beinginserted, he =20 wants the backslash to be included in the string, that's why he had =20 two, so it should be: INSERT INTO testing (test_text) values (E'abc\\123'); > >> The help itself (ch 4.1.2.1) tells me to use double backslash =20 >> "Thus, to include a backslash character, write two backslashes (\=20 >> \). " > > Note that the String Constants section (4.1.2.1) says put the E =20 > "before the opening single quote". > > http://www.postgresql.org/docs/8.2/interactive/sql-syntax-=20 > lexical.html#SQL-SYNTAX-CONSTANTS > >> An escape string constant is specified by writing the letter E =20 >> (upper or lower case) just before the opening single quote, e.g. =20 >> E'foo'. > > Also be sure to read the Caution section. > > Using \ as an escape character is the old non-standard PostgreSQL =20 > escape syntax that the WARNING (above) is, uh, warning you about. =20 > With standard_conforming_strings on (i.e., follow the SQL spec), =20 > the backslash is just a backslash character. > >> Which one is the correct syntax and how can I make it not return =20 >> anything other than a successful insert? > > Depends on the setting of standard_conforming_strings. With standard_conforming_strings turned on, it would just need to be: INSERT INTO test (test_text) values ('abc\123'); > > Michael Glaesemann > grzm seespotcode net > > > > ---------------------------(end of =20 > broadcast)--------------------------- > TIP 7: You can help support the PostgreSQL project by donating at > > http://www.postgresql.org/about/donate Erik Jones Software Developer | Emma=AE erik@myemma.com 800.595.4401 or 615.292.5888 615.292.0777 (fax) Emma helps organizations everywhere communicate & market in style. Visit us online at http://www.myemma.com