FLATTEN()

All functions > ARRAY > FLATTEN()

Flattens a nested array structure into a single-level array.

Signatures

Returns: Single-level array of inner elements

FLATTEN(array: ARRAY<ARRAY<T>>) → ARRAY<T>
sql
ParameterTypeRequiredDescription
arrayARRAY<ARRAY<T>>YesNested array to flatten one level

Notes

  • Flattens one level of nesting
  • Preserves element order
  • Works with any array element type
  • Empty nested arrays are removed from result
  • Pass an array of arrays (for example ARRAY[ARRAY[1, 2], ARRAY[3, 4]]), not multiple sibling arguments

Aliases

  • ARRAY_FLATTEN

See also

Examples

FeatureQL
SELECT
    -- Flatten numeric arrays
    f1 := FLATTEN(ARRAY(ARRAY(1, 2, 3), ARRAY(4, 5, 6))),
    -- Flatten string arrays
    f2 := FLATTEN(ARRAY(ARRAY('A', 'B'), ARRAY('C'), ARRAY('D', 'E'))),
    -- Empty arrays ignored
    f3 := FLATTEN(ARRAY(ARRAY()::BIGINT[], ARRAY(1, 2), ARRAY()::BIGINT[])),
    -- Empty input array
    f4 := FLATTEN(ARRAY()::ARRAY(BIGINT)[])
;
Result
f1 ARRAYf2 ARRAYf3 ARRAYf4 ARRAY
[1, 2, 3, 4, 5, 6][A, B, C, D, E][1, 2][]