Cloud

ltrim

The ltrim() function removes the longest string containing only characters from a specified set from the start (left side) of a string. If you don’t specify a set of characters, ltrim() removes spaces.

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

Syntax

The syntax of the ltrim() function is:

LTRIM(string)
LTRIM(string, characters)

The ltrim() function accepts the following arguments:

  • string: The string to trim.

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

Examples

Trim leading spaces

This example removes leading spaces from a string:

SELECT LTRIM('   Redpanda');
+-----------+
| ltrim     |
+-----------+
| Redpanda  |
+-----------+

Trim a specified set of leading characters

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

SELECT LTRIM('xyxyRedpanda', 'xy');
+-----------+
| ltrim     |
+-----------+
| Redpanda  |
+-----------+