Cloud

rtrim

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() to trim from the start of a string, btrim() to trim from both ends, and trim() for the SQL-standard TRIM(…​ FROM …​) syntax.

Syntax

The syntax of the rtrim() function is:

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

Trim trailing spaces

This example removes trailing spaces from a string:

SELECT RTRIM('Redpanda   ');
+-----------+
| rtrim     |
+-----------+
| Redpanda  |
+-----------+

Trim a specified set of trailing characters

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

SELECT RTRIM('Redpandaxyxy', 'xy');
+-----------+
| rtrim     |
+-----------+
| Redpanda  |
+-----------+