w3resource
MySQL Tutorial

PostgreSQL BTRIM() function

BTRIM() function

The PostgreSQL btrim function is used to remove the longest string specified in the argument from the start and end of the given string. If no string for removing default space will be removed from leading and trailing side from the string.

Syntax:

btrim(<string>[ , <text_trim>])

PostgreSQL Version: 9.3

Pictorial Presentation of PostgreSQL BTRIM() function

Pictorial presentation of postgresql btrim function

Example - 1: PostgreSQL BTRIM() function:

In the example below, the btrim searches the letters 't' or 'e' or 's' or 't' from the left or right most position of the given string and removes those letters which match consecutively and displays the result 'w3resourc'.

Example:

Code:

SELECT btrim('settw3resourcesttes', 'test');

Sample Output:

   btrim
-----------
 w3resourc
(1 row)

Example - 2: PostgreSQL BTRIM() function:

In the example below, the btrim searches the letters white space ( ' ' ) in the given string and removes all white spaces from both sides of the given string.

Example:

Code:

SELECT btrim(' w3resource.com ');

Sample Output:

     btrim
----------------
 w3resource.com
(1 row)

Example - 3: PostgreSQL BTRIM() function:

In the example below, no trimming text have been defined, so this statement by default will remove all white spaces from both sides of the given string.

Example:

Code:

SELECT btrim(' w3resource.com ');

Sample Output:

     btrim
----------------
 w3resource.com
(1 row)

Many of our valued users post comments along with piece of code. Disqus may, false positively, consider those piece of code as Bad or Starnge syntax and send those comments to spam automatically. Even if that happens, we will make sure those useful comments are taken out of spam and approved. It may take a couple of days for that though, but any useful comment will be brought to public view for sure. We regret if that happend to any user. You may write us directly regarding this to - w3resource[at]yahoo[dot]com.