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
| Parameter | Type | Required | Description |
|---|---|---|---|
string | VARCHAR | Yes | Source string |
n | BIGINT | Yes | Number of characters to take from the start |
Notes
- Equivalent to
SUBSTR(string, 1, n)for non-negativen; see Related functions (SUBSTR) - For
nlarger than the string length, the whole string is returned; forn = 0, the result is'' - If
STRINGorNis NULL, the result is NULL (useNULL(VARCHAR)/NULL(BIGINT); bareNULLfails 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 VARCHAR | f2 VARCHAR | f3 VARCHAR | f4 VARCHAR | f5 VARCHAR |
|---|---|---|---|---|
| abc | abc | hi | (empty) | NULL |
On this page