Appearance
TRIM
Remove specific leading or trailing characters from a string. Remove spaces by default. See also BTRIM.
TRIM ([ LEADING | TRAILING | BOTH ] [characters] FROM string)
By default, TRIM
without BOTH
trims both sides of the string.
Examples
Trim leading and trailing spaces:
premdb=# select trim(from ' City') from sys.const;
btrim
-------
City
(1 row)
premdb=# select trim(from ' City ') from sys.const;
btrim
-------
City
(1 row)
premdb=# select trim(trailing from ' City ') from sys.const;
rtrim
----------
City
(1 row)
Remove a specific set of leading and trailing characters:
premdb=# select nickname, trim('aeiousy' from nickname) from team where nickname like '%s';
nickname | btrim
------------+-----------
Gunners | Gunner
Villains | Villain
Tykes | Tyk
Blues | Bl
Rovers | Rover
Seasiders | Seasider
Trotters | Trotter
Cherries | Cherr
...
Remove a specific set of trailing characters:
premdb=# select season_name, trim(trailing '0123456789' from season_name) from season;
season_name | rtrim
-------------+-----------
1992-1993 | 1992-
1993-1994 | 1993-
1994-1995 | 1994-
1995-1996 | 1995-
1996-1997 | 1996-
...
Parent topic:String Functions