ARRAY_SLICE
functionsupportedCore SQL functionsReturns an array constructed from a specified subset of elements of the input array.
Syntax
ARRAY_SLICE( <array> , <from> , <to> )
Parameters
| Name | Required | Description |
|---|---|---|
array | required | The source array of which a subset of the elements are used to construct the resulting array. |
from | required | A position in the source array. The position of the first element is 0. Elements from positions less than from aren’t included in the resulting array. |
to | required | A position in the source array. Elements from positions equal to or greater than to are not included in the resulting array. |
Returns
This function returns a value of type ARRAY. Returns NULL if the any argument is NULL, including the input array, from, or to.
Usage notes
- The output includes elements up to, but not including the element specified by the parameter to.
- If either from or to is negative, it is relative to the end of the array, not the beginning of the array. For example, -2 refers to the second-from-the-last position in the array.
- If from and to are both beyond the upper end of the array, or are both beyond the lower end of the array, then the result is the empty set.
- When you pass a structured array to the function, the function returns a structured array of the same type.
- Note that many of these rules (for example, interpretation of negative numbers as indexes from the end of the array, and the rule that the slice is up to, but not including, the to index), are similar to the rules for array slices in programming languages such as Python.
- Each of these rules is illustrated in at least one example below.