index_of_item#

Description#

Given an array and a value, return the index of the first occurrence of that value within that array, or NULL if the value isn’t found in the array. The index of the first element in an array is 0.

Note that strings and numbers do not compare equal – "42" and 42 are not the same value.

Return type#

int64

Domain#

This is a scalar function (calculates a single output value for a single input row.)

Categories#

Usage#

index_of_item(array, item)

Argument

Type

Optional

Repeatable

Restrictions

array

array

no

no

none

item

variant

no

no

none

Examples#

make_col somevalue:17
make_col somearray:array(parse_json("[5,3,17,3,8,17,2,20]"))
make_col position:index_of_item(somearray, somevalue)

Make a new column position that contains the value 2, because the first occurrence of 17 in the argument array is at index 2.

make_col somevalue:1
make_col somearray:array(parse_json("[5,17,3,8,2,20]"))
make_col position:index_of_item(somearray, somevalue)

Make a new column position that contains a null value, because the value 1 is not present in the array.