Re: Using escape strings in an insert statement. - Mailing list pgsql-sql

From Michael Glaesemann
Subject Re: Using escape strings in an insert statement.
Date
Msg-id B98511E0-E97F-4B76-82F0-CE92FC2ACA07@seespotcode.net
Whole thread Raw
In response to Using escape strings in an insert statement.  (Paul Lambert <paul.lambert@autoledgers.com.au>)
Responses Re: Using escape strings in an insert statement.  (Paul Lambert <paul.lambert@autoledgers.com.au>)
Re: Using escape strings in an insert statement.  (Erik Jones <erik@myemma.com>)
List pgsql-sql
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




pgsql-sql by date:

Previous
From: Paul Lambert
Date:
Subject: Using escape strings in an insert statement.
Next
From: Paul Lambert
Date:
Subject: Re: Using escape strings in an insert statement.