BTRIM function - Amazon Redshift

BTRIM function

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


BTRIM(string [, matching_string ] )



The first input parameter is a VARCHAR string.


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

Return type

The BTRIM function returns a VARCHAR string.


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

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'

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.