Skip to content

Commit bb389ad

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 6c1a257 commit bb389ad

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
@@ -1321,11 +1321,12 @@
13211321
</entry>
13221322
<entry><type>text</type></entry>
13231323
<entry>
1324-
Remove the longest string containing only the
1324+
Remove the longest string containing only characters from
13251325
<parameter>characters</parameter> (a space by default) from the
1326-
start/end/both ends of the <parameter>string</parameter>
1326+
start, end, or both ends (<literal>both</> is the default)
1327+
of <parameter>string</parameter>
13271328
</entry>
1328-
<entry><literal>trim(both 'x' from 'xTomxx')</literal></entry>
1329+
<entry><literal>trim(both 'xyz' from 'yxTomxx')</literal></entry>
13291330
<entry><literal>Tom</literal></entry>
13301331
</row>
13311332

@@ -1334,14 +1335,14 @@
13341335
<literal><function>trim(<optional>leading | trailing
13351336
| both</optional> <optional>from</optional>
13361337
<parameter>string</parameter>
1337-
<optional><parameter>, characters</parameter></optional>
1338+
<optional>, <parameter>characters</parameter></optional>
13381339
)</function></literal>
13391340
</entry>
13401341
<entry><type>text</type></entry>
13411342
<entry>
1342-
Non-standard version of <function>trim()</>
1343+
Non-standard syntax for <function>trim()</>
13431344
</entry>
1344-
<entry><literal>trim(both from 'xTomxx', 'x')</literal></entry>
1345+
<entry><literal>trim(both from 'yxTomxx', 'xyz')</literal></entry>
13451346
<entry><literal>Tom</literal></entry>
13461347
</row>
13471348

@@ -1413,7 +1414,7 @@
14131414
in <parameter>characters</parameter> (a space by default)
14141415
from the start and end of <parameter>string</parameter>
14151416
</entry>
1416-
<entry><literal>btrim('xyxtrimyyx', 'xy')</literal></entry>
1417+
<entry><literal>btrim('xyxtrimyyx', 'xyz')</literal></entry>
14171418
<entry><literal>trim</literal></entry>
14181419
</row>
14191420

@@ -1682,8 +1683,8 @@
16821683
<parameter>characters</parameter> (a space by default) from the start of
16831684
<parameter>string</parameter>
16841685
</entry>
1685-
<entry><literal>ltrim('zzzytrim', 'xyz')</literal></entry>
1686-
<entry><literal>trim</literal></entry>
1686+
<entry><literal>ltrim('zzzytest', 'xyz')</literal></entry>
1687+
<entry><literal>test</literal></entry>
16871688
</row>
16881689

16891690
<row>
@@ -1965,8 +1966,8 @@
19651966
<parameter>characters</parameter> (a space by default) from the end of
19661967
<parameter>string</parameter>
19671968
</entry>
1968-
<entry><literal>rtrim('trimxxxx', 'x')</literal></entry>
1969-
<entry><literal>trim</literal></entry>
1969+
<entry><literal>rtrim('testxxzx', 'xyz')</literal></entry>
1970+
<entry><literal>test</literal></entry>
19701971
</row>
19711972

19721973
<row>
@@ -3231,11 +3232,11 @@ SELECT format('Testing %3$s, %2$s, %s', 'one', 'two', 'three');
32313232
</entry>
32323233
<entry><type>bytea</type></entry>
32333234
<entry>
3234-
Remove the longest string containing only the bytes in
3235+
Remove the longest string containing only bytes appearing in
32353236
<parameter>bytes</parameter> from the start
32363237
and end of <parameter>string</parameter>
32373238
</entry>
3238-
<entry><literal>trim(E'\\000'::bytea from E'\\000Tom\\000'::bytea)</literal></entry>
3239+
<entry><literal>trim(E'\\000\\001'::bytea from E'\\000Tom\\001'::bytea)</literal></entry>
32393240
<entry><literal>Tom</literal></entry>
32403241
</row>
32413242
</tbody>
@@ -3274,11 +3275,11 @@ SELECT format('Testing %3$s, %2$s, %s', 'one', 'two', 'three');
32743275
</entry>
32753276
<entry><type>bytea</type></entry>
32763277
<entry>
3277-
Remove the longest string consisting only of bytes
3278-
in <parameter>bytes</parameter> from the start and end of
3278+
Remove the longest string containing only bytes appearing in
3279+
<parameter>bytes</parameter> from the start and end of
32793280
<parameter>string</parameter>
32803281
</entry>
3281-
<entry><literal>btrim(E'\\000trim\\000'::bytea, E'\\000'::bytea)</literal></entry>
3282+
<entry><literal>btrim(E'\\000trim\\001'::bytea, E'\\000\\001'::bytea)</literal></entry>
32823283
<entry><literal>trim</literal></entry>
32833284
</row>
32843285

0 commit comments

Comments
 (0)