Mathematical operators
| Operator | Description |
|---|---|
+ | Addition |
- | Subtraction |
* | Multiplication |
/ | Division (integer division performs truncation) |
% | Modulus (remainder) |
Mathematical functions
abs()
abs(x) → same as inputReturns the absolute value of
x.
cbrt()
cbrt(x) → doubleReturns the cube root of
x.
ceil()
ceil(x) → same as inputThis is an alias for
ceiling.
ceiling()
ceiling(x) → same as inputReturns
x rounded up to the nearest integer.
degrees()
degrees(x) → doubleConverts angle
x in radians to degrees.
e()
e() → doubleReturns the constant Euler’s number.
exp()
exp(x) → doubleReturns Euler’s number raised to the power of
x.
floor()
floor(x) → same as inputReturns
x rounded down to the nearest integer.
ln()
ln(x) → doubleReturns the natural logarithm of
x.
log()
log(b, x) → doubleReturns the base
b logarithm of x.
log2()
log2(x) → doubleReturns the base 2 logarithm of
x.
log10()
log10(x) → doubleReturns the base 10 logarithm of
x.
mod()
mod(n, m) → same as inputReturns the modulus (remainder) of
n divided by m.
pi()
pi() → doubleReturns the constant Pi.
pow()
pow(x, p) → doubleThis is an alias for
power.
power()
power(x, p) → doubleReturns
x raised to the power of p.
radians()
radians(x) → doubleConverts angle
x in degrees to radians.
round()
round(x) → same as inputReturns
x rounded to the nearest integer.
round()
round(x, d) → same as inputReturns
x rounded to d decimal places.
sign()
sign(x) → same as inputReturns the signum function of
x, that is:
- 0 if the argument is 0,
- 1 if the argument is greater than 0,
- -1 if the argument is less than 0. For double arguments, the function additionally returns:
- NaN if the argument is NaN,
- 1 if the argument is +Infinity,
- -1 if the argument is -Infinity.
sqrt()
sqrt(x) → doubleReturns the square root of
x.
truncate()
truncate(x) → doubleReturns
x rounded to integer by dropping digits after decimal point.
width_bucket()
width_bucket(x, bound1, bound2, n) → bigintReturns the bin number of
x in an equi-width histogram with the specified bound1 and bound2 bounds and n number of buckets.
width_bucket()
width_bucket(x, bins) → bigintReturns the bin number of
x according to the bins specified by the array bins. The bins parameter must be an array of doubles and is assumed to be in sorted ascending order.
Random functions
rand()
rand() → doubleThis is an alias for
random().
random()
random() → doubleReturns a pseudo-random value in the range 0.0 <= x < 1.0.
random()
random(n) → same as inputReturns a pseudo-random number between 0 and n (exclusive).
random()
random(m, n) → same as inputReturns a pseudo-random number between m and n (exclusive).
Trigonometric functions
All trigonometric function arguments are expressed in radians. See unit conversion functionsdegrees and radians.
acos()
acos(x) → doubleReturns the arc cosine of
x.
asin()
asin(x) → doubleReturns the arc sine of
x.
atan()
atan(x) → doubleReturns the arc tangent of
x.
atan2()
atan2(y, x) → doubleReturns the arc tangent of
y / x.
cos()
cos(x) → doubleReturns the cosine of
x.
cosh()
cosh(x) → doubleReturns the hyperbolic cosine of
x.
sin()
sin(x) → doubleReturns the sine of
x.
tan()
tan(x) → doubleReturns the tangent of
x.
sinh()
sinh(x) → double
Returns the hyperbolic sine of x.
tanh()
tanh(x) → doubleReturns the hyperbolic tangent of
x.
Floating point functions
infinity()
infinity() → doubleReturns the constant representing positive infinity.
is_finite()
is_finite(x) → booleanDetermine if
x is finite.
is_infinite()
is_infinite(x) → booleanDetermine if
x is infinite.
is_nan()
is_nan(x) → booleanDetermine if
x is not-a-number.
nan()
nan() → doubleReturns the constant representing not-a-number.
Base conversion functions
from_base()
from_base(string, radix) → bigintReturns the value of
string interpreted as a base-radix number.
to_base()
to_base(x, radix) → varcharReturns the base-
radix representation of x.
Statistical functions
cosine_similarity()
cosine_similarity(x, y) → doubleReturns the cosine similarity between the sparse vectors
x and y:
SELECT cosine_similarity(MAP(ARRAY[‘a’], ARRAY[1.0]), MAP(ARRAY[‘a’], ARRAY[2.0])); — 1.0
wilson_interval_lower()
wilson_interval_lower(successes, trials, z) → doubleReturns the lower bound of the Wilson score interval of a Bernoulli trial process at a confidence specified by the z-score
z.
wilson_interval_upper()
wilson_interval_upper(successes, trials, z) → doubleReturns the upper bound of the Wilson score interval of a Bernoulli trial process at a confidence specified by the z-score
z.
Cumulative distribution functions
beta_cdf()
beta_cdf(a, b, v) → doubleCompute the Beta cdf with given a, b parameters: P(N < v; a, b). The a, b parameters must be positive real numbers and value v must be a real value. The value v must lie on the interval [0, 1].
inverse_beta_cdf()
inverse_beta_cdf(a, b, p) → doubleCompute the inverse of the Beta cdf with given a, b parameters for the cumulative probability (p): P(N < n). The a, b parameters must be positive real values. The probability p must lie on the interval [0, 1].
inverse_normal_cdf()
inverse_normal_cdf(mean, sd, p) → doubleCompute the inverse of the Normal cdf with given mean and standard
normal_cdf()
normal_cdf(mean, sd, v) → doubleCompute the Normal cdf with given mean and standard deviation (sd): P(N < v; mean, sd). The mean and value v must be real values and the standard deviation must be a real and positive value.

