ARRAY

Construct an ARRAY value from a list of expressions.

Category: collectionReturns: ARRAY<T>Dialect: Standard

Syntax

ARRAY(expr1, expr2, ...)

Description

## Overview Constructs an ARRAY value from a list of expressions. ARRAY is the canonical literal constructor for array-typed values and is used everywhere a collection literal is needed: in DDL defaults, in projections that assemble per-row arrays from scalar columns, and in arguments to other array functions. Typical uses include building row-level arrays from individual column values, composing test fixtures inline, and constructing singleton arrays to pass to ARRAY_CAT or ARRAY_UNION. ## Behavior - Returns an ARRAY<T> whose element type T is the common super-type of the argument expressions. - Element order matches the order of the supplied expressions. - Zero-argument form requires an explicit type cast: CAST(ARRAY() AS ARRAY<INT>) produces an empty ARRAY<INT>. - NULL arguments are preserved as NULL elements; they do not cause the whole literal to become NULL. - The bracket syntax ARRAY[expr1, expr2, ...] is an equivalent form. - Never mutates its arguments. ## Null and empty handling - NULL expressions are accepted and appear as NULL elements. - An empty ARRAY() literal without a type cast raises because the element type is undefined. - The resulting array is non-NULL; even an all-NULL list produces a non-NULL array of NULLs. ## Compatibility - Matches the standard SQL array/map convention. Both function-call form and bracket form are accepted; behaviour is identical. - The element type is inferred from the widest common type; explicit casts may be required when mixing numeric widths.

Parameters

NameTypeDescription
exprSpecifies one or more expressions that become the elements of the resulting array, in the order supplied. All expressions must share a compatible element type.

Examples

-- Integer array
SELECT ARRAY(1, 2, 3);  -- [1, 2, 3]
-- String array
SELECT ARRAY('a', 'b', 'c');  -- ['a', 'b', 'c']
-- Array with NULL elements
SELECT ARRAY(1, CAST(NULL AS INT), 3);  -- [1, NULL, 3]
-- Single-element array
SELECT ARRAY(42);  -- [42]
-- Bracket syntax is equivalent
SELECT ARRAY[10, 20, 30];  -- [10, 20, 30]
-- Build a per-row constant array of tags derived from columns
SELECT session_id, ARRAY(country, device, browser) AS dimensions
FROM analytics.events.user_sessions;

Pitfalls

See Also

Open in interactive docs →   DeltaForge home →