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
ParameterTypeRequiredDescription
stringVARCHARYesString to trim
charactersVARCHARNoCharacters to remove from both ends (optional; default trims whitespace)

Notes

  • Removes leading and trailing whitespace (spaces, tabs, line breaks, and similar) when characters is omitted
  • With characters, removes any leading or trailing code points that appear in that string (order in characters does not matter)
  • Whitespace inside the string is left unchanged
  • TRIM('') is ''; if the input is NULL the result is NULL (use NULL(VARCHAR); bare NULL fails 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 VARCHARf2 VARCHARf3 VARCHARf4 VARCHARf5 VARCHARf6 VARCHARf7 VARCHAR
helloworldmixed spacesno trim neededNULLhellohello

Last update at: 2026/06/20 10:08:10