Documentation Index
Fetch the complete documentation index at: https://private-7c7dfe99-page-updates.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
Arithmetic functions
Overview
Arithmetic functions work for any two operands of typeUInt8, UInt16, UInt32, UInt64, Int8, Int16, Int32, Int64, Float32, or Float64.
Before performing the operation, both operands are cast to the result type. The result type is determined as follows (unless specified
differently in the function documentation below):
- If both operands are up to 32 bits wide, the size of the result type will be the size of the next bigger type following the bigger of the
two operands (integer size promotion). For example,
UInt8 + UInt16 = UInt32orFloat32 * Float32 = Float64. - If one of the operands has 64 or more bits, the size of the result type will be the same size as the bigger of the two operands. For
example,
UInt32 + UInt128 = UInt128orFloat32 * Float64 = Float64. - If one of the operands is signed, the result type will also be signed, otherwise it will be unsigned. For example,
UInt32 * Int32 = Int64orUInt32 * UInt32 = UInt64.
abs
Introduced in: v1.1.0 Calculates the absolute value ofx. Has no effect if x is of an unsigned type. If x is of a signed type, it returns an unsigned number.
Syntax
x— Value to get the absolute value of
x
Examples
Usage example
Query
Response
avg2
Introduced in: v25.11.0 Computes and returns the average value of the provided arguments. Supports numerical and temporal types. Syntaxx1, x2]— Accepts two values for averaging.
Query
Response
Query
Response
Query
Response
Query
Response
Query
Response
byteSwap
Introduced in: v23.10.0 Reverses the bytes of an integer, i.e. changes its endianness. The below example can be worked out in the following manner:- Convert the base-10 integer to its equivalent hexadecimal format in big-endian format, i.e. 3351772109 -> C7 C7 FB CD (4 bytes)
- Reverse the bytes, i.e. C7 C7 FB CD -> CD FB C7 C7
- Convert the result back to an integer assuming big-endian, i.e. CD FB C7 C7 -> 3455829959 One use case of this function is reversing IPv4s:
x— An integer value.(U)Int*
x with bytes reversed. (U)Int*
Examples
Usage example
Query
Response
Query
Response
Query
Response
Query
Response
Query
Response
divide
Introduced in: v1.1.0 Calculates the quotient of two valuesa and b. The result type is always Float64.
Integer division is provided by the intDiv function.
Division by
0 returns inf, -inf, or nan.x— Dividend -y— Divisor
Query
Response
Query
Response
divideDecimal
Introduced in: v22.12.0 Performs division on two decimals. Result value will be of type Decimal256. Result scale can be explicitly specified byresult_scale argument (const Integer in range [0, 76]). If not specified, the result scale is the max scale of given arguments.
These function work significantly slower than usual
divide.
In case you don’t really need controlled precision and/or need fast computation, consider using divide.x— First value: Decimal. -y— Second value: Decimal. -result_scale— Scale of result. Type Int/UInt.
Decimal256
Examples
Example 1
Query
Response
Query
Response
divideOrNull
Introduced in: v25.5.0 Same asdivide but returns NULL when dividing by zero.
Syntax
x— Dividend -y— Divisor
Query
Response
gcd
Introduced in: v1.1.0 Returns the greatest common divisor of two values a and b. An exception is thrown when dividing by zero or when dividing a minimal negative number by minus one. Syntaxx— First integer -y— Second integer
x and y.
Examples
Usage example
Query
Response
ifNotFinite
Introduced in: v20.3.0 Checks whether a floating point value is finite. You can get a similar result by using the ternary operator:isFinite(x) ? x : y.
Syntax
xifxis finite.yifxis not finite.
Query
Response
intDiv
Introduced in: v1.1.0 Performs an integer division of two valuesx by y. In other words it
computes the quotient rounded down to the next smallest integer.
The result has the same width as the dividend (the first parameter).
An exception is thrown when dividing by zero, when the quotient does not fit
in the range of the dividend, or when dividing a minimal negative number by minus one.
Syntax
x— Left hand operand. -y— Right hand operand.
x and y
Examples
Integer division of two floats
Query
Response
Query
Response
intDivOrNull
Introduced in: v25.5.0 Same asintDiv but returns NULL when dividing by zero or when dividing a
minimal negative number by minus one.
Syntax
x and y, or NULL.
Examples
Integer division by zero
Query
Response
Query
Response
intDivOrZero
Introduced in: v1.1.0 Same asintDiv but returns zero when dividing by zero or when dividing a
minimal negative number by minus one.
Syntax
Query
Response
Query
Response
isFinite
Introduced in: v1.1.0 Returns1 if the Float32 or Float64 argument not infinite and not a NaN,
otherwise this function returns 0.
Syntax
x— Number to check for finiteness.Float*
1 if x is not infinite and not NaN, otherwise 0.
Examples
Test if a number is finite
Query
Response
isInfinite
Introduced in: v1.1.0 Returns1 if the Float32 or Float64 argument is infinite, otherwise this function returns 0.
Note that 0 is returned for a NaN.
Syntax
x— Number to check for infiniteness.Float*
1 if x is infinite, otherwise 0 (including for NaN).
Examples
Test if a number is infinite
Query
Response
isNaN
Introduced in: v1.1.0 Returns1 if the Float32 and Float64 argument is NaN, otherwise returns 0.
Syntax
x— Argument to evaluate for if it isNaN.Float*
1 if NaN, otherwise 0
Examples
Usage example
Query
Response
lcm
Introduced in: v1.1.0 Returns the least common multiple of two valuesx and y.
An exception is thrown when dividing by zero or when dividing a minimal negative number by minus one.
Syntax
x and y. (U)Int*
Examples
Usage example
Query
Response
max2
Introduced in: v21.11.0 Returns the bigger of two numeric valuesx and y.
Syntax
x— First value(U)Int8/16/32/64orFloat*orDecimaly— Second value(U)Int8/16/32/64orFloat*orDecimal
x and y. Float64
Examples
Usage example
Query
Response
midpoint
Introduced in: v25.11.0 Computes and returns the average value of the provided arguments. Supports numerical and temporal types. Syntaxx1[, x2, ...]— Accepts a single value or multiple values for averaging.
Query
Response
Query
Response
Query
Response
Query
Response
Query
Response
min2
Introduced in: v21.11.0 Returns the smaller of two numeric valuesx and y.
Syntax
x— First value(U)Int8/16/32/64orFloat*orDecimaly— Second value(U)Int8/16/32/64orFloat*orDecimal
x and y. Float64
Examples
Usage example
Query
Response
minus
Introduced in: v1.1.0 Calculates the difference of two valuesa and b. The result is always signed.
Similar to plus, it is possible to subtract an integer from a date or date with time.
Additionally, subtraction between date with time is supported, resulting in the time difference between them.
Syntax
x— Minuend. -y— Subtrahend.
Query
Response
Query
Response
modulo
Introduced in: v1.1.0 Calculates the remainder of the division of two values a by b. The result type is an integer if both inputs are integers. If one of the inputs is a floating-point number, the result type is Float64. The remainder is computed like in C++. Truncated division is used for negative numbers. An exception is thrown when dividing by zero or when dividing a minimal negative number by minus one. Syntaxmod
Arguments
a— The dividend -b— The divisor (modulus)
Query
Response
moduloLegacy
Introduced in: v1.1.0 Calculates the remainder of a division. This is the legacy modulo implementation that uses the C++% operator, which may produce negative results for negative arguments. This function exists for backward compatibility with old table partitioning logic. Use modulo or positiveModulo for standard behavior.
Syntax
(U)Int* or Float*
Examples
Basic usage
Query
Response
moduloOrNull
Introduced in: v25.5.0 Calculates the remainder when dividinga by b. Similar to function modulo except that moduloOrNull will return NULL
if the right argument is 0.
Syntax
modOrNull
Arguments
Returned value
Returns the remainder of the division of x by y, or null when the divisor is zero.
Examples
moduloOrNull by zero
Query
Response
moduloOrZero
Introduced in: v20.3.0 Like modulo but returns zero when the divisor is zero, as opposed to an exception with the modulo function. Syntax0 when the divisor is 0.
Examples
Usage example
Query
Response
multiply
Introduced in: v1.1.0 Calculates the product of two valuesx and y.
Syntax
Query
Response
multiplyDecimal
Introduced in: v22.12.0 Performs multiplication on two decimals. Result value will be of type Decimal256. Result scale can be explicitly specified byresult_scale argument (const Integer in range [0, 76]). If not specified, the result scale is the max scale of given arguments.
These functions work significantly slower than usual
multiply.
In case you don’t really need controlled precision and/or need fast computation, consider using multiplyDecimal256
Examples
Usage example
Query
Response
Query
Response
Query
Response
negate
Introduced in: v1.1.0 Negates the argumentx. The result is always signed.
Syntax
x— The value to negate.
Query
Response
plus
Introduced in: v1.1.0 Calculates the sum of two valuesx and y. Alias: x + y (operator).
It is possible to add an integer and a date or date with time. The former
operation increments the number of days in the date, the latter operation
increments the number of seconds in the date with time.
It is also possible to add a date and a time. Adding a Date and a Time
produces a DateTime. Adding a Date and a Time64, or a Date32 and
a Time or Time64, produces a DateTime64.
Syntax
x— Left hand operand. -y— Right hand operand.
Query
Response
Query
Response
Query
Response
positiveModulo
Introduced in: v22.11.0 Calculates the remainder when dividingx by y. Similar to function
modulo except that positiveModulo always return non-negative number.
Syntax
positive_modulo, pmod
Arguments
x— The dividend.(U)Int*orFloat*orDecimaly— The divisor (modulus).(U)Int*orFloat*orDecimal
x and the nearest integer not greater than
x divisible by y.
Examples
Usage example
Query
Response
positiveModuloOrNull
Introduced in: v25.5.0 Calculates the remainder when dividinga by b. Similar to function positiveModulo except that positiveModuloOrNull will return NULL
if the right argument is 0.
Syntax
positive_modulo_or_null, pmodOrNull
Arguments
x— The dividend.(U)Int*/Float32/64. -x— The divisor (modulus).(U)Int*/Float32/64.
x and the nearest integer not greater than
x divisible by y, null when the divisor is zero.
Examples
positiveModuloOrNull
Query
Response