TRIM()
All functions > STRING > TRIM()
Returns the string with whitespace from both ends removed.
Signatures
Returns: String with leading and trailing whitespace removed
TRIM(string: VARCHAR, [characters: VARCHAR]) → VARCHAR sql
| Parameter | Type | Required | Description |
|---|---|---|---|
string | VARCHAR | Yes | String to trim |
characters | VARCHAR | No | Characters to remove from both ends (optional; default trims whitespace) |
Notes
- Removes leading and trailing whitespace (spaces, tabs, line breaks, and similar) when
charactersis omitted - With
characters, removes any leading or trailing code points that appear in that string (order incharactersdoes not matter) - Whitespace inside the string is left unchanged
TRIM('')is''; if the input is NULL the result is NULL (useNULL(VARCHAR); bareNULLfails inference)
Examples
FeatureQL
SELECT
-- Trim both ends
f1 := TRIM(' hello '),
-- Trim tabs
f2 := TRIM(' world '),
-- Only trim ends
f3 := TRIM(' mixed spaces '),
-- No whitespace to trim
f4 := TRIM('no trim needed'),
-- NULL yields NULL
f5 := TRIM(NULL(VARCHAR)),
-- Line breaks at both ends
f6 := TRIM(CONCAT(CHR(10), 'hello', CHR(10))),
-- Trim custom characters
f7 := TRIM('xxhelloxx', 'x')
;Result
| f1 VARCHAR | f2 VARCHAR | f3 VARCHAR | f4 VARCHAR | f5 VARCHAR | f6 VARCHAR | f7 VARCHAR |
|---|---|---|---|---|---|---|
| hello | world | mixed spaces | no trim needed | NULL | hello | hello |
On this page