TRIM
Trim both ends
English words and abbreviations
trim = cut away the edges
What is it for?
Clean imported CSV and form values for analysis.
Syntax
TRIM(text[, characters])What goes in each argument?
| Argument | Type / notation | Example input | Meaning / default |
|---|---|---|---|
textRequired | VARCHAR | 'Ann' / name | The text to process: a column or string literal. |
charactersOptional | VARCHAR | ' /' | Set of characters to trim; default is whitespace/space. |
SQL you can run as written
Check each example’s inputs before copying it to the selected SQL engine. AS result names the output column.
Example 1 · Basic
SELECT
TRIM(' Ann ') AS result;Remove the spaces from both ends of ' Ann '. Return the output in the result column.
Result of this SQL
| result |
|---|
Ann |
Example 2 · Advanced
SELECT
TRIM('xyxAnnxyxy', 'xy') AS result;'xy' specifies the character set {x, y}. Remove consecutive x or y characters at both ends, leaving Ann. It does not match the substring 'xy'; characters inside the text stay unchanged. Return the output in the result column.
Result of this SQL
| result |
|---|
Ann |
Before you use it
Snowflake defaults to ASCII spaces; BigQuery to whitespace. The second argument is a character set, not a substring.
In the other dialect BigQuery
TRIM(text[, characters])Snowflake defaults to ASCII spaces; BigQuery to whitespace. The second argument is a character set, not a substring.
Official reference ↗