All Products
Search
Document Center

MaxCompute:ARRAY_POSITION

Last Updated:Mar 26, 2026

Returns the position of the first occurrence of a given element in an array. Positions are 1-based, counted from left to right.

Syntax

bigint array_position(array<T> <a>, T <element>)

Parameters

ParameterRequiredDescription
aYesThe array to search. T in array<T> specifies the element data type. Supported types: TINYINT, SMALLINT, INT, BIGINT, FLOAT, DOUBLE, BOOLEAN, DECIMAL, DECIMALVAL, DATE, DATETIME, TIMESTAMP, IntervalDayTime, IntervalYearMonth, STRING, BINARY, VARCHAR, CHAR, ARRAY, STRUCT, and MAP.
elementYesThe element to find. Must be the same data type as the elements in a.

Usage notes

  • Positions start at 1, not 0.

  • If a or element is null, the function returns null.

  • If element is not found in a, the function returns 0.

Examples

Example 1: Find the position of 1 in array(3, 2, 1).

-- Returns 3
SELECT array_position(array(3, 2, 1), 1);

Example 2: Search for a null element.

-- Returns null
SELECT array_position(array(3, 1, null), null);

Related functions

array_position is a complex type function. For other functions that process ARRAY, MAP, STRUCT, and JSON data, see Complex type functions.