# trim — DuckDB 1.4.4

Removes any occurrences of any of the `characters` from either side of the `string`. `characters` defaults to `space`.

- Reference: /products/haybarn/functions/releases/duckdb-1.4.4/trim/
- JSON: /products/haybarn/functions/api/v1/duckdb-1.4.4/functions/trim.json
- Snapshot ID: duckdb-1.4.4
- Engine: duckdb v1.4.4
- Source ID: 6ddac802ff
- Binary SHA-256: 8d05bee013ea13d6b5d75272d7ddb52b3d6d9cdaf30d1a3e8e82d42757905182
- Captured: 2026-09-05T18:37:36.091Z
- Source: https://github.com/duckdb/duckdb/releases/tag/v1.4.4
- Loaded extensions: autocomplete, core_functions, icu, json, parquet, shell

## Interpretation

- Choose a snapshot matching the target engine and build. The default is captured from the published Haybarn WASM package used by the browser playground. Historical native snapshots are also available.
- Availability is an observation in the recorded build and extension profile, not a guarantee of support in every installation or in WASM.
- Types and descriptions are declarations from duckdb_functions(). Binding can specialize result types. Null means not supplied by the catalog; do not invent defaults, optionality, argument mode, or table output columns.
- Raw parameter arrays preserve catalog order for scalar/aggregate/macro functions. Raw table arguments are alphabetical. Use callingConvention for engine-confirmed positional order and named arguments; null modes are unrecorded. Named does not mean optional. Macro defaults and special named variadic behavior are not supplied by duckdb_functions().
- Catalog examples are source material and may require data or extensions. runnableExamples contains separately verified SQL for the pinned WASM package; sample-data adaptations and guide examples are labeled separately.
- Guide annotations and recipes are separate editorial content. The browser runner always uses Haybarn WASM 1.5.5-rc3, independently of the documentation snapshot.
- All URLs beginning with / are relative to the origin hosting this document. Exports require no JavaScript, cookies, API key, or browser engine.

## Overloads

### overload-3d07acaa6ff49919

Kind: scalar. Parameter order: catalog-order.

```text
trim(string: VARCHAR) → VARCHAR
```

Link: /products/haybarn/functions/releases/duckdb-1.4.4/trim/#overload-3d07acaa6ff49919

| Argument | Catalog type | Calling mode |
| --- | --- | --- |
| string | VARCHAR | not recorded |

Declared return type: VARCHAR. Variadic argument type: none declared.
Stability: CONSISTENT. Declared side effects: false.

### overload-63165f24f1d5239d

Kind: scalar. Parameter order: catalog-order.

```text
trim(string: VARCHAR, characters: VARCHAR) → VARCHAR
```

Link: /products/haybarn/functions/releases/duckdb-1.4.4/trim/#overload-63165f24f1d5239d

| Argument | Catalog type | Calling mode |
| --- | --- | --- |
| string | VARCHAR | not recorded |
| characters | VARCHAR | not recorded |

Declared return type: VARCHAR. Variadic argument type: none declared.
Stability: CONSISTENT. Declared side effects: false.


## Guide recipes

### Turn a label into a useful key.

Trim the edges, normalize case, and replace runs of spaces. Small functions compose into a readable cleaning step.

Intended runtime: Haybarn WASM 1.5.5-rc3. Per-example execution verification: not recorded in this export.

```sql
SELECT regexp_replace(
  lower(trim('  Summer Harvest 2026  ')),
  '\s+', '-', 'g'
) AS slug;
```

## Engine catalog examples

Source examples may require additional data or extensions. Expressions are wrapped in SELECT; execution verification is not recorded.

Reported for: overload-3d07acaa6ff49919, overload-63165f24f1d5239d

```sql
SELECT trim('    test  ');
```

Reported for: overload-3d07acaa6ff49919, overload-63165f24f1d5239d

```sql
SELECT trim('>>>>test<<', '><');
```

## Runnable examples

Executed successfully in Haybarn WASM 1.5.5-rc3. Sample data and guide examples are separate from the original catalog.

```sql
SELECT trim('    test  ');
```

```sql
SELECT trim('>>>>test<<', '><');
```

## Additional DuckDB documentation

- [Text Functions](https://duckdb.org/docs/current/sql/functions/text#trimstring-characters)
- [Text Functions](https://duckdb.org/docs/current/sql/functions/text.html#trimstring-characters)

## In other engines

### PostgreSQL: btrim()



PostgreSQL:

```sql
SELECT BTRIM(x, 'ab')
```

Haybarn / DuckDB:

```sql
SELECT TRIM(x, 'ab')
```

Translation from [SQLGlot](https://github.com/tobymao/sqlglot/blob/3086608e6fd4c41c02dfba47171608d2b193fce2/tests/dialects/test_postgres.py#L90).

### ClickHouse



ClickHouse:

```sql
SELECT LTRIM(s), RTRIM(s), TRIM(s)
```

Haybarn / DuckDB:

```sql
SELECT LTRIM(s), RTRIM(s), TRIM(s)
```

Translation from [SQLGlot](https://github.com/tobymao/sqlglot/blob/3086608e6fd4c41c02dfba47171608d2b193fce2/tests/dialects/test_clickhouse.py#L737).

## Observed availability

| Snapshot | Observed | Overloads | JSON |
| --- | --- | --- | --- |
| haybarn-1.5.5-rc3 | present | 2 | [reference](/products/haybarn/functions/api/v1/haybarn-1.5.5-rc3/functions/trim.json) |
| duckdb-1.5.5 | present | 2 | [reference](/products/haybarn/functions/api/v1/duckdb-1.5.5/functions/trim.json) |
| duckdb-1.4.4 | present | 2 | [reference](/products/haybarn/functions/api/v1/duckdb-1.4.4/functions/trim.json) |
| duckdb-1.3.2 | present | 2 | [reference](/products/haybarn/functions/api/v1/duckdb-1.3.2/functions/trim.json) |

Engine catalog documentation is derived from MIT-licensed Haybarn and DuckDB. [Notices](/third-party-notices.txt).
