ClickHouse Functions/Array Functions

arrayMap

Transform every element of an array with a lambda — no subquery, no UNNEST.

Signature

arrayMap(func: x -> expr, arr: Array(T)): Array(U)

Returns

Array(U)

What it does

Applies a lambda function to every element of an array and returns a new array of the transformed results. Uses ClickHouse's higher-order lambda syntax (x -> expr).

arrayMap is ClickHouse's higher-order array transform: you pass a lambda (x -> expr) and an array, and it returns a new array where each element is the result of running the lambda on the original. Because ClickHouse arrays are first-class column values, arrayMap chains naturally with groupArray — collect rows into an array with groupArray, then reshape each value inline without a correlated subquery or a second GROUP BY pass. The multi-array form arrayMap((x, y) -> ..., arr1, arr2) walks several equal-length arrays in lockstep, which is how you combine collected fields (say, prices and quantities) element by element.

Notes

  • The lambda uses ClickHouse arrow syntax (x -> expr), not a SQL function name — express it inside selectExpr in hypequery.
  • The multi-array form arrayMap((x, y) -> x * y, prices, quantities) requires every input array to be the same length or the query errors.
  • Pair with groupArray to collect rows first, then transform each value inline instead of writing a subquery or second aggregation pass.

Example SQL

arrayMap in ClickHouse SQL

arrayMap-example.sql

TypeScript with hypequery

Use arrayMap 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 arrayMap when you need them inside a builder query.

adjusted-prices.ts

Common questions

What developers search for with arrayMap

Transform an array in ClickHouse

arrayMap runs a lambda over every element of an array and returns a new array. Use arrayMap(x -> expr, arr) to convert units, round values, or reshape each element without touching the rest of the query.

arrayMap with groupArray

Collect rows into an array with groupArray, then wrap it in arrayMap to transform each collected value in place — no correlated subquery and no second GROUP BY.

ClickHouse arrayMap in TypeScript

hypequery has no dedicated arrayMap builder method, but selectExpr lets you pass arrayMap(x -> round(x * 1.2, 2), prices) straight into .select([...]) and get typed rows back.

FAQ

Frequently asked questions about arrayMap

What does arrayMap return in ClickHouse?

It returns a new array of the same length as the input, where each element is the result of applying the lambda (x -> expr) to the corresponding source element.

Can arrayMap work over multiple arrays at once?

Yes. The multi-array form arrayMap((x, y) -> ..., arr1, arr2) walks several arrays in parallel, so you can combine collected fields element by element. All input arrays must be the same length.

How do I use arrayMap in hypequery?

There is no arrayMap method on the query builder. Pass the expression through selectExpr, for example selectExpr('arrayMap(x -> round(x * 1.2, 2), groupArray(price))', 'adjusted_prices') inside .select([...]).

Related functions

Functions used alongside arrayMap

Next step

Use arrayMap in a type-safe TypeScript query

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