w3resource

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)

Previous: ASCII function
Next: CHR function



Follow us on Facebook and Twitter for latest update.