Watch the 7.3 Webinar On-Demand
This new release brings updates to Universal Storage, query optimization, and usability that you won’t want to miss.

TRIM

Removes padding from the ends of the given string.

Syntax

TRIM ([[BOTH | LEADING | TRAILING] [padding] FROM] str)

Arguments

  • padding: any string or binary object (optional, defaults to " “)
  • str: any string or binary object

If no keyword is specified, defaults to BOTH.

Return Type

String

Examples

Info

This function removes only space " " characters. Other whitespace characters like tab \t, newline \n, etc are preserved.

select trim('    ohai     ') as t,
    -> trim(LEADING FROM '    ohai     ') as l,
    -> trim(TRAILING FROM '    ohai     ') as r;
+------+-----------+----------+
| t    | l         | r        |
+------+-----------+----------+
| ohai | ohai      |     ohai |
+------+-----------+----------+

select trim("abra" FROM "abracadabra") as t;
+------+
| t    |
+------+
| cad  |
+------+

Related Topics