Menu
Amazon Redshift
Database Developer Guide (API Version 2012-12-01)

BTRIM Function

The BTRIM function trims a string by removing leading and trailing blanks or by removing characters that match an optional specified string.

Syntax

Copy
BTRIM(string [, matching_string ] )

Arguments

string

The first input parameter is a VARCHAR string.

matching_string

The second parameter, if present, is a VARCHAR string.

Return Type

The BTRIM function returns a VARCHAR string.

Examples

The following example trims leading and trailing blanks from the string ' abc ':

Copy
select ' abc ' as untrim, btrim(' abc ') as trim; untrim | trim ----------+------ abc | abc (1 row)

The following example removes the leading and trailing 'xyz' strings from the string 'xyzaxyzbxyzcxyz'

Copy
select 'xyzaxyzbxyzcxyz' as untrim, btrim('xyzaxyzbxyzcxyz', 'xyz') as trim; untrim | trim -----------------+----------- xyzaxyzbxyzcxyz | axyzbxyzc (1 row)

Note that the leading and trailing occurrences of 'xyz' were removed, but that occurrences that were internal within the string were not removed.