Contact us

The following is a list of all available mathematical functions. They are divided into several sections:


Angle Functions


fn PI
PI() -> float64

Returns the value of the PI constant.

Notes

The precision of the value of PI is no less than 12 decimal places.

Examples

SELECT PI();
  --> 3.14159265358979

fn DEGREES
DEGREES(x: float64) -> float64

Converts the argument from radians to degrees.

Null handling

If the argument is NULL, the function will also return NULL.

Examples

SELECT DEGREES(3.1415);
  --> 179.99469134034814
SELECT DEGREES(0);
  --> 0.0
SELECT DEGREES(-1.5708);
  --> -90.00021045914971

See also


fn RADIANS
RADIANS(x: float64) -> float64

Converts the argument from degrees to radians.

Null handling

If the argument is NULL, the function will also return NULL.

Examples

SELECT RADIANS(180);
  --> 3.14159265358979
SELECT RADIANS(0);
  --> 0.0
SELECT RADIANS(-90);
  --> -1.5707963267949

See also


Rounding Functions


fn CEIL
CEIL(x: float64) -> int64

Returns the nearest integer greater or equal to the argument.

Null handling

If the argument is NULL, the function will also return NULL.

Notes

When the argument is negative, CEIL rounds it towards zero, which, even though mathematically correct, can be suprising to some.

Examples

SELECT CEIL(4.2);
  --> 5
SELECT CEIL(2.7);
  --> 3
SELECT CEIL(-3.1);
  --> -3

See also


fn FLOOR
FLOOR(x: float64) -> int64

Returns the nearest integer less than or equal to the argument.

Null handling

If the argument is NULL, the function will also return NULL.

Notes

When the argument is negative, FLOOR rounds it towards negative infinity, which, even though mathematically correct, can be suprising to some. If rounding towards zero is desired in all cases, use the TRUNC function.

Examples

SELECT FLOOR(4.2);
  --> 4
SELECT FLOOR(2.7);
  --> 2
SELECT FLOOR(-3.1);
  --> -4

See also


fn ROUND
ROUND(x: float64) -> int64
ROUND(x: float64, n: int64) -> float64

Rounds the argument to the nearest integer, or to n decimal places.

Null handling

If any of the arguments is NULL, the function will also return NULL.

Examples

SELECT ROUND(4.2);
  --> 4
SELECT ROUND(2.7);
  --> 3
SELECT ROUND(-3.1);
  --> -3

With specified number of decimal places:

SELECT ROUND(4.2573, 1);
  --> 4.3
SELECT ROUND(2.7418, 1);
  --> 2.7
SELECT ROUND(-3.1201, 1);
  --> -3.1

fn TRUNC
TRUNC(x: float64) -> int64
TRUNC(x: float64, n: int64) -> float64

Truncates the argument to an integer, or to n decimal places.

Null handling

If any of the arguments is NULL, the function will also return NULL.

Notes

TRUNC always rounds the argument towards zero.

Examples

SELECT TRUNC(4.2);
  --> 4
SELECT TRUNC(2.7);
  --> 2
SELECT TRUNC(-3.1);
  --> -3

With specified number of decimal places:

SELECT TRUNC(4.2573, 1);
  --> 4.2
SELECT TRUNC(2.7418, 1);
  --> 2.7
SELECT TRUNC(-3.1201, 1);
  --> -3.1

fn FMOD
FMOD(x: f64, y: f64) -> f64

Returns the floating-point remainder of the division operation x / y.

Null handling

If any of the arguments is NULL, the function will also return NULL.

Error handling

If the value of the divisor y is 0, the function will return an error Division by zero.

Notes

The function behaves the same as C++ std::fmod function.

Examples

SELECT fmod(+5.1, +3.0)
  --> 2.1
SELECT fmod(-5.1, +3.0)
  --> -2.1
SELECT fmod(+5.1, -3.0)
  --> 2.1
SELECT fmod(-5.1, -3.0)
  --> -2.1

Powers, Exponents, Logarithms


fn CBRT
CBRT(x: float64) -> float64

Returns the cubic root of the argument.

Arguments

The function accepts negative numbers as valid arguments.

Null handling

If the argument is NULL, the function will also return NULL.

Notes

