PostgreSQL 18 reference · String Functions

PostgreSQL RTRIM() Function

Remove spaces, or any characters you list, from the end (right side) of a string only.

PostgreSQL 18

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

rtrim(string, characters)

Parameters

ParameterDescription
string The input text.
characters optional Characters to remove; spaces by default.

Return value

Text.

Examples

Trailing spaces
SELECT '[' || rtrim('right   ') || ']' AS result;

Output

 result
---------
 [right]
(1 row)

Run this on your computer — see “Get Started” for setup.

Trailing slashes
SELECT rtrim('https://example.com///', '/') AS url;

Output

         url
---------------------
 https://example.com
(1 row)

Run this on your computer — see “Get Started” for setup.

In other languages

Was this page helpful?