Mathematical functions and operators#
Mathematical operators#
Operator |
Description |
|---|---|
|
Addition |
|
Subtraction |
|
Multiplication |
|
Division (integer division performs truncation) |
|
Modulus (remainder) |
Mathematical functions#
- e() double#
Returns the constant Euler’s number.
- pi() double#
Returns the constant Pi.
- round(x, d) [same as input]
Returns
xrounded toddecimal places.
- sign(x) [same as input]#
Returns 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 floating point arguments, the function additionally returns:
-0 if the argument is -0,
NaN if the argument is NaN,
1 if the argument is +Infinity,
-1 if the argument is -Infinity.
- width_bucket(x, bound1, bound2, n) bigint#
Returns the bin number of
xin an equi-width histogram with the specifiedbound1andbound2bounds andnnumber of buckets.
- width_bucket(x, bins) bigint
Returns the bin number of
xaccording to the bins specified by the arraybins. Thebinsparameter must be an array of doubles and is assumed to be in sorted ascending order.
Random functions#
- random() double#
Returns a pseudo-random value in the range 0.0 <= x < 1.0.
- random(n) [same as input]
Returns a pseudo-random number between 0 and n (exclusive).
- random(m, n) [same as input]
Returns a pseudo-random number between m and n (exclusive).
Trigonometric functions#
All trigonometric function arguments are expressed in radians.
See unit conversion functions degrees() and radians().
Geometric functions#
- cosine_distance(array(double), array(double)) double#
Calculates the cosine distance between two dense vectors:
SELECT cosine_distance(ARRAY[1.0, 2.0], ARRAY[3.0, 4.0]); -- 0.01613008990009257
- cosine_similarity(array(double), array(double)) double#
Calculates the cosine similarity of two dense vectors:
SELECT cosine_similarity(ARRAY[1.0, 2.0], ARRAY[3.0, 4.0]); -- 0.9838699100999074
- cosine_similarity(x, y) double
Calculates the cosine similarity of two sparse vectors:
SELECT cosine_similarity(MAP(ARRAY['a'], ARRAY[1.0]), MAP(ARRAY['a'], ARRAY[2.0])); -- 1.0
Floating point functions#
- infinity() double#
Returns the constant representing positive infinity.
- nan() double#
Returns the constant representing not-a-number.
Base conversion functions#
Statistical functions#
- t_pdf(x, df) double#
Computes the Student’s t-distribution probability density function for given x and degrees of freedom (df). The x must be a real value and degrees of freedom must be an integer and positive value.
- wilson_interval_lower(successes, trials, z) double#
Returns 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(successes, trials, z) double#
Returns 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(a, b, v) double#
Compute 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(a, b, p) double#
Compute 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(mean, sd, p) double#
Compute the inverse of the Normal cdf with given mean and standard deviation (sd) for the cumulative probability (p): P(N < n). The mean must be a real value and the standard deviation must be a real and positive value. The probability p must lie on the interval (0, 1).