All Products
Search
Document Center

MaxCompute:ARRAYS_ZIP

Last Updated:Mar 26, 2026

ARRAYS_ZIP merges multiple arrays into a single struct array, where the Nth struct contains the Nth element from each input array. For example, the first struct holds the first element of every input array, the second struct holds the second elements, and so on.

Syntax

array<struct<T, U, ...>> arrays_zip(array<T> <a>, array<U> <b>[, ...])

Parameters

ParameterRequiredDescription
aYesAn array. T specifies the element data type.
bYesAn array. U specifies the element data type.
...NoAdditional arrays.

Array elements can be of any supported data type, including TINYINT, SMALLINT, INT, BIGINT, FLOAT, DOUBLE, BOOLEAN, DECIMAL, DECIMALVAL, DATE, DATETIME, TIMESTAMP, IntervalDayTime, IntervalYearMonth, STRING, BINARY, VARCHAR, CHAR, ARRAY, STRUCT, and MAP.

Return value

Returns a value of the ARRAY type, structured as array<struct<T, U, ...>>.

  • Unequal-length arrays: If an input array has fewer than N elements, the Nth position in that array is filled with null. The output length matches the longest input array.

  • NULL input: If any input array is NULL, the function returns NULL.

Examples

Equal-length arrays

-- Returns [{0:1, 1:2}, {0:2, 1:3}, {0:3, 1:4}].
SELECT arrays_zip(array(1, 2, 3), array(2, 3, 4));

Arrays of different lengths

When input arrays have different lengths, null fills the missing positions.

-- Returns [{0:1, 1:4}, {0:2, 1:5}, {0:3, 1:null}].
-- The third struct uses null for the second array, which has only 2 elements.
SELECT arrays_zip(array(1, 2, 3), array(4, 5));

Related functions

ARRAYS_ZIP is a complex type function. For more information about functions for processing ARRAY, MAP, STRUCT, and JSON data, see Complex type functions.