Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 213c0f2

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 021d254 commit 213c0f2

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

doc/src/sgml/func.sgml

+17-16
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>
@@ -2218,8 +2219,8 @@
22182219
<parameter>characters</parameter> (a space by default) from the end of
22192220
<parameter>string</parameter>
22202221
</entry>
2221-
<entry><literal>rtrim('trimxxxx', 'x')</literal></entry>
2222-
<entry><literal>trim</literal></entry>
2222+
<entry><literal>rtrim('testxxzx', 'xyz')</literal></entry>
2223+
<entry><literal>test</literal></entry>
22232224
</row>
22242225

22252226
<row>
@@ -3484,11 +3485,11 @@ SELECT format('Testing %3$s, %2$s, %s', 'one', 'two', 'three');
34843485
</entry>
34853486
<entry><type>bytea</type></entry>
34863487
<entry>
3487-
Remove the longest string containing only the bytes in
3488+
Remove the longest string containing only bytes appearing in
34883489
<parameter>bytes</parameter> from the start
34893490
and end of <parameter>string</parameter>
34903491
</entry>
3491-
<entry><literal>trim(E'\\000'::bytea from E'\\000Tom\\000'::bytea)</literal></entry>
3492+
<entry><literal>trim(E'\\000\\001'::bytea from E'\\000Tom\\001'::bytea)</literal></entry>
34923493
<entry><literal>Tom</literal></entry>
34933494
</row>
34943495
</tbody>
@@ -3527,11 +3528,11 @@ SELECT format('Testing %3$s, %2$s, %s', 'one', 'two', 'three');
35273528
</entry>
35283529
<entry><type>bytea</type></entry>
35293530
<entry>
3530-
Remove the longest string consisting only of bytes
3531-
in <parameter>bytes</parameter> from the start and end of
3531+
Remove the longest string containing only bytes appearing in
3532+
<parameter>bytes</parameter> from the start and end of
35323533
<parameter>string</parameter>
35333534
</entry>
3534-
<entry><literal>btrim(E'\\000trim\\000'::bytea, E'\\000'::bytea)</literal></entry>
3535+
<entry><literal>btrim(E'\\000trim\\001'::bytea, E'\\000\\001'::bytea)</literal></entry>
35353536
<entry><literal>trim</literal></entry>
35363537
</row>
35373538

0 commit comments

Comments
 (0)