LEFT()

All functions > STRING > LEFT()

Returns the first n characters of the string (or the full string when n is greater than its length).

Signatures

Returns: Leading substring

LEFT(string: VARCHAR, n: BIGINT) → VARCHAR
sql
ParameterTypeRequiredDescription
stringVARCHARYesSource string
nBIGINTYesNumber of characters to take from the start

Notes

  • Equivalent to SUBSTR(string, 1, n) for non-negative n; see Related functions (SUBSTR)
  • For n larger than the string length, the whole string is returned; for n = 0, the result is ''
  • If STRING or N is NULL, the result is NULL (use NULL(VARCHAR) / NULL(BIGINT); bare NULL fails inference)

Examples

FeatureQL
SELECT
    f1 := LEFT('abcdef', 3), -- First three characters
    f2 := LEFT('abcdef', 3), -- Matches SUBSTR from the start
    f3 := LEFT('hi', 10), -- n longer than string
    f4 := LEFT('x', 0), -- Zero length
    f5 := LEFT(NULL(VARCHAR), 3) -- NULL string yields NULL
;
Result
f1 VARCHARf2 VARCHARf3 VARCHARf4 VARCHARf5 VARCHAR
abcabchi(empty)NULL

Last update at: 2026/05/26 17:22:09