All Products
Search
Document Center

MaxCompute:INDEX

Last Updated:Mar 25, 2026

Returns an element from an array by position, or a value from a map by key.

Syntax

Array access

<array_expr>[<index>]

Map access

<map_expr>[<key>]
Important

Use bracket notation directly. Do not wrap it in INDEX(...) — calling INDEX(<var1>[<var2>]) returns an error.

Usage notes

  • Array indexing is 0-based: the first element is at index 0, the second at 1, and so on.

  • For map access, the key must match the declared key type K of the map exactly.

Parameters

Array access

ParameterTypeDescription
array_exprarray<T>The array to access. Returns null if the array is null.
indexBIGINT, >= 0The 0-based position of the element to retrieve. Returns null if the index is out of bounds.

Return type: T — the element type declared in array<T>.

Map access

ParameterTypeDescription
map_exprmap<K, V>The map to access. Returns null if the map is null.
keySame type as KThe key to look up. Returns null if the key does not exist in the map.

Return type: V — the value type declared in map<K, V>.

Examples

Access an array element by position

-- Returns 'c' (index 2 is the third element)
SELECT ARRAY('a', 'b', 'c')[2];

Access a map value by key

-- Returns 1
SELECT STR_TO_MAP("test1=1,test2=2")["test1"];

Related functions

INDEX is a complex type function. For more information about functions that process ARRAY, MAP, STRUCT, and JSON data, see Complex type functions.