Scalar function
Aliases: array_slice
NULL supplied argument returns NULL.
Syntax
Slice endpoint (scalar)
- The third argument is the inclusive end index. It is not a length. Supply exactly three arguments.
Arguments
Returns
- Type: ARRAY<T>, preserving the input element type
- Possible values: Selected elements.
- NULL behavior: NULL supplied argument returns NULL.
- Shape: Contains the input elements between the inclusive start and end bounds, after adjusting out-of-range bounds as described below.
- Ordering: Preserves input encounter order; reversed positive bounds return an empty array.
Properties
Usage notes
- Negative bounds count from the end; start zero behaves as one.
- Bounds are inclusive, positive indexes are one-based, negative indexes count from the end, and start zero acts as one. Too-negative start is clamped to the start; an end beyond the length is clamped to the last element. An end below the array or a start beyond the array produces an empty array.
- INTEGER and INT mean the same type; STRING means VARCHAR text. NULL can be used with a supported type. Cast NULL explicitly when its type would otherwise be unclear.
Examples
Count from the end of a string array
Both bounds count from the end. The third argument is the inclusive end position.
Limitations
- ARRAY_SLICE and SLICE take exactly three arguments. The third is an inclusive end index; SLICE does not use Spark’s length interpretation. A fourth step or stride argument is not accepted.
Last modified on October 15, 2026