RTRIM
Removes the given characters (spaces by default) from the end of a string.
PostgreSQL 17.9
RTRIM(string[, characters])- [ ]optional part
- string
- Source stringtext
- characters
- Set of characters to remove, a space by defaulttextOptional
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.9
SELECT '[' || RTRIM(' Hello ') || ']' AS trimmed;Removing trailing zeros
PostgreSQL 17.9
SELECT RTRIM('2.5000', '0');Details
characters is a set of single characters, not a substring: RTRIM('abcxyx', 'xy') removes both x and y and returns abc.