Cloud

btrim

The btrim() function removes the longest string containing only characters from a specified set from both the start and end of a string. If you don’t specify a set of characters, btrim() removes spaces.

See also ltrim() to trim from the start of a string only, rtrim() to trim from the end only, and trim() for the SQL-standard TRIM(…​ FROM …​) syntax.

Syntax

The syntax of the btrim() function is:

BTRIM(string)
BTRIM(string, characters)

The btrim() function accepts the following arguments:

  • string: The string to trim.

  • characters: Optional. The set of characters to remove from both ends of string. Defaults to a space character.

Examples

Trim leading and trailing spaces

This example removes leading and trailing spaces from a string:

SELECT BTRIM('   Redpanda   ');
+-----------+
| btrim     |
+-----------+
| Redpanda  |
+-----------+

Trim a specified set of characters from both ends

This example removes any leading or trailing x or y characters from a string:

SELECT BTRIM('xyRedpandayx', 'xy');
+-----------+
| btrim     |
+-----------+
| Redpanda  |
+-----------+