Skip to main content
Test, transform, and aggregate over array values — the active_channels, active_emails, and active_phone_numbers columns on users, and JSON arrays like user_properties -> 'tags'. Lambda-based functions take an x -> expression argument that runs once per element.

= ANY (array)

Tests whether a scalar value equals any element of an array. It is the most common way to check array membership in a WHERE clause. Syntax
Arguments
  • value — the scalar to look for.
  • array — the array (or JSON array) to search.
Returned value
  • true if value matches at least one element, otherwise false. Boolean.
Example
Users with email as an active channel

array_length

Returns the number of elements in the given dimension of an array. Syntax
Arguments
  • arr — the input array.
  • dimension — the array dimension to measure; use 1 for a flat array.
Returned value
  • The element count for that dimension. Integer.
Example
Users with at least one active email

cardinality

Returns the number of elements in an array. Syntax
Arguments
  • arr — the input array.
Returned value
  • The element count. Integer.
Example
Users active on two or more channels

hasAll

Tests whether an array contains every element of a second array. Syntax
Arguments
  • set — the array to search within.
  • subset — the array whose elements must all be present.
Returned value
  • 1 if set contains all elements of subset, otherwise 0. An empty subset returns 1.
Example
Users active on both email and sms

hasAny

Tests whether two arrays share at least one common element. Syntax
Arguments
  • arr1 — the first array.
  • arr2 — the second array.
Returned value
  • 1 if the arrays have any element in common, otherwise 0.
Example
Users active on whatsapp or sms

arrayExists

Returns whether at least one element satisfies a lambda condition. Syntax
Arguments
  • x -> condition — a lambda returning a boolean for each element x.
  • arr — the array to test.
Returned value
  • 1 if the condition holds for any element, otherwise 0.
Example
Users with an Acme work email

arrayFilter

Returns the elements of an array for which a lambda condition is true. Syntax
Arguments
  • x -> condition — a lambda returning a boolean for each element x.
  • arr — the array to filter.
Returned value
  • An array of the elements that satisfy the condition. Array.
Example
Keep only Acme email addresses

arrayMap

Applies a lambda to each element and returns the resulting array. Syntax
Arguments
  • x -> expression — a lambda producing a new value for each element x.
  • arr — the input array.
Returned value
  • An array of the transformed elements, same length as the input. Array.
Example
Uppercase each active channel

array_position

Returns the 1-based index of the first element equal to the given value. Syntax
Arguments
  • arr — the array to search.
  • value — the element to locate.
Returned value
  • The 1-based position of the first match, or NULL if the value is not present. Integer.
Example
Position of email in each channel list

arrayUniq

Returns the number of distinct elements in an array. Syntax
Arguments
  • arr — the input array.
Returned value
  • The count of distinct elements. Integer.
Example
Count of distinct active channels

arraySort

Returns the array sorted in ascending order. Syntax
Arguments
  • arr — the input array.
Returned value
  • The array sorted ascending. Array.
Example
Channels sorted alphabetically

arrayConcat

Combines several arrays into one, preserving order and duplicates. Syntax
Arguments
  • arr1, arr2, ... — two or more arrays of a compatible element type.
Returned value
  • A single array with the elements of all inputs, in argument order. Array.
Example
All contact strings on the profile

arrayDistinct

Returns the distinct elements of an array, dropping duplicates. Syntax
Arguments
  • arr — the input array.
Returned value
  • An array containing each distinct element once. Array.
Example
Distinct active channels per user

array_append

Appends a value to the end of an array. Syntax
Arguments
  • arr — the input array.
  • value — the element to append; must match the array’s element type.
Returned value
  • A new array with value added as the last element. Array.
Example
Add in_app to the active channel list

arrayIntersect

Returns the distinct elements present in every one of the given arrays. Syntax
Arguments
  • arr1, arr2, ... — two or more arrays.
Returned value
  • An array of distinct elements common to all inputs. Array.
Example
Which of email/sms a user has active

arraySlice

Returns a contiguous slice of an array. Syntax
Arguments
  • arr — the input array.
  • offset — 1-based start index; a negative offset counts from the end.
  • length — optional number of elements to return; omitted means to the end of the array.
Returned value
  • The selected sub-array. Array.
Example
First two active emails

arrayReverse

Returns the array with its elements in reverse order. Syntax
Arguments
  • arr — the input array.
