INDEX

INDEX(array, index)[source]

Retrieves the element or row at a specified index from an array or table.

The INDEX function returns the item at the given 1-based index within an array or table. If the input is a Table or OBJECT_ARRAY, it returns the row corresponding to the index. If the input is a primitive ARRAY type (e.g. INTEGER_ARRAY, BOOLEAN_ARRAY), it returns the array element at that position. If the index argument is an array type, an array of indices is returned. A ValueError is raised if index is not an INTEGER or INTEGER_ARRAY type or if array is not a valid array type.

Parameters:
  • array (Table | Operand) –

    The array or table from which to retrieve an element. Must be an array type or a Table. If the type is invalid, a ValueError is raised.

    Supported types:

    • BOOLEAN_ARRAY

    • INTEGER_ARRAY

    • DECIMAL_ARRAY

    • STRING_ARRAY

    • DATE_ARRAY

    • DATETIME_ARRAY

    • TIME_ARRAY

    • OBJECT_ARRAY

  • index (Operand | int) –

    The 1-based index of the element or row to retrieve. Must be an INTEGER or INTEGER_ARRAY value. If the index is not INTEGER or INTEGER_ARRAY, a ValueError is raised. If the index is less than 1 or greater than the size of the array, the formula evaluates to an error.

    Supported types:

    • INTEGER

    • INTEGER_ARRAY

Return type:

Formula

Returns:

The element or row at the specified index. If the array is OBJECT_ARRAY or Table, the result is an object type. If the array is a primitive ARRAY, the result is the corresponding singular type.

Supported types:

  • BOOLEAN

  • INTEGER

  • DECIMAL

  • STRING

  • DATE

  • DATETIME

  • TIME

  • OBJECT

  • BOOLEAN_ARRAY

  • INTEGER_ARRAY

  • DECIMAL_ARRAY

  • STRING_ARRAY

  • DATE_ARRAY

  • DATETIME_ARRAY

  • TIME_ARRAY

  • OBJECT_ARRAY

Raises:
  • ValueError – If index is not of type INTEGER or INTEGER_ARRAY.

  • ValueError – If array is not a valid array or Table type.

Examples

Retrieving an element from an array:

INDEX([10, 20, 30], 2)
# Returns 20

Retrieving multiple elements from an array:

INDEX([10, 20, 30], [1, 2])
# Returns [10, 20]

Retrieving a row from a table:

INDEX(my_table, 1)
# Returns the first row of the table