Skip to content

Commit d1ca2a1

Browse files
committed
Update examples for string-related functions.
In the example for decode(), show the bytea result in hex format, since that's now the default. Use an E'' string in the example for quote_literal(), so that it works regardless of the standard_conforming_strings setting. On the functions-for-binary-strings page, leave the examples as-is for readability, but add a note pointing out that they are shown in escape format. Per comments from Thom Brown. Also, improve the description for encode() and decode() a tad. Backpatch to 9.0, where bytea_output was introduced.
1 parent f1d8692 commit d1ca2a1

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

doc/src/sgml/func.sgml

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1427,27 +1427,27 @@
14271427
<row>
14281428
<entry>
14291429
<literal><function>decode(<parameter>string</parameter> <type>text</type>,
1430-
<parameter>type</parameter> <type>text</type>)</function></literal>
1430+
<parameter>format</parameter> <type>text</type>)</function></literal>
14311431
</entry>
14321432
<entry><type>bytea</type></entry>
14331433
<entry>
1434-
Decode binary data from <parameter>string</parameter> previously
1435-
encoded with <function>encode</>. Parameter type is same as in <function>encode</>.
1434+
Decode binary data from textual representation in <parameter>string</>.
1435+
Options for <parameter>format</> are same as in <function>encode</>.
14361436
</entry>
14371437
<entry><literal>decode('MTIzAAE=', 'base64')</literal></entry>
1438-
<entry><literal>123\000\001</literal></entry>
1438+
<entry><literal>x3132330001</literal></entry>
14391439
</row>
14401440

14411441
<row>
14421442
<entry>
14431443
<literal><function>encode(<parameter>data</parameter> <type>bytea</type>,
1444-
<parameter>type</parameter> <type>text</type>)</function></literal>
1444+
<parameter>format</parameter> <type>text</type>)</function></literal>
14451445
</entry>
14461446
<entry><type>text</type></entry>
14471447
<entry>
1448-
Encode binary data to different representation. Supported
1449-
types are: <literal>base64</>, <literal>hex</>, <literal>escape</>.
1450-
<literal>Escape</> merely outputs null bytes as <literal>\000</> and
1448+
Encode binary data into a textual representation. Supported
1449+
formats are: <literal>base64</>, <literal>hex</>, <literal>escape</>.
1450+
<literal>escape</> merely outputs null bytes as <literal>\000</> and
14511451
doubles backslashes.
14521452
</entry>
14531453
<entry><literal>encode(E'123\\000\\001', 'base64')</literal></entry>
@@ -1570,7 +1570,7 @@
15701570
<function>quote_nullable</function> is often more suitable.
15711571
See also <xref linkend="plpgsql-quote-literal-example">.
15721572
</entry>
1573-
<entry><literal>quote_literal('O\'Reilly')</literal></entry>
1573+
<entry><literal>quote_literal(E'O\'Reilly')</literal></entry>
15741574
<entry><literal>'O''Reilly'</literal></entry>
15751575
</row>
15761576

@@ -2620,6 +2620,14 @@
26202620
(see <xref linkend="functions-binarystring-other">).
26212621
</para>
26222622

2623+
<note>
2624+
<para>
2625+
The sample results shown on this page assume that the server parameter
2626+
<link linkend="guc-bytea-output"><varname>bytea_output</></link> is set
2627+
to <literal>escape</literal> (the traditional PostgreSQL format).
2628+
</para>
2629+
</note>
2630+
26232631
<table id="functions-binarystring-sql">
26242632
<title><acronym>SQL</acronym> Binary String Functions and Operators</title>
26252633
<tgroup cols="5">

0 commit comments

Comments
 (0)