Re: Escaping special characters

From: "Daniel Verite" <daniel(at)manitou-mail(dot)org>
To: "Neanderthelle Jones" <elle(at)view(dot)net(dot)au>
Cc: "PGSQL Mailing List" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Escaping special characters
Date: 2009-03-17 12:48:18
Message-ID: b9b176fc-de94-423b-b3ec-b1ba0025766f@mm
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Neanderthelle Jones wrote:

> About the string "Smith \& Jones".
>
> According to the documentation,
>
> INSERT INTO thing (name) VALUES ('Smith E'\\'& Jones');
>
> must work. But it doesn't. So, double the enclosed quotes:
>
> INSERT INTO thing (name) VALUES ('Smith E''\\''& Jones');

The E can't be inside the string, it must appear before the quote
starting the string.

But first, you need to choose a setting for
standard_conforming_strings, especially if you're concerned with
compatibility against future versions. Either your session has
standard_conforming_strings set to ON or set to OFF. This is what
defines which characters have to be quoted and how.

if OFF you must escape the backslash:
test=> set standard_conforming_strings=off;
SET
test=> select E'Smith \\& Jones';
?column?
----------------
Smith \& Jones
(1 row)

if ON you don't:
test=> set standard_conforming_strings=on;
SET
test=> select 'Smith \& Jones';
?column?
----------------
Smith \& Jones
(1 row)

ON is supposed to become the default at some point in the future.

Cordialement,
--
Daniel

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Alvaro Herrera 2009-03-17 13:16:39 Re: What are the benefits of using a clustered index?
Previous Message Tom Lane 2009-03-17 12:43:05 Re: [GENERAL] different results for large objects