@@ -1294,9 +1294,9 @@ SELECT b, char_length(b) FROM test2;
1294
1294
per byte, most significant nibble first. The entire string is
1295
1295
preceded by the sequence <literal>\x</literal> (to distinguish it
1296
1296
from the escape format). In some contexts, the initial backslash may
1297
- need to be escaped by doubling it, in the same cases in which backslashes
1298
- have to be doubled in escape format; details appear below .
1299
- The hexadecimal digits can
1297
+ need to be escaped by doubling it
1298
+ (see <xref linkend="sql-syntax-strings">) .
1299
+ For input, the hexadecimal digits can
1300
1300
be either upper or lower case, and whitespace is permitted between
1301
1301
digit pairs (but not within a digit pair nor in the starting
1302
1302
<literal>\x</literal> sequence).
@@ -1338,9 +1338,7 @@ SELECT '\xDEADBEEF';
1338
1338
values <emphasis>must</emphasis> be escaped, while all octet
1339
1339
values <emphasis>can</emphasis> be escaped. In
1340
1340
general, to escape an octet, convert it into its three-digit
1341
- octal value and precede it
1342
- by a backslash (or two backslashes, if writing the value as a
1343
- literal using escape string syntax).
1341
+ octal value and precede it by a backslash.
1344
1342
Backslash itself (octet decimal value 92) can alternatively be represented by
1345
1343
double backslashes.
1346
1344
<xref linkend="datatype-binary-sqlesc">
@@ -1357,7 +1355,7 @@ SELECT '\xDEADBEEF';
1357
1355
<entry>Description</entry>
1358
1356
<entry>Escaped Input Representation</entry>
1359
1357
<entry>Example</entry>
1360
- <entry>Output Representation</entry>
1358
+ <entry>Hex Representation</entry>
1361
1359
</row>
1362
1360
</thead>
1363
1361
@@ -1381,7 +1379,7 @@ SELECT '\xDEADBEEF';
1381
1379
<row>
1382
1380
<entry>92</entry>
1383
1381
<entry>backslash</entry>
1384
- <entry><literal>'\'</literal> or <literal>'\ \134'</literal></entry>
1382
+ <entry><literal>'\\ '</literal> or <literal>'\134'</literal></entry>
1385
1383
<entry><literal>SELECT '\\'::bytea;</literal></entry>
1386
1384
<entry><literal>\x5c</literal></entry>
1387
1385
</row>
@@ -1401,39 +1399,35 @@ SELECT '\xDEADBEEF';
1401
1399
<para>
1402
1400
The requirement to escape <emphasis>non-printable</emphasis> octets
1403
1401
varies depending on locale settings. In some instances you can get away
1404
- with leaving them unescaped. Note that the result in each of the examples
1405
- in <xref linkend="datatype-binary-sqlesc"> was exactly one octet in
1406
- length, even though the output representation is sometimes
1407
- more than one character.
1402
+ with leaving them unescaped.
1408
1403
</para>
1409
1404
1410
1405
<para>
1411
- The reason multiple backslashes are required, as shown
1412
- in <xref linkend="datatype-binary-sqlesc">, is that an input
1413
- string written as a string literal must pass through two parse
1414
- phases in the <productname>PostgreSQL</productname> server.
1415
- The first backslash of each pair is interpreted as an escape
1416
- character by the string-literal parser (assuming escape string
1417
- syntax is used) and is therefore consumed, leaving the second backslash of the
1418
- pair. (Dollar-quoted strings can be used to avoid this level
1419
- of escaping.) The remaining backslash is then recognized by the
1420
- <type>bytea</type> input function as starting either a three
1421
- digit octal value or escaping another backslash. For example,
1422
- a string literal passed to the server as <literal>'\001'</literal>
1423
- becomes <literal>\001</literal> after passing through the
1424
- escape string parser. The <literal>\001</literal> is then sent
1425
- to the <type>bytea</type> input function, where it is converted
1426
- to a single octet with a decimal value of 1. Note that the
1427
- single-quote character is not treated specially by <type>bytea</type>,
1428
- so it follows the normal rules for string literals. (See also
1429
- <xref linkend="sql-syntax-strings">.)
1406
+ The reason that single quotes must be doubled, as shown
1407
+ in <xref linkend="datatype-binary-sqlesc">, is that this
1408
+ is true for any string literal in a SQL command. The generic
1409
+ string-literal parser consumes the outermost single quotes
1410
+ and reduces any pair of single quotes to one data character.
1411
+ What the <type>bytea</type> input function sees is just one
1412
+ single quote, which it treats as a plain data character.
1413
+ However, the <type>bytea</type> input function treats
1414
+ backslashes as special, and the other behaviors shown in
1415
+ <xref linkend="datatype-binary-sqlesc"> are implemented by
1416
+ that function.
1417
+ </para>
1418
+
1419
+ <para>
1420
+ In some contexts, backslashes must be doubled compared to what is
1421
+ shown above, because the generic string-literal parser will also
1422
+ reduce pairs of backslashes to one data character;
1423
+ see <xref linkend="sql-syntax-strings">.
1430
1424
</para>
1431
1425
1432
1426
<para>
1433
1427
<type>Bytea</type> octets are output in <literal>hex</literal>
1434
1428
format by default. If you change <xref linkend="guc-bytea-output">
1435
1429
to <literal>escape</literal>,
1436
- <quote>non-printable</quote> octet are converted to
1430
+ <quote>non-printable</quote> octets are converted to their
1437
1431
equivalent three-digit octal value and preceded by one backslash.
1438
1432
Most <quote>printable</quote> octets are output by their standard
1439
1433
representation in the client character set, e.g.:
0 commit comments