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 by default.

Uses of BTRIM() Function
  • Removing Specific Characters: Eliminate specific unwanted characters from the beginning and end of a string.

  • Whitespace Trimming: Clean up strings by removing leading and trailing spaces.

  • Data Cleaning: Standardize input data by trimming unwanted characters or spaces.

  • Formatting Strings: Prepare strings for consistent display or storage by trimming extraneous characters.

  • Improving Data Quality: Ensure uniformity in text data by removing inconsistencies at the edges of strings.

  • Pre-processing for Comparisons: Trim strings to ensure accurate comparisons by removing extraneous characters.

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



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/PostgreSQL/btrim-function.php