Skip to content

Commit 6554d5d

Browse files
committed
Update trim.md
1 parent 886f94c commit 6554d5d

File tree

1 file changed

+41
-10
lines changed
  • docs/en/sql-reference/20-sql-functions/06-string-functions

1 file changed

+41
-10
lines changed
Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,72 @@
11
---
22
title: TRIM
33
---
4+
import FunctionDescription from '@site/src/components/FunctionDescription';
45

5-
Returns the string without leading or trailing occurrences of the specified remove string. If remove string
6-
is omitted, spaces are removed.
6+
<FunctionDescription description="Introduced or updated: v1.2.659"/>
7+
8+
Removes specific characters or spaces from a string, optionally specifying the position (BOTH, LEADING, or TRAILING).
79

810
## Syntax
911

1012
```sql
11-
TRIM([{BOTH | LEADING | TRAILING} [remstr] FROM ] str)
13+
-- Trim specific characters and specify the position
14+
TRIM({ BOTH | LEADING | TRAILING } <trim_character> FROM <string>)
15+
16+
-- Trim specific characters from both sides (default BOTH)
17+
TRIM(<string>, <trim_character>)
18+
19+
-- Trim spaces from both sides
20+
TRIM(<string>)
1221
```
1322

1423
## Examples
1524

16-
Please note that ALL the examples in this section will return the string 'databend'.
17-
1825
The following example removes the leading and trailing string 'xxx' from the string 'xxxdatabendxxx':
1926

2027
```sql
21-
SELECT TRIM(BOTH 'xxx' FROM 'xxxdatabendxxx');
28+
SELECT TRIM(BOTH 'xxx' FROM 'xxxdatabendxxx'), TRIM('xxxdatabendxxx', 'xxx');
29+
30+
┌─────────────────────────────────────────────────────────────────────────────────┐
31+
TRIM(BOTH 'xxx' FROM 'xxxdatabendxxx') │ TRIM(BOTH 'xxx' FROM 'xxxdatabendxxx') │
32+
├────────────────────────────────────────┼────────────────────────────────────────┤
33+
│ databend │ databend │
34+
└─────────────────────────────────────────────────────────────────────────────────┘
2235
```
2336

2437
The following example removes the leading string 'xxx' from the string 'xxxdatabend':
2538

2639
```sql
2740
SELECT TRIM(LEADING 'xxx' FROM 'xxxdatabend' );
41+
42+
┌────────────────────────────────────────┐
43+
TRIM(LEADING 'xxx' FROM 'xxxdatabend') │
44+
├────────────────────────────────────────┤
45+
│ databend │
46+
└────────────────────────────────────────┘
2847
```
48+
2949
The following example removes the trailing string 'xxx' from the string 'databendxxx':
3050

3151
```sql
3252
SELECT TRIM(TRAILING 'xxx' FROM 'databendxxx' );
53+
54+
┌─────────────────────────────────────────┐
55+
TRIM(TRAILING 'xxx' FROM 'databendxxx') │
56+
├─────────────────────────────────────────┤
57+
│ databend │
58+
└─────────────────────────────────────────┘
3359
```
3460

35-
If no remove string is specified, the function removes all leading and trailing spaces. The following examples remove the leading and/or trailing spaces:
61+
The following examples remove the leading and/or trailing spaces:
3662

3763
```sql
38-
SELECT TRIM(' databend ');
39-
SELECT TRIM(' databend');
40-
SELECT TRIM('databend ');
64+
SELECT TRIM(' databend '), TRIM(' databend'), TRIM('databend ');
65+
66+
┌────────────────────────────────────────────────────────────────────┐
67+
TRIM(' databend ') │ TRIM(' databend') │ TRIM('databend ') │
68+
│ String │ String │ String │
69+
├────────────────────────┼─────────────────────┼─────────────────────┤
70+
│ databend │ databend │ databend │
71+
└────────────────────────────────────────────────────────────────────┘
4172
```

0 commit comments

Comments
 (0)