Skip to content

Functions ​

Every function, by what it works on: 36 that take one row's values and 12 aggregates for summarize.

A function given null returns null, except the four that exist to handle it — isnull, isnotnull, coalesce and iff.

Null ​

FunctionGives
isnull(x), isnotnull(x)whether x is null
coalesce(a, b, …)The first argument that is not null. All must share a type.
iff(c, a, b)a when c is true, otherwise b. Same as c ? a : b.

Numbers ​

FunctionGives
format(x, decimals)x with the point moved left decimals places, exact: format(1e18, 18) is 1.0
parse(d, decimals)The reverse: parse(1.05, 18) is 1050000000000000000. Extra digits are dropped.
abs(x)the absolute value
pow(base, exp)base to the power exp. exp may not be negative, and CQL refuses very large results.
tobigint(x)A whole number from bytes, a string or a decimal. null when it cannot.
todecimal(x)A decimal from a whole number or a string. null when it cannot.

Time ​

FunctionGives
bin(t, d)t rounded down to a multiple of d — the buckets every 1h samples on
blockat(chain, t)The last block at or before t. null before the chain began.
datetime(x)A datetime from an ISO-8601 string or unix seconds. null when it cannot parse.
unixtime(t)unix seconds
duration(n)a duration of n seconds, the function form of 3600s
totalseconds(d)the seconds in a duration

Text and bytes ​

FunctionGives
tostring(x)Any value as text: an address as chain:0x…, a datetime as 2026-09-01T00:00:00Z.
tohex(x)A number of 0 or more, bytes or an address as 0x…. An address comes without its chain.
concat(a, b, …)strings joined, or bytes joined — not both in one call
len(x)the length of a string in characters, of bytes in bytes, of an array in elements
slice(b, start, len)len bytes of b from start. null when out of range.
keccak256(x)the Keccak-256 of bytes or a string, as bytes32
pad32(x)a value left-padded to 32 bytes, the way the ABI encodes a word

Addresses and chains ​

FunctionGives
address(n)the 20 bytes a constant integer stands for, without a chain: address(0) is the zero address, and t.from == address(0) matches it on any chain
address(chain, b)an address on chain from 20 bytes, or from a constant integer: address('ethereum', 0)
raw(a)the 20 bytes of an address, without its chain
chain(a)The chain of an address. chain(1) and chain('ethereum') name one directly.
iscontract(a)whether there is code at a at the row's block

ABI encoding ​

FunctionGives
selector(sig)the 4-byte selector of a function signature
topic0(sig)the 32-byte topic of an event signature
abi_encode(sig, args…)the arguments encoded as bytes, without a selector
abi_decode(sig, data)data decoded by a signature. A record for several outputs, null on a misfit.

Calls ​

FunctionGives
revert_reason(call)null when the call succeeded. Otherwise its Error(string) text, a Panic code, a decoded custom error, or the raw bytes.

Arrays ​

FunctionGives
contains(xs, x)Whether x is an element of xs. The same test as x in xs.
array_concat(a, b, …)the arrays joined
array_sort(xs)sorted ascending, null first

Storage ​

FunctionGives
slot(mapping: n, key: k)the slot of mapping[k] when the mapping is in slot n
slot(array: n, index: i)the slot of element i of a dynamic array in slot n
slot(base: s, offset: k)slot s + k, for a struct member

These follow Solidity's layout exactly. A nested mapping passes an inner slot(…) as the mapping: argument. They are the only functions that take named arguments. The names select the form, so name both arguments: CQL refuses slot(0, k).

Aggregates ​

For summarize. Rows reach an aggregate in pipeline order — chain, block, address, transaction, log. That order defines first, last and make_list.

Each aggregate is one full item of the summarize list. It cannot be part of an expression or go inside another function. To format a sum, write summarize total = sum(t.value), then | extend total = format(total, 18).

FunctionGives
count()the rows in the group
count_distinct(x)the distinct values of x
sum(x), min(x), max(x)exact
avg(x)To 38 significant digits. CQL reports a rounded average as CQL4901.
first(x), last(x)the first and last value in pipeline order
make_list(x)every value, in order
make_set(x)The distinct values. All null values count as one.
arg_max(x, cols…), arg_min(x, cols…)The listed columns from the row where x is largest or smallest. Write * for all of them. A listed value that is not a column gets the name _0, _1, … from its place in the list.

See also ​