SLICE_LEN()
All functions > ARRAY > SLICE_LEN()
Returns a slice of an array using start:length:step semantics.
Signatures
Returns: The specified slice of elements or characters
SLICE_LEN(array: ARRAY<T> or VARCHAR, start: BIGINT, [length: BIGINT], [step: BIGINT]) → ARRAY<T> or VARCHAR sql
| Parameter | Type | Required | Description |
|---|---|---|---|
array | ARRAY<T> or VARCHAR | Yes | The input array or string to slice |
start | BIGINT | Yes | Starting position (1-based indexing, negative for end-relative) |
length | BIGINT | No | Number of elements or characters to extract |
step | BIGINT | No | Step size for element selection (default: 1) |
Notes
- Canonical name is
SLICE_LEN. BareSLICEis a permissive alias;FORMAT (FIX)rewrites it - Inclusive-end slicing is
SLICE_ENDorarr[a:b]. Do not writeARRAY_SLICEorLIST_SLICE - Uses 1-based indexing (SQL standard)
- Also slices VARCHAR with the same start/length contract
- Negative start values count from the end of the array
- Optional length parameter specifies how many elements to extract
- Optional step parameter allows extracting every nth element
- Step can be negative for reverse traversal
- Returns empty array if start is out of bounds
Aliases
SLICE
See also
Examples
Basic Slicing
FeatureQL
RETURN
-- Basic positive start, no length (slice to end)
f1 := SLICE_LEN(ARRAY(1, 2, 3, 4, 5, 6), 4),
-- Basic positive start and length
f2 := SLICE_LEN(ARRAY(1, 2, 3, 4, 5, 6), 2, 3),
-- Start from beginning, positive length
f3 := SLICE_LEN(ARRAY(1, 2, 3, 4, 5, 6), 1, 4),
-- Positive start, length extends past end
f4 := SLICE_LEN(ARRAY(1, 2, 3, 4, 5, 6), 4, 5)
;Result
| f1 ARRAY | f2 ARRAY | f3 ARRAY | f4 ARRAY |
|---|---|---|---|
| [4, 5, 6] | [2, 3, 4] | [1, 2, 3, 4] | [4, 5, 6] |
Negative Indices
FeatureQL
RETURN
-- Negative start, no length (slice to end)
f1 := SLICE_LEN(ARRAY(1, 2, 3, 4, 5, 6), -3),
-- Negative start, positive length
f2 := SLICE_LEN(ARRAY(1, 2, 3, 4, 5, 6), -4, 2)
;Result
| f1 ARRAY | f2 ARRAY |
|---|---|
| [4, 5, 6] | [3, 4] |
Step Parameter
FeatureQL
RETURN
-- Step of 1 (same as no step)
f1 := SLICE_LEN(ARRAY(1, 2, 3, 4, 5, 6), 3, 3, 1),
-- Step of 2, every other element
f2 := SLICE_LEN(ARRAY(1, 2, 3, 4, 5, 6), 1, 6, 2),
-- Step of 2, starting from position 2
f3 := SLICE_LEN(ARRAY(1, 2, 3, 4, 5, 6), 2, 4, 2),
-- Step of 3, every third element
f4 := SLICE_LEN(ARRAY(1, 2, 3, 4, 5, 6), 1, 6, 3)
;Result
| f1 ARRAY | f2 ARRAY | f3 ARRAY | f4 ARRAY |
|---|---|---|---|
| [3, 4, 5] | [1, 3, 5] | [2, 4] | [1, 4] |
Negative Step
FeatureQL
RETURN
-- Negative step=-1, length=3 from position 6
f1 := SLICE_LEN(ARRAY(1, 2, 3, 4, 5, 6), 6, 3, -1),
-- Negative step=-1, length=4 from position 4
f2 := SLICE_LEN(ARRAY(1, 2, 3, 4, 5, 6), 4, 4, -1),
-- Negative start with negative step
f3 := SLICE_LEN(ARRAY(1, 2, 3, 4, 5, 6), -1, 3, -1),
-- Full reverse with negative step
f4 := SLICE_LEN(ARRAY(1, 2, 3, 4, 5, 6), 6, 6, -1)
;Result
| f1 ARRAY | f2 ARRAY | f3 ARRAY | f4 ARRAY |
|---|---|---|---|
| [6, 5, 4] | [4, 3, 2, 1] | [6, 5, 4] | [6, 5, 4, 3, 2, 1] |