ARRAY_REPEAT
Updated at:
Copy as MD
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
| Parameter | Required | Type | Description |
|---|---|---|---|
element | Yes | T | The 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. |
count | Yes | INT | The 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
countis null, the function returns null.If
countis 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.
Is this page helpful?