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
| Parameter | Type | Required | Description |
|---|---|---|---|
string | VARCHAR | Yes | String to extract from |
start | BIGINT | Yes | Starting position (1-indexed, or negative to count from end) |
length | BIGINT | No | Number 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 VARCHAR | f2 VARCHAR | f3 VARCHAR | f4 VARCHAR | f5 VARCHAR | f6 VARCHAR |
|---|---|---|---|---|---|
| Hello | World | World | World | Hello World | CD |
On this page