Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4ed9f1d

Browse files
committed
Update documentation for backslashes to mention escape string syntax
more, and standard_conforming_strings less, because in the future non-Estrings will not treat backslashes specially.Also use E'' strings where backslashes are used in examples. (Theexisting examples would have drawn warnings.)Backpatch to 8.2.X.
1 parent35b039a commit4ed9f1d

File tree

9 files changed

+82
-87
lines changed

9 files changed

+82
-87
lines changed

‎doc/src/sgml/array.sgml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/array.sgml,v 1.52 2006/09/29 21:22:21 tgl Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/array.sgml,v 1.53 2007/01/3022:29:22 momjian Exp $ -->
22

33
<sect1 id="arrays">
44
<title>Arrays</title>
@@ -597,17 +597,17 @@ SELECT f1[1][-2][3] AS e1, f1[1][-1][5] AS e2
597597
</para>
598598

599599
<para>
600-
As shown previously, when writing an array value youmay write double
600+
As shown previously, when writing an array value youcan write double
601601
quotes around any individual array element. You <emphasis>must</> do so
602602
if the element value would otherwise confuse the array-value parser.
603603
For example, elements containing curly braces, commas (or whatever the
604604
delimiter character is), double quotes, backslashes, or leading or trailing
605605
whitespace must be double-quoted. Empty strings and strings matching the
606606
word <literal>NULL</> must be quoted, too. To put a double quote or
607-
backslash in a
608-
quoted array element value,precede it with a backslash. Alternatively, you
609-
can usebackslash-escaping to protect all data characters that would
610-
otherwisebe taken as array syntax.
607+
backslash in a quoted array element value, use escape string syntax
608+
andprecede it with a backslash. Alternatively, you can use
609+
backslash-escaping to protect all data characters that would otherwise
610+
be taken as array syntax.
611611
</para>
612612

613613
<para>
@@ -625,16 +625,16 @@ SELECT f1[1][-2][3] AS e1, f1[1][-1][5] AS e2
625625
backslashes you need. For example, to insert a <type>text</> array
626626
value containing a backslash and a double quote, you'd need to write
627627
<programlisting>
628-
INSERT ... VALUES ('{"\\\\","\\""}');
628+
INSERT ... VALUES (E'{"\\\\","\\""}');
629629
</programlisting>
630-
The string-literal processor removes one level of backslashes, so that
630+
Theescapestring processor removes one level of backslashes, so that
631631
what arrives at the array-value parser looks like <literal>{"\\","\""}</>.
632632
In turn, the strings fed to the <type>text</> data type's input routine
633633
become <literal>\</> and <literal>"</> respectively. (If we were working
634634
with a data type whose input routine also treated backslashes specially,
635635
<type>bytea</> for example, we might need as many as eight backslashes
636636
in the command to get one backslash into the stored array element.)
637-
Dollar quoting (see <xref linkend="sql-syntax-dollar-quoting">)may be
637+
Dollar quoting (see <xref linkend="sql-syntax-dollar-quoting">)can be
638638
used to avoid the need to double backslashes.
639639
</para>
640640
</note>

‎doc/src/sgml/datatype.sgml

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/datatype.sgml,v 1.187 2007/01/29 13:24:30 petere Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/datatype.sgml,v 1.188 2007/01/30 22:29:22 momjian Exp $ -->
22

33
<chapter id="datatype">
44
<title id="datatype-title">Data Types</title>
@@ -1152,11 +1152,9 @@ SELECT b, char_length(b) FROM test2;
11521152
of a string literal in an <acronym>SQL</acronym> statement. In
11531153
general, to escape an octet, it is converted into the three-digit
11541154
octal number equivalent of its decimal octet value, and preceded
1155-
by two backslashes (or one backslash if
1156-
<varname>standard_conforming_strings</> is <literal>off</>).
1157-
<xref linkend="datatype-binary-sqlesc"> shows the characters
1158-
that must be escaped, and gives the alternate escape sequences
1159-
where applicable.
1155+
by two backslashes. <xref linkend="datatype-binary-sqlesc">
1156+
shows the characters that must be escaped, and gives the alternate
1157+
escape sequences where applicable.
11601158
</para>
11611159

11621160
<table id="datatype-binary-sqlesc">
@@ -1176,32 +1174,32 @@ SELECT b, char_length(b) FROM test2;
11761174
<row>
11771175
<entry>0</entry>
11781176
<entry>zero octet</entry>
1179-
<entry><literal>'\\000'</literal></entry>
1180-
<entry><literal>SELECT '\\000'::bytea;</literal></entry>
1177+
<entry><literal>E'\\000'</literal></entry>
1178+
<entry><literal>SELECTE'\\000'::bytea;</literal></entry>
11811179
<entry><literal>\000</literal></entry>
11821180
</row>
11831181