Returned value
  • An array of the same length with the element order reversed. Array.
Example
Channels in reverse order

arrayPushBack

Appends a value to the end of an array. Syntax
Arguments
  • arr — the input array.
  • value — the element to append; must match the array’s element type.
Returned value
  • A new array with value as the last element. Array.
Example
Append in_app to the channel list

arrayPushFront

Prepends a value to the start of an array. Syntax
Arguments
  • arr — the input array.
  • value — the element to prepend; must match the array’s element type.
Returned value
  • A new array with value as the first element. Array.
Example
Prepend the primary channel

arrayPopBack

Removes the last element of an array. Syntax
Arguments
  • arr — the input array.
Returned value
  • A copy of the array without its last element. Array.
Example
All but the most recently added email

arrayPopFront

Removes the first element of an array. Syntax
Arguments
  • arr — the input array.
Returned value
  • A copy of the array without its first element. Array.
Example
All but the first email

arrayAvg

Returns the arithmetic mean of a numeric array, optionally over a lambda applied to each element. Syntax
Arguments
  • x -> expression — optional lambda evaluated per element to produce the numbers to average.
  • arr — the input array.
Returned value
  • The average of the (mapped) elements. Float.
Example
Average email length per user

arraySum

Returns the sum of a numeric array, optionally over a lambda applied to each element. Syntax
Arguments
  • x -> expression — optional lambda evaluated per element to produce the numbers to sum.
  • arr — the input array.
Returned value
  • The sum of the (mapped) elements. Numeric.
Example
Total characters across all emails

arrayMin

Returns the smallest element of an array, optionally over a lambda applied to each element. Syntax
Arguments
  • x -> expression — optional lambda evaluated per element.
  • arr — the input array.
Returned value
  • The minimum of the (mapped) elements. Same type as the elements.
Example
Shortest phone number length per user

arrayMax

Returns the largest element of an array, optionally over a lambda applied to each element. Syntax
Arguments
  • x -> expression — optional lambda evaluated per element.
  • arr — the input array.
Returned value
  • The maximum of the (mapped) elements. Same type as the elements.
Example
Longest email length per user

countEqual

Returns how many elements of an array equal a given value. Syntax
Arguments
  • arr — the input array.
  • value — the value to count occurrences of.
Returned value
  • The number of elements equal to value. Integer.
Example
How many times email appears in the channel list

arrayWithConstant

Builds an array of a given length where every element is the same value. Syntax
Arguments
  • length — the number of elements to produce.
  • value — the fill value; the result preserves this value’s type.
Returned value
  • An array of length copies of value. Array.
Example
A placeholder array of two sms entries

array_to_string

Joins array elements into a single string using a separator. Syntax
Arguments
  • arr — the input array.
  • separator — the string placed between elements.
Returned value
  • The concatenated string. String.
Example
Channels as a comma-separated string

unnest

Expands an array into a set of rows, one row per element. Syntax
Arguments
  • arr — the array to expand.
Returned value
  • A set of rows, each carrying one element of the array. Set of values.
Example
One row per active channel per user

range

Produces an array of consecutive integers over a half-open interval (ClickHouse only). Syntax
Arguments
  • start — optional first integer; defaults to 0.
  • end — the exclusive upper bound.
  • step — optional increment; defaults to 1.
Returned value
  • An array of integers over [start, end). Array.
Example
Integers 0 through 4

generate_series

Produces an inclusive array of consecutive integers between two bounds (ClickHouse only). Syntax
Arguments
  • start — the first integer in the series.
  • stop — the last integer in the series (inclusive).
Returned value
  • An array of integers from start to stop inclusive. Array.
Example
Integers 1 through 5

array_compact

Removes consecutive duplicate elements from an array. Non-adjacent duplicates are kept (ClickHouse only). Syntax
Arguments
  • arr — the input array.
Returned value
  • An array with runs of consecutive equal elements collapsed to a single element. Array.
Example
Collapse repeated adjacent channels

array_resize

Changes the length of an array, truncating from the end or padding with a fill value (ClickHouse only). Syntax
Arguments
  • arr — the input array.
  • size — the target length.
  • extender — optional value used to pad when growing; defaults to the element type’s zero value.
Returned value
  • An array of exactly size elements. Array.
Example
Normalize email lists to length 3