The CBRT function is logically equivalent to POWER(x, 1/3), but unlike POWER, CBRT works correctly for negative arguments (while the POWER function doesn't allow raising negative values to a decimal power).

Examples

SELECT CBRT(27);
  --> 3.0
SELECT CBRT(-8);
  --> -2.0
SELECT CBRT(15.625);
  --> 2.5

See also


fn EXP
EXP(x: float64) -> float64

Returns the value of the exponential function, e^x, for the given argument.

Null handling

If the argument is NULL, the function will also return NULL.

Error handling

If the value of e^x exceeds the maximum value representable by a 64-bit floating-point number (~1.8e+308), the function will return an error: Result out of representable range.

Examples

SELECT EXP(1);
  --> 2.71828182845905
SELECT EXP(-0.5);
  --> 0.60653065971263
SELECT EXP(0.0001);
  --> 1.00010000500017

See also


fn LN
LN(x: float64) -> float64

Returns the value of the natural logarithm of the argument.

Null handling

If the argument is NULL, the function will also return NULL.

Error handling

As logarithms are defined only for positive numbers, for a non-positive argument the function will return an error: Argument out of domain.

Examples

SELECT LN(2.718);
  --> 0.99989631572895
SELECT LN(0.135);
  --> -2.00248050054371
SELECT LN(10);
  --> 2.30258509299405

See also


fn LOG10
LOG10(x: float64) -> float64

Returns the value of the base-10 logarithm of the argument.

Null handling

If the argument is NULL, the function will also return NULL.

Error handling

As logarithms are defined only for positive numbers, for a non-positive argument the function will return an error: Argument out of domain.

Examples

SELECT LOG10(10);
  --> 1.0
SELECT LOG10(0.01);
  --> -2.0
SELECT LOG10(2);
  --> 0.30102999566398

See also


fn LOG2
LOG2(x: float64) -> float64

Returns the value of the base-2 logarithm of the argument.

Null handling

If the argument is NULL, the function will also return NULL.

Error handling

As logarithms are defined only for positive numbers, for a non-positive argument the function will return an error: Argument out of domain.

Examples

SELECT LOG2(2);
  --> 1.0
SELECT LOG2(0.125);
  --> -3.0
SELECT LOG2(10);
  --> 3.32192809488736

See also


fn POWER
POWER(x: float64, y: float64) -> float64

Returns the value of the first argument raised to the power of the second argument, i.e. x^y.

Null handling

If any of the arguments is NULL, the function will also return NULL.

Error handling

If the first argument is negative, the second argument must be an integer, otherwise the function will return an error: Cannot raise a negative number to decimal power.

If the first argument is 0 and the second argument is negative, the function will return an error: Division by zero.

If the value of x^y exceeds the maximum value representable by a 64-bit floating-point number (~1.8e+308), the function will return an error: Result out of representable range.

Examples

SELECT POWER(3, 2);
  --> 9.0
SELECT POWER(27, 0.33333);
  --> 2.99996704181238
SELECT POWER(6.25, -0.5);
  --> 0.4

See also


fn SQRT
SQRT(x: float64) -> float64

Returns the square root of the argument.

Null handling

If the argument is NULL, the function will also return NULL.

Error handling

As the square root of a negative number is not real, for negative arguments the function returns an error: Argument out of domain.

Examples

SELECT SQRT(9);
  --> 3.0
SELECT SQRT(0.25);
  --> 0.5
SELECT SQRT(256);
  --> 16.0

See also


Trigonometric Functions


fn ACOS
ACOS(x: float64) -> float64

Returns the arc cosine of the argument, i.e. the number for which the cosine is equal to x.

Null handling

If the argument is NULL, the function will also return NULL.

Error handling

As arc cosine is defined only for arguments from the range [-1, 1], for values outside of that range the function will return an error: Argument out of domain.

Notes

The result is always from the range [0, pi].

ACOS is the inverse function of COS, so it holds that ACOS(COS(x)) = x, but only for arguments from the range [0, pi] and up to rounding errors.

Examples

SELECT ACOS(0.5);
  --> 1.0471975511966
SELECT ACOS(-0.707);
  --> 2.3560434901900
SELECT ACOS(0);
  --> 1.5707963267949

See also


fn ASIN
ASIN(x: float64) -> float64

Returns the arc sine of the argument, i.e. the number for which the sine is equal to x.

Null handling

If the argument is NULL, the function will also return NULL.

Error handling

As arc sine is defined only for arguments from the range [-1, 1], for values outside of that range the function will return an error: Argument out of domain.

Notes

The result is always from the range [-pi/2, pi/2].

ASIN is the inverse function of SIN, so it holds that ASIN(SIN(x)) = x, but only arguments from the range [-pi/2, pi/2] and up to rounding errors.

Examples

SELECT ASIN(0.5);
  --> 0.5235987755983
SELECT ASIN(-0.707);
  --> -0.7852471633951
SELECT ASIN(0);
  --> 0.0

See also


fn ATAN
ATAN(x: float64) -> float64

Returns the arc tangent of the argument, i.e. the number for which the tangent is equal to x.

Null handling

If the argument is NULL, the function will also return NULL.

Notes

The result is always from the range [-pi/2, pi/2].

ATAN is the inverse function of TAN, so it holds that ATAN(TAN(x)) = x, but only for arguments from the range [-pi/2, pi/2] and up to rounding errors.

Examples

SELECT ATAN(SQRT(3));
  --> 1.0471975511966
SELECT ATAN(-1);
  --> -0.7853981633974
SELECT ATAN(0);
  --> 0.0

See also


fn ATAN2
ATAN2(y: float64, x: float64) -> float64

Return the arc tangent of the y/x, using the signs of the arguments to determine the correct quadrant.

Null handling

If any of the arguments is NULL, the function will also return NULL.

Notes

The result is always from the range [-pi, pi].

For the special case x=0, y=0, the function returns 0.

Examples

SELECT ATAN2(SQRT(3)/2, 0.5);
  --> 1.0471975511966
SELECT ATAN2(2, 2);
  --> 0.7853981633974
SELECT ATAN2(1, 0);
  --> 1.5707963267949

See also


fn COS
COS(x: float64) -> float64

Returns the cosine of the argument.

Null handling

If the argument is NULL, the function will also return NULL.

Examples

SELECT COS(PI()/3);
  --> 0.5
SELECT COS(3*PI()/4);
  --> -0.70710678118655
SELECT COS(PI()/2);
  --> 6.12323399573677e-17

See also


fn SIN
SIN(x: float64) -> float64

Returns the sine of the argument.

Null handling

If the argument is NULL, the function will also return NULL.

Examples

SELECT SIN(PI()/6);
  --> 0.5
SELECT SIN(-PI()/4);
  --> -0.70710678118655
SELECT SIN(0);
  --> 0.0

See also


fn TAN
TAN(x: float64) -> float64

Returns the tangent of the argument.

Null handling

If the argument is NULL, the function will also return NULL.

Examples

SELECT TAN(PI()/3);
  --> 1.73205080756888
SELECT TAN(-PI()/4);
  --> -1.0
SELECT TAN(0);
  --> 0.0

See also


Hyperbolic Functions


fn ACOSH
ACOSH(x: float64) -> float64

Returns the area hyperbolic cosine of the argument, i.e. the number for which the hyperbolic cosine is equal to x.

Null handling

If the argument is NULL, the function will also return NULL.

Error handling

As area hyperbolic cosine is defined only for x >= 1, for arguments smaller than 1 the function will return an error: Argument out of domain.

Notes

The result is always non-negative.

ACOSH is the inverse function of COSH, so it holds that ACOSH(COSH(x)) = x, but only for x >= 1 and up to rounding errors.

Examples

SELECT ACOSH(1);
  --> 0.0
SELECT ACOSH(2);
  --> 1.3169578969248
SELECT ACOSH(5);
  --> 2.2924316695612

See also


fn ASINH
ASINH(x: float64) -> float64

Returns the area hyperbolic sine of the argument, i.e. the number for which the hyperbolic sine is equal to x.

Null handling

If the argument is NULL, the function will also return NULL.

Notes

ASINH is the inverse function of SINH, so it holds that ASINH(SINH(x)) = x for all values of x.

Examples

SELECT ASINH(1);
  --> 0.8813735870195
SELECT ASINH(0);
  --> 0.0
SELECT ASINH(-1);
  --> -0.8813735870195

See also


fn ATANH
ATANH(x: float64) -> float64

Returns the area hyperbolic tangent of the argument, i.e. the number for which the hyperbolic tangent is equal to x.

Null handling

If the argument is NULL, the function will also return NULL.

Error handling

As area hyperbolic tangent is only defined for arguments from the open range <-1, 1>, for arguments outside of this range the function will return an error: Argument out of domain.

Notes

ATANH is the inverse function of TANH, so it holds that ATANH(TANH(x)) = x (up to rounding errors) for all values of x from the domain.

Examples

SELECT ATANH(0.5);
  --> 0.5493061443340
SELECT ATANH(0);
  --> 0.0
SELECT ATANH(-0.5);
  --> -0.5493061443340

See also


fn COSH
COSH(x: float64) -> float64

Returns the hyperbolic cosine of the argument.

Null handling

If the argument is NULL, the function will also return NULL.

Error handling

If the value of COSH(x) exceeds the maximum value representable by a 64-bit floating-point number (~1.8e+308), the function will return an error: Result out of representable range.

Examples

SELECT COSH(1);
  --> 1.54308063481524
SELECT COSH(0);
  --> 1.0
SELECT COSH(-1);
  --> 1.54308063481524

See also


fn SINH
SINH(x: float64) -> float64

Returns the hyperbolic sine of the argument.

Null handling

If the argument is NULL, the function will also return NULL.

Error handling

If the value of SINH(x) exceeds the maximum value representable by a 64-bit floating-point number (~1.8e+308), the function will return an error: Result out of representable range.

Examples

SELECT SINH(1);
  --> 1.1752011936438
SELECT SINH(0);
  --> 0.0
SELECT SINH(-1);
  --> -1.1752011936438

See also


fn TANH
TANH(x: float64) -> float64

Returns the hyperbolic tangent of the argument.

Null handling

If the argument is NULL, the function will also return NULL.

Examples

SELECT TANH(1);
  --> 0.76159415595576
SELECT TANH(0);
  --> 0.0
SELECT TANH(-1);
  --> -0.76159415595576

See also


Random functions


fn RANDINT
RANDINT(max: int64) -> int64

Returns a random integer between 0 (inclusive) and the given argument (exclusive).

Null handling

If the argument is NULL, the function will also return NULL.

Examples

SELECT RANDINT(10);
  --> 7

See also


fn RANDOM
RANDOM() -> float64

Returns a random number between 0 and 1.

Examples

SELECT RANDOM();
  --> 0.23679588880354

See also