SUBSTR

All functions > STRING > SUBSTR

Returns a substring from a string starting at a specified position.

Signatures

Returns: Extracted substring

SUBSTR(string: VARCHAR, start: BIGINT, [length: BIGINT]) → VARCHAR
sql
ParameterTypeRequiredDescription
stringVARCHARYesString to extract from
startBIGINTYesStarting position (1-indexed, or negative to count from end)
lengthBIGINTNoNumber of characters to extract (optional, defaults to end of string)

Notes

  • Start position is 1-indexed
  • Negative start position counts from end of string
  • If length omitted, extracts to end of string
  • If length exceeds remaining string, returns what's available

Examples

FeatureQL
SELECT
    f1 := SUBSTR('Hello World', 1, 5),  -- First 5 characters
    f2 := SUBSTR('Hello World', 7, 5),  -- Starting from position 7
    f3 := SUBSTR('Hello World', 7),  -- From position 7 to end
    f4 := SUBSTR('Hello World', -5, 5),  -- Negative start position
    f5 := SUBSTR('Hello World', 1, 100),  -- Length exceeds string
    f6 := SUBSTR('ABCDEF', 3, 2)  -- Middle substring
;
Result
f1 VARCHARf2 VARCHARf3 VARCHARf4 VARCHARf5 VARCHARf6 VARCHAR
HelloWorldWorldWorldHello WorldCD

Last update at: 2026/03/03 16:47:38
Last updated: 2026-03-03 16:48:19