Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
APPLIES TO:
NoSQL
Returns a subset of an array expression using the index and length specified.
ARRAY_SLICE(<array_expr>, <numeric_expr_1> [, <numeric_expr_2>])
Description | |
---|---|
array_expr |
An array expression. |
numeric_expr_1 |
A numeric expression indicating the index where to begin the array for the subset. Optionally, negative values can be used to specify the starting index relative to the last element of the array. |
numeric_expr_2 (Optional) |
An optional numeric expression indicating the maximum length of elements in the resulting array. |
Returns an array expression.
The following example shows how to get different slices of an array using the function.
SELECT VALUE {
sliceFromStart: ARRAY_SLICE([70, 86, 92, 99, 85, 90, 82], 0),
sliceFromSecond: ARRAY_SLICE([70, 86, 92, 99, 85, 90, 82], 1),
sliceFromLast: ARRAY_SLICE([70, 86, 92, 99, 85, 90, 82], -1),
sliceFromSecondToLast: ARRAY_SLICE([70, 86, 92, 99, 85, 90, 82], -2),
sliceThreeFromStart: ARRAY_SLICE([70, 86, 92, 99, 85, 90, 82], 0, 3),
sliceTwelveFromStart: ARRAY_SLICE([70, 86, 92, 99, 85, 90, 82], 0, 12),
sliceFiveFromThird: ARRAY_SLICE([70, 86, 92, 99, 85, 90, 82], 3, 5),
sliceOneFromSecondToLast: ARRAY_SLICE([70, 86, 92, 99, 85, 90, 82], -2, 1)
}
[
{
"sliceFromStart": [70, 86, 92, 99, 85, 90, 82],
"sliceFromSecond": [86, 92, 99, 85, 90, 82],
"sliceFromLast": [82],
"sliceFromSecondToLast": [90, 82],
"sliceThreeFromStart": [70, 86, 92],
"sliceTwelveFromStart": [70, 86, 92, 99, 85, 90, 82],
"sliceFiveFromThird": [99, 85, 90, 82],
"sliceOneFromSecondToLast": [90]
}
]
- This system function doesn't use the index.