> ## 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.

> Reference material for TRIM function

# TRIM

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`.<br /><br />`LEADING` - trims from the beginning of the specified string<br /><br />`TRAILING` - trims from the end of the specified string. <br /><br />`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:

<div className="query-window">
  ```
  SELECT TRIM(TRAILING 'xy' FROM 'xyxyThe Acceleration Cupyyxx');
  ```

  | rtrim <span>text</span>  |
  | :----------------------- |
  | xyxyThe Acceleration Cup |

  <p><span>Rows: 1</span><span>Execution time: 5.06ms</span></p>
</div>

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

<div className="query-window">
  ```
  SELECT TRIM('xy' FROM 'xyxyThe Acceleration Cupyyxx');
  ```

  | btrim <span>text</span> |
  | :---------------------- |
  | The Acceleration Cup    |

  <p><span>Rows: 1</span><span>Execution time: 6.61ms</span></p>
</div>

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

<div className="query-window">
  ```
  SELECT TRIM(TRAILING FROM '   The Acceleration Cup     ');
  ```

  | rtrim <span>text</span> |
  | :---------------------- |
  | The Acceleration Cup    |

  <p><span>Rows: 1</span><span>Execution time: 5.53ms</span></p>
</div>

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:

<div className="query-window">
  ```
  SELECT TRIM(FROM '   The Acceleration Cup     ');
  ```

  | btrim <span>text</span> |
  | :---------------------- |
  | The Acceleration Cup    |

  <p><span>Rows: 1</span><span>Execution time: 5.37ms</span></p>
</div>
