|PostgreSQL Reference Manual - Volume 1 - SQL Language Reference|
by The PostgreSQL Global Development Group
Paperback (6"x9"), 716 pages
RRP £32.00 ($49.95)
Sales of this book support the PostgreSQL project! Get a printed copy>>>
18.104.22.168 String Constants
A string constant in SQL is an arbitrary sequence of characters
bounded by single quotes (
'), for example
'This is a string'. To include
a single-quote character within a string constant,
write two adjacent single quotes, e.g.
Note that this is not the same as a double-quote
Two string constants that are only separated by whitespace with at least one newline are concatenated and effectively treated as if the string had been written as one constant. For example:
SELECT 'foo' 'bar';
is equivalent to
SELECT 'foo' 'bar';
is not valid syntax. (This slightly bizarre behavior is specified by SQL; PostgreSQL is following the standard.)
PostgreSQL also accepts “escape”
string constants, which are an extension to the SQL standard.
An escape string constant is specified by writing the letter
E (upper or lower case) just before the opening single
E'foo'. (When continuing an escape string
constant across lines, write
E only before the first opening
Within an escape string, a backslash character (
\) begins a
C-like backslash escape sequence, in which the combination
of backslash and following character(s) represents a special byte value.
\b is a backspace,
\f is a form feed,
\n is a newline,
\r is a carriage return,
\t is a tab.
Also supported are
digits represents an octal byte value, and
hexdigits represents a hexadecimal byte value.
(It is your responsibility that the byte sequences you create are
valid characters in the server character set encoding.) Any other
character following a backslash is taken literally. Thus, to
include a backslash character, write two backslashes (
Also, a single quote can be included in an escape string by writing
\', in addition to the normal way of
Caution: If the configuration parameter
off, then PostgreSQL recognizes backslash escapes in both regular and escape string constants. This is for backward compatibility with the historical behavior, in which backslash escapes were always recognized. Although
standard_conforming_stringscurrently defaults to
off, the default will change to
onin a future release for improved standards compliance. Applications are therefore encouraged to migrate away from using backslash escapes. If you need to use a backslash escape to represent a special character, write the constant with an
Eto be sure it will be handled the same way in future releases.
The character with the code zero cannot be in a string constant.
|ISBN 0954612027||PostgreSQL Reference Manual - Volume 1 - SQL Language Reference||See the print edition|