11841182
<row>
11851183
<entry>39</entry>
11861184
<entry>single quote</entry>
1187-
<entry><literal>'\''</literal> or <literal>'\\047'</literal></entry>
1188-
<entry><literal>SELECT '\''::bytea;</literal></entry>
1185+
<entry><literal>''''</literal> or <literal>E'\\047'</literal></entry>
1186+
<entry><literal>SELECTE'\''::bytea;</literal></entry>
11891187
<entry><literal>'</literal></entry>
11901188
</row>
11911189

11921190
<row>
11931191
<entry>92</entry>
11941192
<entry>backslash</entry>
1195-
<entry><literal>'\\\\'</literal> or <literal>'\\134'</literal></entry>
1196-
<entry><literal>SELECT '\\\\'::bytea;</literal></entry>
1193+
<entry><literal>E'\\\\'</literal> or <literal>E'\\134'</literal></entry>
1194+
<entry><literal>SELECTE'\\\\'::bytea;</literal></entry>
11971195
<entry><literal>\\</literal></entry>
11981196
</row>
11991197

12001198
<row>
12011199
<entry>0 to 31 and 127 to 255</entry>
12021200
<entry><quote>non-printable</quote> octets</entry>
1203-
<entry><literal>'\\<replaceable>xxx'</></literal> (octal value)</entry>
1204-
<entry><literal>SELECT '\\001'::bytea;</literal></entry>
1201+
<entry><literal>E'\\<replaceable>xxx'</></literal> (octal value)</entry>
1202+
<entry><literal>SELECTE'\\001'::bytea;</literal></entry>
12051203
<entry><literal>\001</literal></entry>
12061204
</row>
12071205

@@ -1224,18 +1222,18 @@ SELECT b, char_length(b) FROM test2;
12241222
string written as a string literal must pass through two parse
12251223
phases in the <productname>PostgreSQL</productname> server.
12261224
The first backslash of each pair is interpreted as an escape
1227-
character by the string-literal parser (assuming
1228-
<varname>standard_conforming_strings</> is<literal>off</>)
1229-
and is therefore consumed, leaving the second backslash of the
1230-
pair. The remaining backslash is then recognized by the
1225+
character by the string-literal parser (assuming escape string
1226+
syntax isused) and is therefore consumed, leaving the second backslash of the
1227+
pair. (Dollar-quoted strings can be used to avoid this level
1228+
of escaping.) The remaining backslash is then recognized by the
12311229
<type>bytea</type> input function as starting either a three
12321230
digit octal value or escaping another backslash. For example,
1233-
a string literal passed to the server as <literal>'\\001'</literal>
1231+
a string literal passed to the server as <literal>E'\\001'</literal>
12341232
becomes <literal>\001</literal> after passing through the
1235-
string-literal parser. The <literal>\001</literal> is then sent
1233+
escapestring parser. The <literal>\001</literal> is then sent
12361234
to the <type>bytea</type> input function, where it is converted
12371235
to a single octet with a decimal value of 1. Note that the
1238-
apostrophe character is not treated specially by <type>bytea</type>,
1236+
single-quote character is not treated specially by <type>bytea</type>,
12391237
so it follows the normal rules for string literals. (See also
12401238
<xref linkend="sql-syntax-strings">.)
12411239
</para>
@@ -1269,23 +1267,23 @@ SELECT b, char_length(b) FROM test2;
12691267
<entry>92</entry>
12701268
<entry>backslash</entry>
12711269
<entry><literal>\\</literal></entry>
1272-
<entry><literal>SELECT '\\134'::bytea;</literal></entry>
1270+
<entry><literal>SELECTE'\\134'::bytea;</literal></entry>
12731271
<entry><literal>\\</literal></entry>
12741272
</row>
12751273

12761274
<row>
12771275
<entry>0 to 31 and 127 to 255</entry>
12781276
<entry><quote>non-printable</quote> octets</entry>
12791277
<entry><literal>\<replaceable>xxx</></literal> (octal value)</entry>
1280-
<entry><literal>SELECT '\\001'::bytea;</literal></entry>
1278+
<entry><literal>SELECTE'\\001'::bytea;</literal></entry>
12811279
<entry><literal>\001</literal></entry>
12821280
</row>
12831281

12841282
<row>
12851283
<entry>32 to 126</entry>
12861284
<entry><quote>printable</quote> octets</entry>
12871285
<entry>client character set representation</entry>
1288-
<entry><literal>SELECT '\\176'::bytea;</literal></entry>
1286+
<entry><literal>SELECTE'\\176'::bytea;</literal></entry>
12891287
<entry><literal>~</literal></entry>
12901288
</row>
12911289

‎doc/src/sgml/func.sgml

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.354 2007/01/3002:39:27 momjian Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.355 2007/01/3022:29:22 momjian Exp $ -->
22

33
<chapter id="functions">
44
<title>Functions and Operators</title>
@@ -1339,7 +1339,7 @@
13391339
Encode binary data to <acronym>ASCII</acronym>-only representation. Supported
13401340
types are: <literal>base64</>, <literal>hex</>, <literal>escape</>.
13411341
</entry>
1342-
<entry><literal>encode( '123\\000\\001', 'base64')</literal></entry>
1342+
<entry><literal>encode(E'123\\000\\001', 'base64')</literal></entry>
13431343
<entry><literal>MTIzAAE=</literal></entry>
13441344
</row>
13451345

@@ -1439,7 +1439,7 @@
14391439
<entry>
14401440
Return the given string suitably quoted to be used as a string literal
14411441
in an <acronym>SQL</acronym> statement string.
1442-
Embedded quotes and backslashes are properly doubled.
1442+
Embeddedsingle-quotes and backslashes are properly doubled.
14431443
</entry>
14441444
<entry><literal>quote_literal( 'O\'Reilly')</literal></entry>
14451445
<entry><literal>'O''Reilly'</literal></entry>
@@ -2393,7 +2393,7 @@
23932393
<secondary>concatenation</secondary>
23942394
</indexterm>
23952395
</entry>
2396-
<entry><literal>'\\\\Post'::bytea || '\\047gres\\000'::bytea</literal></entry>
2396+
<entry><literal>E'\\\\Post'::bytea ||E'\\047gres\\000'::bytea</literal></entry>
23972397
<entry><literal>\\Post'gres\000</literal></entry>
23982398
</row>
23992399

@@ -2406,7 +2406,7 @@
24062406
<primary>get_bit</primary>
24072407
</indexterm>
24082408
</entry>
2409-
<entry><literal>get_bit('Th\\000omas'::bytea, 45)</literal></entry>
2409+
<entry><literal>get_bit(E'Th\\000omas'::bytea, 45)</literal></entry>
24102410
<entry><literal>1</literal></entry>
24112411
</row>
24122412

@@ -2419,23 +2419,23 @@
24192419
<primary>get_byte</primary>
24202420
</indexterm>
24212421
</entry>
2422-
<entry><literal>get_byte('Th\\000omas'::bytea, 4)</literal></entry>
2422+
<entry><literal>get_byte(E'Th\\000omas'::bytea, 4)</literal></entry>
24232423
<entry><literal>109</literal></entry>
24242424
</row>
24252425

24262426
<row>
24272427
<entry><literal><function>octet_length</function>(<parameter>string</parameter>)</literal></entry>
24282428
<entry><type>int</type></entry>
24292429
<entry>Number of bytes in binary string</entry>
2430-
<entry><literal>octet_length( 'jo\\000se'::bytea)</literal></entry>
2430+
<entry><literal>octet_length(E'jo\\000se'::bytea)</literal></entry>
24312431
<entry><literal>5</literal></entry>
24322432
</row>
24332433

24342434
<row>
24352435
<entry><literal><function>position</function>(<parameter>substring</parameter> in <parameter>string</parameter>)</literal></entry>
24362436
<entry><type>int</type></entry>
24372437
<entry>Location of specified substring</entry>
2438-
<entry><literal>position('\\000om'::bytea in 'Th\\000omas'::bytea)</literal></entry>
2438+
<entry><literal>position(E'\\000om'::bytea inE'Th\\000omas'::bytea)</literal></entry>
24392439
<entry><literal>3</literal></entry>
24402440
</row>
24412441

@@ -2449,7 +2449,7 @@
24492449
<primary>set_bit</primary>
24502450
</indexterm>
24512451
</entry>
2452-
<entry><literal>set_bit('Th\\000omas'::bytea, 45, 0)</literal></entry>
2452+
<entry><literal>set_bit(E'Th\\000omas'::bytea, 45, 0)</literal></entry>
24532453
<entry><literal>Th\000omAs</literal></entry>
24542454
</row>
24552455

@@ -2463,7 +2463,7 @@
24632463
<primary>set_byte</primary>
24642464
</indexterm>
24652465
</entry>
2466-
<entry><literal>set_byte('Th\\000omas'::bytea, 4, 64)</literal></entry>
2466+
<entry><literal>set_byte(E'Th\\000omas'::bytea, 4, 64)</literal></entry>
24672467
<entry><literal>Th\000o@as</literal></entry>
24682468
</row>
24692469

@@ -2476,7 +2476,7 @@
24762476
<primary>substring</primary>
24772477
</indexterm>
24782478
</entry>
2479-
<entry><literal>substring('Th\\000omas'::bytea from 2 for 3)</literal></entry>
2479+
<entry><literal>substring(E'Th\\000omas'::bytea from 2 for 3)</literal></entry>
24802480
<entry><literal>h\000o</literal></entry>
24812481
</row>
24822482

@@ -2492,7 +2492,7 @@
24922492
<parameter>bytes</parameter> from the start
24932493
and end of <parameter>string</parameter>
24942494
</entry>
2495-
<entry><literal>trim('\\000'::bytea from '\\000Tom\\000'::bytea)</literal></entry>
2495+
<entry><literal>trim(E'\\000'::bytea fromE'\\000Tom\\000'::bytea)</literal></entry>
24962496
<entry><literal>Tom</literal></entry>
24972497
</row>
24982498
</tbody>
@@ -2530,7 +2530,7 @@
25302530
in <parameter>bytes</parameter> from the start and end of
25312531
<parameter>string</parameter>
25322532
</entry>
2533-
<entry><literal>btrim('\\000trim\\000'::bytea, '\\000'::bytea)</literal></entry>
2533+
<entry><literal>btrim(E'\\000trim\\000'::bytea,E'\\000'::bytea)</literal></entry>
25342534
<entry><literal>trim</literal></entry>
25352535
</row>
25362536

@@ -2544,7 +2544,7 @@
25442544
Decode binary string from <parameter>string</parameter> previously
25452545
encoded with <function>encode</>. Parameter type is same as in <function>encode</>.
25462546
</entry>
2547-
<entry><literal>decode('123\\000456', 'escape')</literal></entry>
2547+
<entry><literal>decode(E'123\\000456', 'escape')</literal></entry>
25482548
<entry><literal>123\000456</literal></entry>
25492549
</row>
25502550

@@ -2558,7 +2558,7 @@
25582558
Encode binary string to <acronym>ASCII</acronym>-only representation. Supported
25592559
types are: <literal>base64</>, <literal>hex</>, <literal>escape</>.
25602560
</entry>
2561-
<entry><literal>encode('123\\000456'::bytea, 'escape')</literal></entry>
2561+
<entry><literal>encode(E'123\\000456'::bytea, 'escape')</literal></entry>
25622562
<entry><literal>123\000456</literal></entry>
25632563
</row>
25642564

@@ -2577,7 +2577,7 @@
25772577
<see>binary strings, length</see>
25782578
</indexterm>
25792579
</entry>
2580-
<entry><literal>length('jo\\000se'::bytea)</literal></entry>
2580+
<entry><literal>length(E'jo\\000se'::bytea)</literal></entry>
25812581
<entry><literal>5</literal></entry>
25822582
</row>
25832583

@@ -2588,7 +2588,7 @@
25882588
Calculates the MD5 hash of <parameter>string</parameter>,
25892589
returning the result in hexadecimal
25902590
</entry>
2591-
<entry><literal>md5('Th\\000omas'::bytea)</literal></entry>
2591+
<entry><literal>md5(E'Th\\000omas'::bytea)</literal></entry>
25922592
<entry><literal>8ab2d3c9689aaf18 b4958c334c82d8b1</literal></entry>
25932593
</row>
25942594
</tbody>
@@ -2812,7 +2812,8 @@ cast(-44 as bit(12)) <lineannotation>111111010100</lineannotation>
28122812
<para>
28132813
Note that the backslash already has a special meaning in string
28142814
literals, so to write a pattern constant that contains a backslash
2815-
you must write two backslashes in an SQL statement. Thus, writing a pattern
2815+
you must write two backslashes in an SQL statement (assuming escape
2816+
string syntax is used). Thus, writing a pattern
28162817
that actually matches a literal backslash means writing four backslashes
28172818
in the statement. You can avoid this by selecting a different escape
28182819
character with <literal>ESCAPE</literal>; then a backslash is not special
@@ -3106,7 +3107,7 @@ substring('foobar' from 'o(.)b') <lineannotation>o</lineannotation>
31063107
substring matching the entire pattern should be inserted. Write
31073108
<literal>\\</> if you need to put a literal backslash in the replacement
31083109
text. (As always, remember to double backslashes written in literal
3109-
constant strings.)
3110+
constant strings, assuming escape string syntax is used.)
31103111
The <replaceable>flags</> parameter is an optional text
31113112
string containing zero or more single-letter flags that change the
31123113
function's behavior. Flag <literal>i</> specifies case-insensitive
@@ -3121,7 +3122,7 @@ regexp_replace('foobarbaz', 'b..', 'X')
31213122
<lineannotation>fooXbaz</lineannotation>
31223123
regexp_replace('foobarbaz', 'b..', 'X', 'g')
31233124
<lineannotation>fooXX</lineannotation>
3124-
regexp_replace('foobarbaz', 'b(..)', 'X\\1Y', 'g')
3125+
regexp_replace('foobarbaz', 'b(..)',E'X\\1Y', 'g')
31253126
<lineannotation>fooXarYXazY</lineannotation>
31263127
</programlisting>
31273128
</para>
@@ -3283,7 +3284,8 @@ regexp_replace('foobarbaz', 'b(..)', 'X\\1Y', 'g')
32833284
Remember that the backslash (<literal>\</literal>) already has a special
32843285
meaning in <productname>PostgreSQL</> string literals.
32853286
To write a pattern constant that contains a backslash,
3286-
you must write two backslashes in the statement.
3287+
you must write two backslashes in the statement, assuming escape
3288+
string syntax is used.
32873289
</para>
32883290
</note>
32893291

@@ -3594,7 +3596,7 @@ regexp_replace('foobarbaz', 'b(..)', 'X\\1Y', 'g')
35943596
Keep in mind that an escape's leading <literal>\</> will need to be
35953597
doubled when entering the pattern as an SQL string constant. For example:
35963598
<programlisting>
3597-
'123' ~ '^\\d{3}' <lineannotation>true</lineannotation>
3599+
'123' ~E'^\\d{3}' <lineannotation>true</lineannotation>
35983600
</programlisting>
35993601
</para>
36003602
</note>
@@ -4756,10 +4758,10 @@ SELECT SUBSTRING('XY1234Z', 'Y*?([0-9]{1,3})');
47564758
<listitem>
47574759
<para>
47584760
If you want to have a double quote in the output you must
4759-
precede it with a backslash, for example <literal>'\\"YYYY
4761+
precede it with a backslash, for example <literal>E'\\"YYYY
47604762
Month\\"'</literal>. <!-- "" font-lock sanity :-) -->
47614763
(Two backslashes are necessary because the backslash already
4762-
has a special meaningin astringconstant.)
4764+
has a special meaningwhen using the escapestringsyntax.)
47634765
</para>
47644766
</listitem>
47654767

‎doc/src/sgml/libpq.sgml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/libpq.sgml,v 1.221 2006/12/19 01:53:36 adunstan Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/libpq.sgml,v 1.222 2007/01/30 22:29:22 momjian Exp $ -->
22

33
<chapter id="libpq">
44
<title><application>libpq</application> - C Library</title>
@@ -916,7 +916,7 @@ in a numeric form that is much easier to compare against.
916916

917917
<para>
918918
If no value for <literal>standard_conforming_strings</> is reported,
919-
applications may assume it is <literal>false</>, that is, backslashes
919+
applications may assume it is <literal>off</>, that is, backslashes
920920
are treated as escapes in string literals. Also, the presence of this
921921
parameter may be taken as an indication that the escape string syntax
922922
(<literal>E'...'</>) is accepted.
@@ -2494,7 +2494,7 @@ unsigned char *PQescapeByteaConn(PGconn *conn,
24942494
of a <type>bytea</type> literal in an <acronym>SQL</acronym>
24952495
statement. In general, to escape a byte, it is converted into the
24962496
three digit octal number equal to the octet value, and preceded by
2497-
one or two backslashes. The single quote (<literal>'</>) and backslash
2497+
usually two backslashes. The single quote (<literal>'</>) and backslash
24982498
(<literal>\</>) characters have special alternative escape
24992499
sequences. See <xref linkend="datatype-binary"> for more
25002500
information. <function>PQescapeByteaConn</function> performs this

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp