ClickHouse Functions/Aggregate Functions

groupArray

Collect values into an array — session stitching, event sequences, and path analysis.

Signature

groupArray([max_size])(column): Array

Returns

Array(T)

What it does

Collects all values of a column within a group into an Array. groupArray(10)(col) limits the array to 10 elements. Essential for building event sequences, path arrays, and collecting ordered lists.

groupArray() is ClickHouse's primary way to materialise multiple rows into a single array value per group. Combined with arrayJoin, groupArrayMovingAvg, and array functions, it enables event sequence analysis, funnel reconstruction, and session stitching entirely in SQL. The optional max_size argument caps memory usage when collecting from large groups.

Notes

  • Ordering within the array is not guaranteed — use arraySort(groupArray(col)) if order matters.
  • groupArraySorted(n)(col, order_col) collects the top-n values by a sort key in one pass.
  • For large groups, always cap with groupArray(max_size) to avoid OOM errors.

Example SQL

groupArray in ClickHouse SQL

groupArray-example.sql

TypeScript with hypequery

Use groupArray in a typed TypeScript query

hypequery gives you a type-safe query builder for ClickHouse. The generated schema maps your ClickHouse columns to TypeScript types, and raw SQL expressions let you incorporate functions like groupArray when you need them inside a builder query.

session-paths.ts

Common questions

What developers search for with groupArray

ClickHouse collect rows into array

groupArray(column) is the GROUP_CONCAT equivalent in ClickHouse — it produces an Array per group. Filter and sort the array with array functions afterward.

ClickHouse session path analysis

GROUP BY session_id, then groupArray(page_path) WITHIN GROUP ordered by ts gives per-session page sequences for path and funnel analysis.

FAQ

Frequently asked questions about groupArray

Is the order of elements in groupArray guaranteed?

No. Use arraySort(groupArray(col)) or groupArraySorted() if order matters.

Related functions

Functions used alongside groupArray

More function pages are being added. Use the full function index for the currently published reference set.

Next step

Use groupArray in a type-safe TypeScript query

hypequery generates TypeScript types from your ClickHouse schema. Use groupArray alongside the builder, and reach for raw SQL expressions when the function is not exposed as a dedicated helper.