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

<AgentInstructions>

## Submitting Feedback

If you encounter incorrect, outdated, or confusing documentation on this page, submit feedback:

POST https://docs.firebolt.io/feedback

```json
{
  "path": "/reference-sql/functions-reference/string/trim",
  "feedback": "Description of the issue"
}
```

Only submit feedback when you have something specific and actionable to report.

</AgentInstructions>

> 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":"github-light","dark":"github-dark"}}
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`

## Example

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:

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
SELECT
  TRIM(TRAILING 'xy' FROM 'xyxyThe Acceleration Cupyyxx');
```

**Returns**:

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
'xyxyThe Acceleration Cup'
```

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

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
SELECT
  TRIM('xy' FROM 'xyxyThe Acceleration Cupyyxx');
```

**Returns**:

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
'The Acceleration Cup'
```

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

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
SELECT
  TRIM(TRAILING FROM '   The Acceleration Cup     ');
```

**Returns**:

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
'   The Acceleration Cup'
```

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:

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
SELECT
  TRIM(FROM '   The Acceleration Cup     ');
```

**Returns**:

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
'The Acceleration Cup'
```
