Contents
rtrim()
A system function which trims characters from the right side of a string
rtrim()
is a system function which trims specified characters (default: spaces) from the right-hand side of a string.
rtrim()
was added in PostgreSQL 6.1.
Usage
rtrim()
is a convenience/compatibility function equivalent to the SQL standard trim()
:
postgres=# SELECT rtrim('foobar', 'bar'), trim(TRAILING 'bar' FROM 'foobar'); rtrim | rtrim -------+------- foo | foo (1 row)
Change history
- PostgreSQL 14
- PostgreSQL 6.1
- added (commit 83978e1e)
Examples
Remove spaces from the right side of a string:
postgres=# SELECT rtrim('foobar '); rtrim -------- foobar (1 row)
Remove a particular character from the right side of a string:
postgres=# SELECT rtrim('foobarXXX', 'X'); rtrim -------- foobar (1 row)
A group of characters for removal can be specified; note the removal will stop when the first character not in that group is encountered:
postgres=# SELECT rtrim('foobarX_Z', 'XZ_'); rtrim -------- foobar (1 row) postgres=# SELECT rtrim('foobarX_Z', 'XZ'); rtrim ---------- foobarX_ (1 row)
References
- PostgreSQL documentation: Other String Functions