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>
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
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>
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
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
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
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
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
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
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>
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
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
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
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
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>
31223123regexp_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 a stringconstant .)
4764+ has a special meaningwhen using the escape stringsyntax .)
47634765 </para>
47644766 </listitem>
47654767