From: | Erik Jones <erik(at)myemma(dot)com> |
---|---|
To: | Michael Glaesemann <grzm(at)seespotcode(dot)net> |
Cc: | Paul Lambert <paul(dot)lambert(at)autoledgers(dot)com(dot)au>, pgsql-sql(at)postgresql(dot)org |
Subject: | Re: Using escape strings in an insert statement. |
Date: | 2007-07-03 15:49:26 |
Message-ID: | EA4E45FC-EC9D-4063-A208-A37B2F509C80@myemma.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
On Jul 2, 2007, at 6:11 PM, 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');
No, that will leave him with the string 'abc23' beinginserted, he
wants the backslash to be included in the string, that's why he had
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
>> "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.
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
> broadcast)---------------------------
> TIP 7: You can help support the PostgreSQL project by donating at
>
> http://www.postgresql.org/about/donate
Erik Jones
Software Developer | Emma®
erik(at)myemma(dot)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
From | Date | Subject | |
---|---|---|---|
Next Message | Mark Fenbers | 2007-07-03 16:22:14 | Informix Schema -> PostgreSQL ? |
Previous Message | Loredana Curugiu | 2007-07-03 13:08:38 | Re: [SQL] dblink inside plpgsql function |