Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

10. Functions at a glance

74 functions, called by name: round(price * qty, 2). Names are not reserved words, arguments are any expressions, and the argument count is checked when the query is parsed. Arity reads min..max (n.. for no maximum).

FunctionArityCategoryReturns
abs1NumericAbsolute value
sqrt1NumericSquare root
pow2NumericPower
round1..3NumericRounded value
trunc1..2NumericValue rounded toward zero
floor1NumericRounded down, integer
ceil1NumericRounded up, integer
sign1Numeric-1, 0 or 1
ln1NumericNatural logarithm
log101NumericBase-10 logarithm
log2NumericLogarithm in a base
exp1NumericExponential
min1..NumericSmallest argument or item
max1..NumericLargest argument or item
sum1..NumericSum
avg1..NumericMean
median1..NumericMiddle value
percentile2NumericValue at a fraction
stddev1..NumericSample standard deviation
div2..3NumericSafe division
if3LogicOne of two values
case2..LogicValue of the first true condition
coalesce1..Missing valuesFirst present, non-null argument
exists1Missing valuesWhether a value is present
optional1Missing valuesThe value, or null when missing
nullif2Missing valuesnull when equal
between3LogicInclusive range test
bucket2..3LogicLower bound of a range
to_int1ConversionInteger
to_float1ConversionFloat
to_string1ConversionText
to_bool1ConversionBoolean
type1ConversionKind name
len1TextLength
lower1TextLower case
upper1TextUpper case
trim1TextSpaces removed at both ends
ltrim1TextSpaces removed at the start
rtrim1TextSpaces removed at the end
concat1..TextJoined text or arrays
contains2TextSubstring or item test
starts_with2TextPrefix test
ends_with2TextSuffix test
substr2..3TextSubstring
split2TextArray of parts
replace3TextText with every occurrence replaced
index_of2TextPosition, or -1
pad_left2..3TextText padded on the left
pad_right2..3TextText padded on the right
at2ArrayItem at a position
slice2..3ArraySub-array
reverse1ArrayReversed array or text
sort_array1..2ArraySorted copy
unique1ArrayDistinct items
flatten1ArrayArray flattened one level
range2..3ArrayIntegers
keys1ObjectKeys
values1ObjectValues
merge1..ObjectShallow merge
get2..3ObjectValue under a key
has2ObjectWhether a key is present
now0DateCurrent time
parse_date1DateEpoch milliseconds
date_trunc2DateStart of a unit
date_add3DateDate moved by n units
date_diff3DateUnit boundaries crossed
date_part2DateA part of a date
date_format1..2DateFormatted text
fiscal_year2FiscalFiscal year
fiscal_month2FiscalMonth in the fiscal year
fiscal_start2FiscalFirst day of the fiscal year
fiscal_end2FiscalLast day of the fiscal year
month_end1DateLast day of the month
days_in2DateDays in the unit

group measures (sum, avg, min, max, first, last, count, list, median, percentile, stddev) and window functions (lag, lead, cumsum, first, last, row_number) are directives of their stage, not calls.

Common rules

  • Missing arguments. A function reading a missing field fails, like any expression, except exists, coalesce and optional, made for that. Write field? to pass null instead.
  • Null. There is no general null propagation: numeric, text and date functions refuse null (`upper` expects a string, found Null). The functions that accept it: coalesce, exists, optional, nullif, if/case branches, concat (skips it), to_int/to_float/to_string (keep it), type, merge (skips it), and the aggregates sum, avg, median, percentile, stddev (skip null items; min and max refuse them).
  • Kinds. Functions check their argument kinds: upper(42) is an error. Convert with to_string, to_int, to_float.
  • Positions. Text positions count characters; negative positions count from the end; arrays are 0-based.
  • Determinism. Every function is deterministic except now().