+ syntax is used) and is therefore consumed, leaving the second backslash of the
-
+
Functions and Operators
Encode binary data to
ASCII-only representation. Supported
types are: base64>, hex>, escape>.
- encode( '123\\000\\001', 'base64')
+ encode( E'123\\000\\001', 'base64')
MTIzAAE=
Return the given string suitably quoted to be used as a string literal
in an
SQL statement string.
- Embedded quotes and backslashes are properly doubled.
+ Embedded single-quotes and backslashes are properly doubled.
quote_literal( 'O\'Reilly')
'O''Reilly'
concatenation
- '\\\\Post'::bytea || '\\047gres\\000'::bytea
+ E'\\\\Post'::bytea || E'\\047gres\\000'::bytea
\\Post'gres\000
- get_bit('Th\\000omas'::bytea, 45)
+ get_bit(E'Th\\000omas'::bytea, 45)
1
- get_byte('Th\\000omas'::bytea, 4)
+ get_byte(E'Th\\000omas'::bytea, 4)
109
int
Number of bytes in binary string
- octet_length( 'jo\\000se'::bytea)
+ octet_length( E'jo\\000se'::bytea)
5
position(substring in string)
int
Location of specified substring
- position('\\000om'::bytea in 'Th\\000omas'::bytea)
+ position(E'\\000om'::bytea in E'Th\\000omas'::bytea)
3
- set_bit('Th\\000omas'::bytea, 45, 0)
+ set_bit(E'Th\\000omas'::bytea, 45, 0)
Th\000omAs
- set_byte('Th\\000omas'::bytea, 4, 64)
+ set_byte(E'Th\\000omas'::bytea, 4, 64)
Th\000o@as
- substring('Th\\000omas'::bytea from 2 for 3)
+ substring(E'Th\\000omas'::bytea from 2 for 3)
h\000o
- trim('\\000'::bytea from '\\000Tom\\000'::bytea)
+ trim(E'\\000'::bytea from E'\\000Tom\\000'::bytea)
Tom
in
bytes from the start and end of
- btrim('\\000trim\\000'::bytea, '\\000'::bytea)
+ btrim(E'\\000trim\\000'::bytea, E'\\000'::bytea)
trim
Decode binary string from
string previously
encoded with encode>. Parameter type is same as in encode>.
- decode('123\\000456', 'escape')
+ decode(E'123\\000456', 'escape')
123\000456
Encode binary string to
ASCII-only representation. Supported
types are: base64>, hex>, escape>.
- encode('123\\000456'::bytea, 'escape')
+ encode(E'123\\000456'::bytea, 'escape')
123\000456
binary strings, length
- length('jo\\000se'::bytea)
+ length(E'jo\\000se'::bytea)
5
Calculates the MD5 hash of
string,
returning the result in hexadecimal
- md5('Th\\000omas'::bytea)
+ md5(E'Th\\000omas'::bytea)
8ab2d3c9689aaf18 b4958c334c82d8b1
Note that the backslash already has a special meaning in string
literals, so to write a pattern constant that contains a backslash
- you must write two backslashes in an SQL statement. Thus, writing a pattern
+ you must write two backslashes in an SQL statement (assuming escape
+ string syntax is used). Thus, writing a pattern
that actually matches a literal backslash means writing four backslashes
in the statement. You can avoid this by selecting a different escape
character with ESCAPE; then a backslash is not special
substring matching the entire pattern should be inserted. Write
\\> if you need to put a literal backslash in the replacement
text. (As always, remember to double backslashes written in literal
- constant strings.)
+ constant strings, assuming escape string syntax is used.)
The flags> parameter is an optional text
string containing zero or more single-letter flags that change the
function's behavior. Flag i> specifies case-insensitive
fooXbaz
regexp_replace('foobarbaz', 'b..', 'X', 'g')
fooXX
-regexp_replace('foobarbaz', 'b(..)', 'X\\1Y', 'g')
+regexp_replace('foobarbaz', 'b(..)', E'X\\1Y', 'g')
fooXarYXazY
Remember that the backslash (\) already has a special
meaning in
PostgreSQL> string literals.
To write a pattern constant that contains a backslash,
- you must write two backslashes in the statement.
+ you must write two backslashes in the statement, assuming escape
+ string syntax is used.
Keep in mind that an escape's leading \> will need to be
doubled when entering the pattern as an SQL string constant. For example:
-'123' ~ '^\\d{3}' true
+'123' ~ E'^\\d{3}' true
If you want to have a double quote in the output you must
- precede it with a backslash, for example '\\"YYYY
+ precede it with a backslash, for example E'\\"YYYY
Month\\"'.
(Two backslashes are necessary because the backslash already
- has a special meaning in a string constant.)
+ has a special meaning when using the escape string syntax.)
-
+
PL/Perl - Perl Procedural Language
the function body to be written as a string constant. It is usually
most convenient to use dollar quoting (see
linkend="sql-syntax-dollar-quoting">) for the string constant.
- If you choose to use regular single-quoted string constant syntax,
- you must escape single quote marks ('>) and backslashes
- (\>) used in the body of the function, typically by
- doubling them (see ).
+ If you choose to use escape string syntax E''>,
+ you must double the single quote marks ('>) and backslashes
+ (\>) used in the body of the function
+ (see ).
-
+
PL/pgSQL - SQL Procedural Language
CREATE FUNCTION as a string literal. If you
write the string literal in the ordinary way with surrounding
single quotes, then any single quotes inside the function body
- must be doubled; likewise any backslashes must be doubled.
+ must be doubled; likewise any backslashes must be doubled (assuming
+ escape string syntax is used).
Doubling quotes is at best tedious, and in more complicated cases
the code can become downright incomprehensible, because you can
easily find yourself needing half a dozen or more adjacent quote marks.
- A variant approach is to escape quotation marks in the function body
- with a backslash rather than by doubling them. With this method
- you'll find yourself writing things like \'\'> instead
- of ''''>. Some find this easier to keep track of, some
- do not.
-
-
+
PL/Tcl - Tcl Procedural Language
$$ LANGUAGE pltcl;
- We need backslashes inside the query string given to
- spi_prepare> to ensure that the
- $n> markers will be passed
- through to spi_prepare> as-is, and not replaced by Tcl
- variable substitution.
+ We need backslashes inside the query string given to
+ spi_prepare> to ensure that the
+ $n> markers will be passed
+ through to spi_prepare> as-is, and not replaced by Tcl
+ variable substitution.
-
+
Composite Types
Remember that what you write in an SQL command will first be interpreted
as a string literal, and then as a composite. This doubles the number of
- backslashes you need. For example, to insert a text> field
+ backslashes you need (assuming escape string syntax is used).
+ For example, to insert a text> field
containing a double quote and a backslash in a composite
value, you'd need to write
-INSERT ... VALUES ('("\\"\\\\")');
+INSERT ... VALUES (E'("\\"\\\\")');
The string-literal processor removes one level of backslashes, so that
what arrives at the composite-value parser looks like
-
+
User-Defined Functions
most convenient to use dollar quoting (see
linkend="sql-syntax-dollar-quoting">) for the string constant.
If you choose to use regular single-quoted string constant syntax,
- you must escape single quote marks ('>) and backslashes
- (\>) used in the body of the function, typically by
- doubling them (see ).
+ you must double single quote marks ('>) and backslashes
+ (\>) (assuming escape string syntax) in the body of
+ the function (see ).