Select your cookie preferences

We use essential cookies and similar tools that are necessary to provide our site and services. We use performance cookies to collect anonymous statistics, so we can understand how customers use our site and make improvements. Essential cookies cannot be deactivated, but you can choose “Customize” or “Decline” to decline performance cookies.

If you agree, AWS and approved third parties will also use cookies to provide useful site features, remember your preferences, and display relevant content, including relevant advertising. To accept or decline all non-essential cookies, choose “Accept” or “Decline.” To make more detailed choices, choose “Customize.”

BTRIM function - Amazon Redshift

BTRIM function

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

Syntax

BTRIM(string [, trim_chars ] )

Arguments

string

The input VARCHAR string to be trimmed.

trim_chars

The VARCHAR string containing the characters to be matched.

Return type

The BTRIM function returns a VARCHAR string.

Examples

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

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

The following example removes the leading and trailing 'xyz' strings from the string 'xyzaxyzbxyzcxyz'. The leading and trailing occurrences of 'xyz' are removed, but occurrences that are internal within the string are not removed.

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

The following example removes the leading and trailing parts from the string 'setuphistorycassettes' that match any of the characters in the trim_chars list 'tes'. Any t, e, or s that occur before another character that is not in the trim_chars list at the beginning or ending of the input string are removed.

SELECT btrim('setuphistorycassettes', 'tes'); btrim ----------------- uphistoryca
PrivacySite termsCookie preferences
© 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved.