All Products
Search
Document Center

MaxCompute:ARRAY_REPEAT

Last Updated:Mar 26, 2026

Returns a new array in which a given element is repeated a specified number of times.

Syntax

array<T> array_repeat(T <element>, int <count>)

Parameters

ParameterRequiredTypeDescription
elementYesTThe value to repeat. Supported types: TINYINT, SMALLINT, INT, BIGINT, FLOAT, DOUBLE, BOOLEAN, DECIMAL, DECIMALVAL, DATE, DATETIME, TIMESTAMP, IntervalDayTime, IntervalYearMonth, STRING, BINARY, VARCHAR, CHAR, ARRAY, STRUCT, and MAP.
countYesINTThe number of times to repeat element. Must be greater than or equal to 0.

Return value

Returns a value of the ARRAY type.

Usage notes

  • If count is null, the function returns null.

  • If count is less than 0, the function returns an empty array.

Examples

Example 1: Repeat a string value twice.

-- Returns [123, 123]
SELECT array_repeat('123', 2);

Example 2: count is null.

-- Returns null
SELECT array_repeat('123', null);

Example 3: count is less than 0.

-- Returns []
SELECT array_repeat('123', -1);

Related functions

ARRAY_REPEAT is a complex type function. For more information about the functions that are used to process data of complex data types, such as ARRAY, MAP, STRUCT, and JSON, see Complex type functions.