All Products
Search
Document Center

MaxCompute:ARRAY_REPEAT

Last Updated:Jul 06, 2023

Returns a new array in which a given element is repeated several times.

Syntax

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

Description

Returns a new array in which element t is repeated count times.

Parameters

  • t: required. This parameter specifies the element that you want to repeat. The following data types are supported:

    • TINYINT, SMALLINT, INT, and BIGINT
    • FLOAT and DOUBLE
    • BOOLEAN
    • DECIMAL and DECIMALVAL
    • DATE, DATETIME, TIMESTAMP, IntervalDayTime, and IntervalYearMonth
    • STRING, BINARY, VARCHAR, and CHAR
    • ARRAY, STRUCT, and MAP
  • count: required. This parameter specifies the number of repetitions. A value of the INT type is required. The value must be greater than or equal to 0.

Return value

A value of the ARRAY type is returned. The return value varies based on the following rules:

  • If the value of count is null, null is returned.

  • If the value of count is less than 0, an empty array is returned.

Examples

  • Example 1: Repeat 123 twice and return the new array. Sample statement:

    -- The return value is [123, 123]. 
    select array_repeat('123', 2);
  • Example 2: The value of count is null. Sample statement:

    -- The return value is null. 
    select array_repeat('123', null);
  • Example 3: The value of count is less than 0. Sample statement:

    -- The return value is []. 
    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.