Skip to content

Commit dd3edfe

Browse files
committed
Doc: improve description of trim() and related functions.
Per bug #14441 from Mark Pether, the documentation could be misread, mainly because some of the examples failed to show what happens with a multicharacter "characters to trim" string. Also, while the text description in most of these entries was fairly clear that the "characters" argument is a set of characters not a substring to match, some of them used variant wording that was a bit less clear. trim() itself suffered from both deficiencies and was thus pretty misinterpretable. Also fix failure to explain which of LEADING/TRAILING/BOTH is the default. Discussion: https://postgr.es/m/20161130011710.6539.53657@wrigleys.postgresql.org
1 parent e5b8aa6 commit dd3edfe

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

doc/src/sgml/func.sgml

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1534,11 +1534,12 @@
15341534
</entry>
15351535
<entry><type>text</type></entry>
15361536
<entry>
1537-
Remove the longest string containing only the
1537+
Remove the longest string containing only characters from
15381538
<parameter>characters</parameter> (a space by default) from the
1539-
start/end/both ends of the <parameter>string</parameter>
1539+
start, end, or both ends (<literal>both</> is the default)
1540+
of <parameter>string</parameter>
15401541
</entry>
1541-
<entry><literal>trim(both 'x' from 'xTomxx')</literal></entry>
1542+
<entry><literal>trim(both 'xyz' from 'yxTomxx')</literal></entry>
15421543
<entry><literal>Tom</literal></entry>
15431544
</row>
15441545

@@ -1547,14 +1548,14 @@
15471548
<literal><function>trim(<optional>leading | trailing
15481549
| both</optional> <optional>from</optional>
15491550
<parameter>string</parameter>
1550-
<optional><parameter>, characters</parameter></optional>
1551+
<optional>, <parameter>characters</parameter></optional>
15511552
)</function></literal>
15521553
</entry>
15531554
<entry><type>text</type></entry>
15541555
<entry>
1555-
Non-standard version of <function>trim()</>
1556+
Non-standard syntax for <function>trim()</>
15561557
</entry>
1557-
<entry><literal>trim(both from 'xTomxx', 'x')</literal></entry>
1558+
<entry><literal>trim(both from 'yxTomxx', 'xyz')</literal></entry>
15581559
<entry><literal>Tom</literal></entry>
15591560
</row>
15601561

@@ -1626,7 +1627,7 @@
16261627
in <parameter>characters</parameter> (a space by default)
16271628
from the start and end of <parameter>string</parameter>
16281629
</entry>
1629-
<entry><literal>btrim('xyxtrimyyx', 'xy')</literal></entry>
1630+
<entry><literal>btrim('xyxtrimyyx', 'xyz')</literal></entry>
16301631
<entry><literal>trim</literal></entry>
16311632
</row>
16321633

@@ -1895,8 +1896,8 @@
18951896
<parameter>characters</parameter> (a space by default) from the start of
18961897
<parameter>string</parameter>
18971898
</entry>
1898-
<entry><literal>ltrim('zzzytrim', 'xyz')</literal></entry>
1899-
<entry><literal>trim</literal></entry>
1899+
<entry><literal>ltrim('zzzytest', 'xyz')</literal></entry>
1900+
<entry><literal>test</literal></entry>
19001901
</row>
19011902

19021903
<row>
@@ -2201,8 +2202,8 @@
22012202
<parameter>characters</parameter> (a space by default) from the end of
22022203
<parameter>string</parameter>
22032204
</entry>
2204-
<entry><literal>rtrim('trimxxxx', 'x')</literal></entry>
2205-
<entry><literal>trim</literal></entry>
2205+
<entry><literal>rtrim('testxxzx', 'xyz')</literal></entry>
2206+
<entry><literal>test</literal></entry>
22062207
</row>
22072208

22082209
<row>
@@ -3467,11 +3468,11 @@ SELECT format('Testing %3$s, %2$s, %s', 'one', 'two', 'three');
34673468
</entry>
34683469
<entry><type>bytea</type></entry>
34693470
<entry>
3470-
Remove the longest string containing only the bytes in
3471+
Remove the longest string containing only bytes appearing in
34713472
<parameter>bytes</parameter> from the start
34723473
and end of <parameter>string</parameter>
34733474
</entry>
3474-
<entry><literal>trim(E'\\000'::bytea from E'\\000Tom\\000'::bytea)</literal></entry>
3475+
<entry><literal>trim(E'\\000\\001'::bytea from E'\\000Tom\\001'::bytea)</literal></entry>
34753476
<entry><literal>Tom</literal></entry>
34763477
</row>
34773478
</tbody>
@@ -3510,11 +3511,11 @@ SELECT format('Testing %3$s, %2$s, %s', 'one', 'two', 'three');
35103511
</entry>
35113512
<entry><type>bytea</type></entry>
35123513
<entry>
3513-
Remove the longest string consisting only of bytes
3514-
in <parameter>bytes</parameter> from the start and end of
3514+
Remove the longest string containing only bytes appearing in
3515+
<parameter>bytes</parameter> from the start and end of
35153516
<parameter>string</parameter>
35163517
</entry>
3517-
<entry><literal>btrim(E'\\000trim\\000'::bytea, E'\\000'::bytea)</literal></entry>
3518+
<entry><literal>btrim(E'\\000trim\\001'::bytea, E'\\000\\001'::bytea)</literal></entry>
35183519
<entry><literal>trim</literal></entry>
35193520
</row>
35203521

0 commit comments

Comments
 (0)