VeloDB Cloud 26.x·Apache Doris 4.x (up to 4.0 supported)·"Since X.Y" tags refer to Apache Doris versionsVersion mapping
RTRIM
Description
The RTRIM function is used to remove consecutive spaces or specified strings from the right side (trailing) of a string. If the second parameter is not specified, trailing spaces are removed; if specified, the function removes the specified complete string from the right side.
Syntax
RTRIM(<str>[, <rhs>])
Parameters
| Parameter | Description |
|---|---|
<str> | The string to be processed. Type: VARCHAR |
<rhs> | Optional parameter, trailing characters to be trimmed. Type: VARCHAR |
Return Value
Returns a value of type VARCHAR.
Special cases:
- If any parameter is NULL, NULL is returned
- If rhs is not specified, removes trailing spaces
- If rhs is specified, removes the complete rhs string (not character-by-character)
Examples
- Remove trailing spaces
SELECT rtrim('ab d ') str;
+------+
| str |
+------+
| ab d |
+------+
- Remove specified trailing string
SELECT rtrim('ababccaab', 'ab') str;
+---------+
| str |
+---------+
| ababcca |
+---------+
- Default trim only removes ASCII space —
RTRIMdoes not strip tabs (\t) or newlines (\n) without a second argument. CompareLENGTHbefore and after: only the single trailing ASCII space is stripped;\t\nstay.
SELECT LENGTH('hello world \t\n '), LENGTH(RTRIM('hello world \t\n '));
+------------------------------+-------------------------------------+
| LENGTH('hello world \t\n ') | LENGTH(RTRIM('hello world \t\n ')) |
+------------------------------+-------------------------------------+
| 16 | 15 |
+------------------------------+-------------------------------------+
- UTF-8 character support
SELECT rtrim('ṭṛì ḍḍumai ');
+---------------------------+
| rtrim('ṭṛì ḍḍumai ') |
+---------------------------+
| ṭṛì ḍḍumai |
+---------------------------+
- No matching suffix, return original string
SELECT rtrim('Hello World', 'xyz');
+---------------------------------+
| rtrim('Hello World', 'xyz') |
+---------------------------------+
| Hello World |
+---------------------------------+
- NULL value handling
SELECT rtrim(NULL), rtrim('Hello', NULL);
+-------------+------------------------+
| rtrim(NULL) | rtrim('Hello', NULL) |
+-------------+------------------------+
| NULL | NULL |
+-------------+------------------------+
- Empty string handling
SELECT rtrim(''), rtrim('abc', '');
+-----------+-------------------+
| rtrim('') | rtrim('abc', '') |
+-----------+-------------------+
| | abc |
+-----------+-------------------+
- Repeated trailing pattern removal
SELECT rtrim('abcabcabc', 'abc');
+-------------------------------+
| rtrim('abcabcabc', 'abc') |
+-------------------------------+
| |
+-------------------------------+
- Multiple occurrences, remove only trailing match
SELECT rtrim('HelloHelloWorld', 'Hello');
+---------------------------------------+
| rtrim('HelloHelloWorld', 'Hello') |
+---------------------------------------+
| HelloHelloWorld |
+---------------------------------------+
Keywords
RTRIM