Received: from localhost (maia-2.hub.org [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id B856A9FB2EF for ; Mon, 2 Jul 2007 20:11:22 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-maia, port 10024) with ESMTP id 08425-07 for ; Mon, 2 Jul 2007 20:11:12 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from mtai03.charter.net (mtai03.charter.net [209.225.8.183]) by postgresql.org (Postfix) with ESMTP id EB5549FB2DE for ; Mon, 2 Jul 2007 20:11:16 -0300 (ADT) Received: from aa04.charter.net ([10.20.200.156]) by mtai03.charter.net (InterMail vM.7.08.02.00 201-2186-121-20061213) with ESMTP id <20070702231115.BRZC1450.mtai03.charter.net@aa04.charter.net>; Mon, 2 Jul 2007 19:11:15 -0400 Received: from [10.0.1.2] (really [66.188.164.45]) by aa04.charter.net with ESMTP id <20070702231115.IVEK1254.aa04.charter.net@[10.0.1.2]>; Mon, 2 Jul 2007 19:11:15 -0400 In-Reply-To: <46898000.7030601@autoledgers.com.au> References: <46898000.7030601@autoledgers.com.au> Mime-Version: 1.0 (Apple Message framework v752.2) Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed Message-Id: Cc: pgsql-sql@postgresql.org Content-Transfer-Encoding: 7bit From: Michael Glaesemann Subject: Re: Using escape strings in an insert statement. Date: Mon, 2 Jul 2007 18:11:09 -0500 To: Paul Lambert X-Mailer: Apple Mail (2.752.2) X-Chzlrs: 0 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200707/7 X-Sequence-Number: 28742 On Jul 2, 2007, at 17:45 , Paul Lambert wrote: > tester=# insert into testing (test_text) values ('abcE'\\'123'); This 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 > "Thus, to include a backslash character, write two backslashes (\\). " Note that the String Constants section (4.1.2.1) says put the E "before the opening single quote". http://www.postgresql.org/docs/8.2/interactive/sql-syntax- lexical.html#SQL-SYNTAX-CONSTANTS > An escape string constant is specified by writing the letter E > (upper or lower case) just before the opening single quote, e.g. > E'foo'. Also be sure to read the Caution section. Using \ as an escape character is the old non-standard PostgreSQL escape syntax that the WARNING (above) is, uh, warning you about. With standard_conforming_strings on (i.e., follow the SQL spec), the backslash is just a backslash character. > Which one is the correct syntax and how can I make it not return > anything other than a successful insert? Depends on the setting of standard_conforming_strings. Michael Glaesemann grzm seespotcode net