get_item¶
Description¶
Given an array, and a computed index, return the item at that index in the
array. The first item has index 0. As opposed to array_slice()
, this index
may not be negative – you have to calculate the array_length()
and subtract
from it yourself, if you want an index from the end, or you can re-formulate
the operation using array_slice()
, at some performance penalty.
If there is no such item, this function returns null()
.
If you know the exact index you want, e g, the value does not need to be
computed, then it is more efficient to index using regular brackets:
myarray[3]
is more efficient than get_item(myarray, 3)
.
Return type¶
any
Domain¶
This is a scalar function (calculates a single output value for a single input row.)
Categories¶
Usage¶
get_item( array, item )
Argument |
Type |
Required |
Multiple |
---|---|---|---|
array |
array |
Required |
Only one |
item |
int64 |
Required |
Only one |
Examples¶
make_col someindex:1
make_col somearray:array(parse_json("[5,17,3,8,2,20]"))
make_col final:int64(get_item(somearray, someindex))
drop_col someindex, somearray
Make a new column final
that contains the value 17. It does this by constructing
an array in a temporary column somearray
and an index in a temporary column
someindex
and then looking up the value of that index in the array. Because
object lookup returns variant
, the code casts the value to an int64
.