Re: Escaping special characters - Mailing list pgsql-general

From Daniel Verite
Subject Re: Escaping special characters
Date
Msg-id b9b176fc-de94-423b-b3ec-b1ba0025766f@mm
Whole thread Raw
In response to Escaping special characters  (Neanderthelle Jones <elle@view.net.au>)
List 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

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: different results for large objects
Next
From: Subha Ramakrishnan
Date:
Subject: Uploading data to postgresql database