btrim()

A system function which trims characters from both sides of a string

btrim() is a system function which trims characters (default: spaces) from both sides of a string.

btrim() was added in PostgreSQL 6.1.

Usage

btrim ( string text [, characters text ] ) → text

btrim() is a convenience/compatibility function equivalent to the SQL standard trim():

postgres=# SELECT btrim('  foobar  '), trim(BOTH FROM '  foobar  '); 
 btrim  | btrim  
--------+--------
 foobar | foobar
(1 row)

Change history

Examples

Remove all instances of !, ? and # from both sides of a string:

postgres=# SELECT btrim('!#foo##bar??', '!?#');
  btrim   
----------
 foo##bar
(1 row)

Categories

System function

See also

ltrim(), rtrim(), trim()