|
1 | 1 | --- |
2 | 2 | title: TRIM |
3 | 3 | --- |
| 4 | +import FunctionDescription from '@site/src/components/FunctionDescription'; |
4 | 5 |
|
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). |
7 | 9 |
|
8 | 10 | ## Syntax |
9 | 11 |
|
10 | 12 | ```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>) |
12 | 21 | ``` |
13 | 22 |
|
14 | 23 | ## Examples |
15 | 24 |
|
16 | | -Please note that ALL the examples in this section will return the string 'databend'. |
17 | | - |
18 | 25 | The following example removes the leading and trailing string 'xxx' from the string 'xxxdatabendxxx': |
19 | 26 |
|
20 | 27 | ```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 | +└─────────────────────────────────────────────────────────────────────────────────┘ |
22 | 35 | ``` |
23 | 36 |
|
24 | 37 | The following example removes the leading string 'xxx' from the string 'xxxdatabend': |
25 | 38 |
|
26 | 39 | ```sql |
27 | 40 | SELECT TRIM(LEADING 'xxx' FROM 'xxxdatabend' ); |
| 41 | + |
| 42 | +┌────────────────────────────────────────┐ |
| 43 | +│ TRIM(LEADING 'xxx' FROM 'xxxdatabend') │ |
| 44 | +├────────────────────────────────────────┤ |
| 45 | +│ databend │ |
| 46 | +└────────────────────────────────────────┘ |
28 | 47 | ``` |
| 48 | + |
29 | 49 | The following example removes the trailing string 'xxx' from the string 'databendxxx': |
30 | 50 |
|
31 | 51 | ```sql |
32 | 52 | SELECT TRIM(TRAILING 'xxx' FROM 'databendxxx' ); |
| 53 | + |
| 54 | +┌─────────────────────────────────────────┐ |
| 55 | +│ TRIM(TRAILING 'xxx' FROM 'databendxxx') │ |
| 56 | +├─────────────────────────────────────────┤ |
| 57 | +│ databend │ |
| 58 | +└─────────────────────────────────────────┘ |
33 | 59 | ``` |
34 | 60 |
|
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: |
36 | 62 |
|
37 | 63 | ```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 | +└────────────────────────────────────────────────────────────────────┘ |
41 | 72 | ``` |
0 commit comments