get function
Applies to: Databricks SQL
Databricks Runtime 11.3 LTS and above
Returns the element of an arrayExpr at index, starting with 0.
Syntax
get(arrayExpr, index)
Arguments
arrayExpr: An ARRAY expression.index: An INTEGER expression specifying the index in the array.
Returns
The result is of the type of the elements of arrayExpr.
If the index is negative or outside the bounds of the array the resut is NULL.
To return an INVALID_ARRAY_INDEX error instead, use the arrayExpr[index] operator.
Examples
SQL
> SELECT element_at(arr, 2), get(arr, 0), get(arr, 2), arr[2] FROM VALUES(array(1, 2, 3)) AS T(arr);
2 1 3 3
> SELECT get(arr, 5), get(arr, -1) FROM VALUES(array(1, 2, 3)) AS T(arr);
NULL NULL