Function Reference

RTRIM

Removes the given characters (spaces by default) from the end of a string.

PostgreSQL 17.5
RTRIM(string[, characters])

Parameters

stringtext
Source string
characterstextoptional
Set of characters to remove, a space by default

Return value

A string without the characters from characters at the end; tabs and line breaks are not removed by default

Examples

Removing spaces on the right

PostgreSQL 17.5
SELECT '[' || RTRIM('  Hello  ') || ']' AS trimmed;
trimmed
[ Hello]

Removing trailing zeros

PostgreSQL 17.5
SELECT RTRIM('2.5000', '0');
rtrim
2.5

Details

characters is a set of single characters, not a substring: RTRIM('abcxyx', 'xy') removes both x and y and returns abc.

See also