COMBINATIONS()

All functions > ARRAY > COMBINATIONS()

Returns all 2-element sub-groups of the input array as an array of 2-element arrays.

Signatures

Returns: All unordered pairs of elements (with replacement when duplicates appear in the input)

COMBINATIONS(array: ARRAY<T>) → ARRAY<ARRAY<T>>
sql
ParameterTypeRequiredDescription
arrayARRAY<T>YesInput array (scalar or ROW elements)

Notes

  • Always selects pairs of two elements (fixed arity)
  • Supports scalar arrays, arrays of rows (ARRAY<ROW(...)>), and nested arrays (ARRAY<ARRAY<T>>)
  • When the input has no duplicate values, each pair is an unordered subset
  • Duplicate input values produce duplicate pairs in the result
  • Returns an empty array when fewer than two elements are available

See also

Examples

FeatureQL
SELECT
    -- String pairs without duplicates
    f1 := COMBINATIONS(ARRAY('foo', 'bar', 'baz')),
    -- Integer pairs
    f2 := COMBINATIONS(ARRAY(1, 2, 3)),
    -- Duplicate input values
    f3 := COMBINATIONS(ARRAY(1, 2, 2)),
    -- Empty input array
    f4 := COMBINATIONS(ARRAY()::BIGINT[]),
    -- Pairs of rows from ZIP
    f5 := COMBINATIONS(ZIP(ARRAY(1, 2, 3) AS x, ARRAY('a', 'b', 'c') AS y)),
    -- Pairs of nested sub-arrays
    f6 := COMBINATIONS(ARRAY(ARRAY(1, 2), ARRAY(3, 4), ARRAY(5, 6)))
;
Result
f1 ARRAYf2 ARRAYf3 ARRAYf4 ARRAYf5 ARRAYf6 ARRAY
[[foo, bar], [foo, baz], [bar, baz]][[1, 2], [1, 3], [2, 3]][[1, 2], [1, 2], [2, 2]][][[{x: 1, y: a}, {x: 2, y: b}], [{x: 1, y: a}, {x: 3, y: c}], [{x: 2, y: b}, {x: 3, y: c}]][[[1, 2], [3, 4]], [[1, 2], [5, 6]], [[3, 4], [5, 6]]]

Last update at: 2026/06/20 10:08:10