# rtrim

> 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: rtrim
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/rtrim
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/rtrim.adoc
page-edit-url: https://github.com/redpanda-data/cloud-docs/edit/main/modules/reference/pages/sql/sql-functions/string-functions/rtrim.adoc
description: The `rtrim()` function removes the longest string of characters matching a set of characters from the end 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/rtrim.md -->

The `rtrim()` function removes the longest string containing only characters from a specified set from the end (right side) of a string. If you don’t specify a set of characters, `rtrim()` 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, [`btrim()`](https://docs.redpanda.com/cloud-data-platform/reference/sql/sql-functions/string-functions/btrim/) to trim from both ends, 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 `rtrim()` function is:

```sql
RTRIM(string)
RTRIM(string, characters)
```

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

-   `string`: The string to trim.

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


## [](#examples)Examples

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

This example removes trailing spaces from a string:

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

```sql
+-----------+
| rtrim     |
+-----------+
| Redpanda  |
+-----------+
```

### [](#trim-a-specified-set-of-trailing-characters)Trim a specified set of trailing characters

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

```sql
SELECT RTRIM('Redpandaxyxy', 'xy');
```

```sql
+-----------+
| rtrim     |
+-----------+
| Redpanda  |
+-----------+
```