SLICE
All functions > ARRAY > SLICE
Returns a slice of an array with optional step parameter.
Syntax
SLICE(array, start, length[, step]) sql
Arguments
| Parameter | Type | Required | Description |
|---|---|---|---|
array | ARRAYBIGINT | Yes | The input array to slice |
start | BIGINT | Yes | Starting position (1-based indexing, negative for end-relative) |
length | BIGINT | No | Number of elements to extract |
step | BIGINT | No | Step size for element selection (default: 1) |
Returns
A new array containing the specified slice of elements
Notes
- Uses 1-based indexing (SQL standard)
- 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
ARRAY_SLICELIST_SLICE