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 aWHERE clause.
Syntax
value— the scalar to look for.array— the array (or JSON array) to search.
trueifvaluematches at least one element, otherwisefalse. Boolean.
Users with email as an active channel
array_length
Returns the number of elements in the given dimension of an array. Syntaxarr— the input array.dimension— the array dimension to measure; use1for a flat array.
- The element count for that dimension. Integer.
Users with at least one active email
cardinality
Returns the number of elements in an array. Syntaxarr— the input array.
- The element count. Integer.
Users active on two or more channels
hasAll
Tests whether an array contains every element of a second array. Syntaxset— the array to search within.subset— the array whose elements must all be present.
1ifsetcontains all elements ofsubset, otherwise0. An emptysubsetreturns1.
Users active on both email and sms
hasAny
Tests whether two arrays share at least one common element. Syntaxarr1— the first array.arr2— the second array.
1if the arrays have any element in common, otherwise0.
Users active on whatsapp or sms
arrayExists
Returns whether at least one element satisfies a lambda condition. Syntaxx -> condition— a lambda returning a boolean for each elementx.arr— the array to test.
1if the condition holds for any element, otherwise0.
Users with an Acme work email
arrayFilter
Returns the elements of an array for which a lambda condition is true. Syntaxx -> condition— a lambda returning a boolean for each elementx.arr— the array to filter.
- An array of the elements that satisfy the condition. Array.
Keep only Acme email addresses
arrayMap
Applies a lambda to each element and returns the resulting array. Syntaxx -> expression— a lambda producing a new value for each elementx.arr— the input array.
- An array of the transformed elements, same length as the input. Array.
Uppercase each active channel
array_position
Returns the 1-based index of the first element equal to the given value. Syntaxarr— the array to search.value— the element to locate.
- The 1-based position of the first match, or
NULLif the value is not present. Integer.
Position of email in each channel list
arrayUniq
Returns the number of distinct elements in an array. Syntaxarr— the input array.
- The count of distinct elements. Integer.
Count of distinct active channels
arraySort
Returns the array sorted in ascending order. Syntaxarr— the input array.
- The array sorted ascending. Array.
Channels sorted alphabetically
arrayConcat
Combines several arrays into one, preserving order and duplicates. Syntaxarr1, arr2, ...— two or more arrays of a compatible element type.
- A single array with the elements of all inputs, in argument order. Array.
All contact strings on the profile
arrayDistinct
Returns the distinct elements of an array, dropping duplicates. Syntaxarr— the input array.
- An array containing each distinct element once. Array.
Distinct active channels per user
array_append
Appends a value to the end of an array. Syntaxarr— the input array.value— the element to append; must match the array’s element type.
- A new array with
valueadded as the last element. Array.
Add in_app to the active channel list
arrayIntersect
Returns the distinct elements present in every one of the given arrays. Syntaxarr1, arr2, ...— two or more arrays.
- An array of distinct elements common to all inputs. Array.
Which of email/sms a user has active
arraySlice
Returns a contiguous slice of an array. Syntaxarr— 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.
- The selected sub-array. Array.
First two active emails
arrayReverse
Returns the array with its elements in reverse order. Syntaxarr— the input array.
- An array of the same length with the element order reversed. Array.
Channels in reverse order
arrayPushBack
Appends a value to the end of an array. Syntaxarr— the input array.value— the element to append; must match the array’s element type.
- A new array with
valueas the last element. Array.
Append in_app to the channel list
arrayPushFront
Prepends a value to the start of an array. Syntaxarr— the input array.value— the element to prepend; must match the array’s element type.
- A new array with
valueas the first element. Array.
Prepend the primary channel
arrayPopBack
Removes the last element of an array. Syntaxarr— the input array.
- A copy of the array without its last element. Array.
All but the most recently added email
arrayPopFront
Removes the first element of an array. Syntaxarr— the input array.
- A copy of the array without its first element. Array.
All but the first email
arrayAvg
Returns the arithmetic mean of a numeric array, optionally over a lambda applied to each element. Syntaxx -> expression— optional lambda evaluated per element to produce the numbers to average.arr— the input array.
- The average of the (mapped) elements. Float.
Average email length per user
arraySum
Returns the sum of a numeric array, optionally over a lambda applied to each element. Syntaxx -> expression— optional lambda evaluated per element to produce the numbers to sum.arr— the input array.
- The sum of the (mapped) elements. Numeric.
Total characters across all emails
arrayMin
Returns the smallest element of an array, optionally over a lambda applied to each element. Syntaxx -> expression— optional lambda evaluated per element.arr— the input array.
- The minimum of the (mapped) elements. Same type as the elements.
Shortest phone number length per user
arrayMax
Returns the largest element of an array, optionally over a lambda applied to each element. Syntaxx -> expression— optional lambda evaluated per element.arr— the input array.
- The maximum of the (mapped) elements. Same type as the elements.
Longest email length per user
countEqual
Returns how many elements of an array equal a given value. Syntaxarr— the input array.value— the value to count occurrences of.
- The number of elements equal to
value. Integer.
How many times email appears in the channel list
arrayWithConstant
Builds an array of a given length where every element is the same value. Syntaxlength— the number of elements to produce.value— the fill value; the result preserves this value’s type.
- An array of
lengthcopies ofvalue. Array.
A placeholder array of two sms entries
array_to_string
Joins array elements into a single string using a separator. Syntaxarr— the input array.separator— the string placed between elements.
- The concatenated string. String.
Channels as a comma-separated string
unnest
Expands an array into a set of rows, one row per element. Syntaxarr— the array to expand.
- A set of rows, each carrying one element of the array. Set of values.
One row per active channel per user
range
Produces an array of consecutive integers over a half-open interval (ClickHouse only). Syntaxstart— optional first integer; defaults to0.end— the exclusive upper bound.step— optional increment; defaults to1.
- An array of integers over
[start, end). Array.
Integers 0 through 4
generate_series
Produces an inclusive array of consecutive integers between two bounds (ClickHouse only). Syntaxstart— the first integer in the series.stop— the last integer in the series (inclusive).
- An array of integers from
starttostopinclusive. Array.
Integers 1 through 5
array_compact
Removes consecutive duplicate elements from an array. Non-adjacent duplicates are kept (ClickHouse only). Syntaxarr— the input array.
- An array with runs of consecutive equal elements collapsed to a single element. Array.
Collapse repeated adjacent channels
array_resize
Changes the length of an array, truncating from the end or padding with a fill value (ClickHouse only). Syntaxarr— the input array.size— the target length.extender— optional value used to pad when growing; defaults to the element type’s zero value.
- An array of exactly
sizeelements. Array.
Normalize email lists to length 3