ARRAY_REPEAT is used to generate an array of a specified length, where all elements have the given value.
ARRAY_REPEAT(element, count)
element: Any storage type supported in an ARRAY.
count: Integer type, specifies the length of the returned array.
ARRAY<T>, where T is the type of element.count copies of the same element.count = 0 or NULL, returns an empty array.element is NULL, all elements in the array are NULL.ARRAY_WITH_CONSTANT, but the parameter order is reversed.Simple example
SELECT ARRAY_REPEAT('hello', 3); +---------------------------------+ | ARRAY_REPEAT('hello', 3) | +---------------------------------+ | ["hello", "hello", "hello"] | +---------------------------------+
Special cases
SELECT ARRAY_REPEAT('hello', 0); +---------------------------------+ | ARRAY_REPEAT('hello', 0) | +---------------------------------+ | [] | +---------------------------------+ SELECT ARRAY_REPEAT('hello', NULL); +------------------------------------+ | ARRAY_REPEAT('hello', NULL) | +------------------------------------+ | [] | +------------------------------------+ SELECT ARRAY_REPEAT(NULL, 2); +------------------------------+ | ARRAY_REPEAT(NULL, 2) | +------------------------------+ | [null, null] | +------------------------------+ SELECT ARRAY_REPEAT(NULL, NULL); +---------------------------------+ | ARRAY_REPEAT(NULL, NULL) | +---------------------------------+ | [] | +---------------------------------+ -- Returns error: INVALID_ARGUMENT SELECT ARRAY_REPEAT('hello', -1);