# btrim

> For the complete documentation index, see [llms.txt](https://docs.redpanda.com/llms.txt). Component-specific: [cloud-data-platform-full.txt](https://docs.redpanda.com/cloud-data-platform-full.txt)

---
title: btrim
latest-operator-version: v26.2.4
latest-console-tag: v3.12.0
latest-connect-version: 4.113.1
latest-redpanda-tag: v26.2.4
docname: sql/sql-functions/string-functions/btrim
page-component-name: cloud-data-platform
page-version: master
page-component-version: master
page-component-title: Cloud
page-relative-src-path: sql/sql-functions/string-functions/btrim.adoc
page-edit-url: https://github.com/redpanda-data/cloud-docs/edit/main/modules/reference/pages/sql/sql-functions/string-functions/btrim.adoc
description: The `btrim()` function removes the longest string of characters matching a set of characters from both ends of a string.
page-topic-type: reference
page-git-created-date: "2026-09-08"
page-git-modified-date: "2026-09-08"
---

<!-- Source: https://docs.redpanda.com/cloud-data-platform/reference/sql/sql-functions/string-functions/btrim.md -->

The `btrim()` function removes the longest string containing only characters from a specified set from both the start and end of a string. If you don’t specify a set of characters, `btrim()` removes spaces.

See also [`ltrim()`](https://docs.redpanda.com/cloud-data-platform/reference/sql/sql-functions/string-functions/ltrim/) to trim from the start of a string only, [`rtrim()`](https://docs.redpanda.com/cloud-data-platform/reference/sql/sql-functions/string-functions/rtrim/) to trim from the end only, and [`trim()`](https://docs.redpanda.com/cloud-data-platform/reference/sql/sql-functions/string-functions/trim/) for the SQL-standard `TRIM(…​ FROM …​)` syntax.

## [](#syntax)Syntax

The syntax of the `btrim()` function is:

```sql
BTRIM(string)
BTRIM(string, characters)
```

The `btrim()` function accepts the following arguments:

-   `string`: The string to trim.

-   `characters`: Optional. The set of characters to remove from both ends of `string`. Defaults to a space character.


## [](#examples)Examples

### [](#trim-leading-and-trailing-spaces)Trim leading and trailing spaces

This example removes leading and trailing spaces from a string:

```sql
SELECT BTRIM('   Redpanda   ');
```

```sql
+-----------+
| btrim     |
+-----------+
| Redpanda  |
+-----------+
```

### [](#trim-a-specified-set-of-characters-from-both-ends)Trim a specified set of characters from both ends

This example removes any leading or trailing `x` or `y` characters from a string:

```sql
SELECT BTRIM('xyRedpandayx', 'xy');
```

```sql
+-----------+
| btrim     |
+-----------+
| Redpanda  |
+-----------+
```