pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Paul Lambert <paul.lambert@autoledgers.com.au>
To: pgsql-sql@postgresql.org
Subject: Re: Using escape strings in an insert statement.
Date: Tue, 03 Jul 2007 07:26:56 +0800
Message-ID: <468989C0.7020601@autoledgers.com.au> (raw)
In-Reply-To: <B98511E0-E97F-4B76-82F0-CE92FC2ACA07@seespotcode.net>
References: <46898000.7030601@autoledgers.com.au>
	<B98511E0-E97F-4B76-82F0-CE92FC2ACA07@seespotcode.net>

Michael Glaesemann wrote:
> 
> 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 
> 
> 

Missed that part - my apologies. Time to read the manuals more 
thoroughly it would seem.

>> 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
> 

Looks like it's a toss-up between turning standard_conforming_strings on 
or turning escape_string_warning off, both seem to have the same effect 
in not giving the error anymore.

I'll go with your suggestion though, I guess since it's a new install 
not a previous upgrade of an old it's technically more correct to 
conform to current standards rather than attempt to conform to old behavior.

Cheers for the help - much appreciated.

-- 
Paul Lambert
Database Administrator
AutoLedgers




view thread (6+ messages)  latest in thread

Message-ID: <468989C0.7020601@autoledgers.com.au>
Permalink:  ../468989C0.7020601@autoledgers.com.au/
Also on:    postgresql.org/message-id/468989C0.7020601@autoledgers.com.au

 · 

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: paul.lambert@autoledgers.com.au
  Subject: Re: Using escape strings in an insert statement.
  In-Reply-To: <468989C0.7020601@autoledgers.com.au>

* 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