Postgresql Btrim Function

PostgreSQL: btrim Function

In this PostgreSQL post explains how to use the PostgreSQL btrim function with syntax and examples.

Description

The PostgreSQL btrim function removes all specified characters from both the beginning and the end of a string.

Syntax

The syntax for the btrim function in PostgreSQL is:

btrim( string, trim_character )

Parameters or Arguments

string

The string to trim.

trim_character

The set of characters that will be removed from both the left-hand and right-hand side of string. If this parameter is omitted, the btrim function will remove space characters from both sides of string.

Note

  • If you do not specify a trim_character, the btrim function will default the character to be removed as a space character.

Applies To

The btrim function can be used in the following versions of PostgreSQL:

  • PostgreSQL 9.4, PostgreSQL 9.3, PostgreSQL 9.2, PostgreSQL 9.1, PostgreSQL 9.0, PostgreSQL 8.4

Example

Let's look at some PostgreSQL btrim function examples and explore how to use the btrim function in PostgreSQL.

For example:

(Please note that for each of the example results below, we have included single quotes around the result to demonstrate what the btrim function returns in PostgreSQL. If you ran these commands yourself, you would not see the single quotes in the result):

postgres=# SELECT btrim('  AODBA.com  ', ' ');
      btrim
--------------------

 'AODBA.com'
(1 row)

postgres=# SELECT btrim('   AODBA.com   ');
      btrim
--------------------

 'AODBA.com'
(1 row)

postgres=# SELECT btrim('123TTT123', '123');
 btrim
--------

 'TTT'
(1 row)