> ## Documentation Index
> Fetch the complete documentation index at: https://docs.firebolt.io/llms.txt
> Use this file to discover all available pages before exploring further.

# TRIM

> Reference material for TRIM function

Removes the longest string containing only characters in `<trim_characters>` from the left, right, or both sides of the source string `<expression>`. If no `<trim_characters>` parameter is specified, the longest string containing only whitespace characters (ASCII Decimal 32) is removed. If neither `LEADING`, `TRAILING`, nor `BOTH` are specified, characters are removed from both sides of the specified source string `<expression>`.

## Syntax

```sql theme={"theme":{"light":"css-variables","dark":"css-variables"}}
TRIM([LEADING | TRAILING | BOTH] [<trim_characters>] FROM <expression>)
```

## Parameters

| Parameter | Description | Supported input types | | |
| :- | :- | :- | - | - |
| \`LEADING | TRAILING | BOTH\` | Optional. Specifies from which part or parts of the `<expression>` to remove the specified `<trim_characters>`. | If omitted, this defaults to `BOTH`. `LEADING` - trims from the beginning of the specified string `TRAILING` - trims from the end of the specified string.  `BOTH` - trims from the beginning and the end of the specified string. |
| `<trim_characters>` | Optional. An expression that returns characters to trim from the right side of the `<expression>` string. If omitted, whitespace (ASCII Decimal 32) is trimmed. | `TEXT` | | |
| `<expression>` | An expression that returns the string to be trimmed. | `TEXT` | | |

## Return Type

`TEXT`

## Examples

The following example trims the characters `x` and `y` from the right side of a string, since the `TRAILING` parameter is specified. Note that the ordering of characters in `<trim_characters>` is irrelevant:

```
SELECT TRIM(TRAILING 'xy' FROM 'xyxyThe Acceleration Cupyyxx');
```

| rtrim text |
| :- |
| xyxyThe Acceleration Cup |

Rows: 1Execution time: 5.06ms

In the following example, no part of the string is specified for `TRIM`, so it defaults to `BOTH`.

```
SELECT TRIM('xy' FROM 'xyxyThe Acceleration Cupyyxx');
```

| btrim text |
| :- |
| The Acceleration Cup |

Rows: 1Execution time: 6.61ms

The following example omits the `<trim_characters>` parameter but specifies the `TRAILING` parameter, and thus trims whitespace from the right side of a string:

```
SELECT TRIM(TRAILING FROM '   The Acceleration Cup     ');
```

| rtrim text |
| :- |
| The Acceleration Cup |

Rows: 1Execution time: 5.53ms

The following example omits the `<trim_characters>` parameter and specifies no part of the string, and thus trims whitespace from both sides of a string:

```
SELECT TRIM(FROM '   The Acceleration Cup     ');
```

| btrim text |
| :- |
| The Acceleration Cup |

Rows: 1Execution time: 5.37ms


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.