2018-09-05 18:19:49 -04:00
[role="xpack"]
[testenv="basic"]
[[sql-functions-math]]
=== Math Functions
All math and trigonometric functions require their input (where applicable)
to be numeric.
==== Generic
2018-09-24 19:42:18 -04:00
[[sql-functions-math-abs]]
===== `ABS`
2018-09-05 18:19:49 -04:00
2018-09-24 19:42:18 -04:00
.Synopsis:
[source, sql]
--------------------------------------------------
ABS(numeric_exp<1>)
--------------------------------------------------
*Input*:
<1> numeric expression
*Output*: numeric
.Description:
Returns the https://en.wikipedia.org/wiki/Absolute_value[absolute value] of `numeric_exp`. The return type is the same as the input type.
["source","sql",subs="attributes,macros"]
--------------------------------------------------
include-tagged::{sql-specs}/docs.csv-spec[abs]
--------------------------------------------------
[[sql-functions-math-cbrt]]
===== `CBRT`
.Synopsis:
[source, sql]
--------------------------------------------------
CBRT(numeric_exp<1>)
--------------------------------------------------
*Input*:
<1> numeric expression
*Output*: double numeric value
.Description:
Returns the https://en.wikipedia.org/wiki/Cube_root[cube root] of `numeric_exp`.
["source","sql",subs="attributes,macros"]
--------------------------------------------------
include-tagged::{sql-specs}/docs.csv-spec[mathInlineCbrtWithNegativeValue]
--------------------------------------------------
[[sql-functions-math-ceil]]
===== `CEIL/CEILING`
.Synopsis:
[source, sql]
--------------------------------------------------
CEIL(numeric_exp<1>)
--------------------------------------------------
*Input*:
<1> numeric expression
*Output*: integer or long numeric value
.Description:
Returns the smallest integer greater than or equal to `numeric_exp`.
["source","sql",subs="attributes,macros"]
--------------------------------------------------
include-tagged::{sql-specs}/docs.csv-spec[mathInlineCeiling]
--------------------------------------------------
[[sql-functions-math-e]]
===== `E`
.Synopsis:
[source, sql]
--------------------------------------------------
E()
--------------------------------------------------
*Input*: _none_
*Output*: `2.718281828459045`
.Description:
Returns https://en.wikipedia.org/wiki/E_%28mathematical_constant%29[Euler's number].
["source","sql",subs="attributes,macros"]
--------------------------------------------------
include-tagged::{sql-specs}/docs.csv-spec[mathEulersNumber]
--------------------------------------------------
[[sql-functions-math-exp]]
===== `EXP`
.Synopsis:
[source, sql]
--------------------------------------------------
EXP(numeric_exp<1>)
--------------------------------------------------
*Input*:
<1> float numeric expression
*Output*: double numeric value
.Description:
Returns https://en.wikipedia.org/wiki/Exponential_function[Euler's number at the power] of `numeric_exp` e^numeric_exp^.
["source","sql",subs="attributes,macros"]
--------------------------------------------------
include-tagged::{sql-specs}/docs.csv-spec[mathExpInline]
--------------------------------------------------
[[sql-functions-math-expm1]]
===== `EXPM1`
.Synopsis:
[source, sql]
--------------------------------------------------
EXPM1(numeric_exp<1>)
--------------------------------------------------
*Input*:
2018-09-05 18:19:49 -04:00
2018-09-24 19:42:18 -04:00
<1> float numeric expression
*Output*: double numeric value
.Description:
Returns https://docs.oracle.com/javase/8/docs/api/java/lang/Math.html#expm1-double-[Euler's number at the power] of `numeric_exp` minus 1 (e^numeric_exp^ - 1).
["source","sql",subs="attributes,macros"]
2018-09-05 18:19:49 -04:00
--------------------------------------------------
2018-09-24 19:42:18 -04:00
include-tagged::{sql-specs}/docs.csv-spec[mathExpm1Inline]
2018-09-05 18:19:49 -04:00
--------------------------------------------------
2018-09-24 19:42:18 -04:00
[[sql-functions-math-floor]]
===== `FLOOR`
2018-09-05 18:19:49 -04:00
2018-09-24 19:42:18 -04:00
.Synopsis:
[source, sql]
--------------------------------------------------
FLOOR(numeric_exp<1>)
--------------------------------------------------
2018-09-05 18:19:49 -04:00
2018-09-24 19:42:18 -04:00
*Input*:
2018-09-05 18:19:49 -04:00
2018-09-24 19:42:18 -04:00
<1> numeric expression
2018-09-05 18:19:49 -04:00
2018-09-24 19:42:18 -04:00
*Output*: integer or long numeric value
2018-09-05 18:19:49 -04:00
2018-09-24 19:42:18 -04:00
.Description:
2018-09-05 18:19:49 -04:00
2018-09-24 19:42:18 -04:00
Returns the largest integer less than or equal to `numeric_exp`.
2018-09-05 18:19:49 -04:00
2018-09-24 19:42:18 -04:00
["source","sql",subs="attributes,macros"]
--------------------------------------------------
include-tagged::{sql-specs}/docs.csv-spec[mathInlineFloor]
--------------------------------------------------
2018-09-05 18:19:49 -04:00
2018-09-24 19:42:18 -04:00
[[sql-functions-math-log]]
===== `LOG`
2018-09-05 18:19:49 -04:00
2018-09-24 19:42:18 -04:00
.Synopsis:
[source, sql]
--------------------------------------------------
LOG(numeric_exp<1>)
--------------------------------------------------
2018-09-05 18:19:49 -04:00
2018-09-24 19:42:18 -04:00
*Input*:
2018-09-05 18:19:49 -04:00
2018-09-24 19:42:18 -04:00
<1> numeric expression
*Output*: double numeric value
.Description:
Returns the https://en.wikipedia.org/wiki/Natural_logarithm[natural logarithm] of `numeric_exp`.
["source","sql",subs="attributes,macros"]
2018-09-20 08:29:53 -04:00
--------------------------------------------------
2018-09-24 19:42:18 -04:00
include-tagged::{sql-specs}/docs.csv-spec[mathInlineLog]
2018-09-20 08:29:53 -04:00
--------------------------------------------------
2018-09-05 18:19:49 -04:00
2018-09-24 19:42:18 -04:00
[[sql-functions-math-log10]]
===== `LOG10`
2018-09-05 18:19:49 -04:00
2018-09-24 19:42:18 -04:00
.Synopsis:
[source, sql]
2018-09-20 08:29:53 -04:00
--------------------------------------------------
2018-09-24 19:42:18 -04:00
LOG10(numeric_exp<1>)
2018-09-20 08:29:53 -04:00
--------------------------------------------------
2018-09-05 18:19:49 -04:00
2018-09-24 19:42:18 -04:00
*Input*:
<1> numeric expression
*Output*: double numeric value
2018-09-05 18:19:49 -04:00
2018-09-24 19:42:18 -04:00
.Description:
2018-09-05 18:19:49 -04:00
2018-09-24 19:42:18 -04:00
Returns the https://en.wikipedia.org/wiki/Common_logarithm[base 10 logarithm] of `numeric_exp`.
2018-09-05 18:19:49 -04:00
2018-09-24 19:42:18 -04:00
["source","sql",subs="attributes,macros"]
2018-09-05 18:19:49 -04:00
--------------------------------------------------
2018-09-24 19:42:18 -04:00
include-tagged::{sql-specs}/docs.csv-spec[mathInlineLog10]
2018-09-05 18:19:49 -04:00
--------------------------------------------------
2018-09-24 19:42:18 -04:00
[[sql-functions-math-pi]]
===== `PI`
2018-09-05 18:19:49 -04:00
2018-09-24 19:42:18 -04:00
.Synopsis:
[source, sql]
2018-09-05 18:19:49 -04:00
--------------------------------------------------
2018-09-24 19:42:18 -04:00
PI()
2018-09-05 18:19:49 -04:00
--------------------------------------------------
2018-09-24 19:42:18 -04:00
*Input*: _none_
*Output*: `3.141592653589793`
.Description:
Returns https://en.wikipedia.org/wiki/Pi[PI number].
["source","sql",subs="attributes,macros"]
--------------------------------------------------
include-tagged::{sql-specs}/docs.csv-spec[mathPINumber]
--------------------------------------------------
[[sql-functions-math-power]]
===== `POWER`
.Synopsis:
[source, sql]
--------------------------------------------------
POWER(numeric_exp<1>, integer_exp<2>)
--------------------------------------------------
*Input*:
<1> numeric expression
<2> integer expression
*Output*: double numeric value
.Description:
Returns the value of `numeric_exp` to the power of `integer_exp`.
["source","sql",subs="attributes,macros"]
--------------------------------------------------
include-tagged::{sql-specs}/docs.csv-spec[mathInlinePowerPositive]
--------------------------------------------------
["source","sql",subs="attributes,macros"]
--------------------------------------------------
include-tagged::{sql-specs}/docs.csv-spec[mathInlinePowerNegative]
--------------------------------------------------
2018-10-08 17:20:18 -04:00
[[sql-functions-math-random]]
2018-12-21 16:25:54 -05:00
===== `RANDOM/RAND`
2018-10-08 17:20:18 -04:00
.Synopsis:
[source, sql]
--------------------------------------------------
RANDOM(seed<1>)
--------------------------------------------------
*Input*:
<1> numeric expression
*Output*: double numeric value
.Description:
Returns a random double using the given seed.
["source","sql",subs="attributes,macros"]
--------------------------------------------------
include-tagged::{sql-specs}/docs.csv-spec[mathRandom]
--------------------------------------------------
2018-09-24 19:42:18 -04:00
[[sql-functions-math-round]]
===== `ROUND`
2018-09-20 08:29:53 -04:00
.Synopsis:
[source, sql]
----
ROUND(numeric_exp<1>[, integer_exp<2>])
----
*Input*:
2018-09-24 19:42:18 -04:00
<1> numeric expression
<2> integer expression; optional
2018-09-20 08:29:53 -04:00
*Output*: numeric
.Description:
Returns `numeric_exp` rounded to `integer_exp` places right of the decimal point. If `integer_exp` is negative,
`numeric_exp` is rounded to |`integer_exp`| places to the left of the decimal point. If `integer_exp` is omitted,
the function will perform as if `integer_exp` would be 0. The returned numeric data type is the same as the data type
of `numeric_exp`.
2018-09-24 19:42:18 -04:00
["source","sql",subs="attributes,macros"]
2018-09-20 08:29:53 -04:00
--------------------------------------------------
include-tagged::{sql-specs}/docs.csv-spec[mathRoundWithPositiveParameter]
--------------------------------------------------
2018-09-24 19:42:18 -04:00
["source","sql",subs="attributes,macros"]
2018-09-20 08:29:53 -04:00
--------------------------------------------------
include-tagged::{sql-specs}/docs.csv-spec[mathRoundWithNegativeParameter]
--------------------------------------------------
2018-09-24 19:42:18 -04:00
[[sql-functions-math-sign]]
2018-12-21 16:25:54 -05:00
===== `SIGN/SIGNUM`
2018-09-05 18:19:49 -04:00
2018-09-24 19:42:18 -04:00
.Synopsis:
[source, sql]
--------------------------------------------------
SIGN(numeric_exp<1>)
--------------------------------------------------
*Input*:
<1> numeric expression
*Output*: [-1, 0, 1]
.Description:
Returns an indicator of the sign of `numeric_exp`. If `numeric_exp` is less than zero, – 1 is returned. If `numeric_exp` equals zero, 0 is returned. If `numeric_exp` is greater than zero, 1 is returned.
["source","sql",subs="attributes,macros"]
2018-09-05 18:19:49 -04:00
--------------------------------------------------
2018-09-24 19:42:18 -04:00
include-tagged::{sql-specs}/docs.csv-spec[mathInlineSign]
2018-09-05 18:19:49 -04:00
--------------------------------------------------
2018-09-24 19:42:18 -04:00
[[sql-functions-math-sqrt]]
===== `SQRT`
.Synopsis:
[source, sql]
--------------------------------------------------
SQRT(numeric_exp<1>)
--------------------------------------------------
*Input*:
<1> numeric expression
*Output*: double numeric value
.Description:
Returns https://en.wikipedia.org/wiki/Square_root[square root] of `numeric_exp`.
["source","sql",subs="attributes,macros"]
--------------------------------------------------
include-tagged::{sql-specs}/docs.csv-spec[mathInlineSqrt]
--------------------------------------------------
[[sql-functions-math-truncate]]
===== `TRUNCATE`
2018-09-20 08:29:53 -04:00
.Synopsis:
[source, sql]
----
TRUNCATE(numeric_exp<1>[, integer_exp<2>])
----
*Input*:
2018-09-24 19:42:18 -04:00
<1> numeric expression
<2> integer expression; optional
2018-09-20 08:29:53 -04:00
*Output*: numeric
.Description:
Returns `numeric_exp` truncated to `integer_exp` places right of the decimal point. If `integer_exp` is negative,
`numeric_exp` is truncated to |`integer_exp`| places to the left of the decimal point. If `integer_exp` is omitted,
the function will perform as if `integer_exp` would be 0. The returned numeric data type is the same as the data type
of `numeric_exp`.
2018-09-05 18:19:49 -04:00
2018-09-24 19:42:18 -04:00
["source","sql",subs="attributes,macros"]
2018-09-05 18:19:49 -04:00
--------------------------------------------------
2018-09-20 08:29:53 -04:00
include-tagged::{sql-specs}/docs.csv-spec[mathTruncateWithPositiveParameter]
2018-09-05 18:19:49 -04:00
--------------------------------------------------
2018-09-24 19:42:18 -04:00
["source","sql",subs="attributes,macros"]
2018-09-05 18:19:49 -04:00
--------------------------------------------------
2018-09-20 08:29:53 -04:00
include-tagged::{sql-specs}/docs.csv-spec[mathTruncateWithNegativeParameter]
2018-09-05 18:19:49 -04:00
--------------------------------------------------
==== Trigonometric
2018-09-24 19:42:18 -04:00
[[sql-functions-math-acos]]
===== `ACOS`
2018-09-05 18:19:49 -04:00
2018-09-24 19:42:18 -04:00
.Synopsis:
[source, sql]
2018-09-05 18:19:49 -04:00
--------------------------------------------------
2018-09-24 19:42:18 -04:00
ACOS(numeric_exp<1>)
2018-09-05 18:19:49 -04:00
--------------------------------------------------
2018-09-24 19:42:18 -04:00
*Input*:
<1> numeric expression
*Output*: double numeric value
.Description:
2018-09-05 18:19:49 -04:00
2018-09-24 19:42:18 -04:00
Returns the https://en.wikipedia.org/wiki/Inverse_trigonometric_functions[arccosine] of `numeric_exp` as an angle, expressed in radians.
["source","sql",subs="attributes,macros"]
2018-09-05 18:19:49 -04:00
--------------------------------------------------
2018-09-24 19:42:18 -04:00
include-tagged::{sql-specs}/docs.csv-spec[mathInlineAcos]
2018-09-05 18:19:49 -04:00
--------------------------------------------------
2018-09-24 19:42:18 -04:00
[[sql-functions-math-asin]]
===== `ASIN`
2018-09-05 18:19:49 -04:00
2018-09-24 19:42:18 -04:00
.Synopsis:
[source, sql]
2018-09-05 18:19:49 -04:00
--------------------------------------------------
2018-09-24 19:42:18 -04:00
ASIN(numeric_exp<1>)
2018-09-05 18:19:49 -04:00
--------------------------------------------------
2018-09-24 19:42:18 -04:00
*Input*:
<1> numeric expression
2018-09-05 18:19:49 -04:00
2018-09-24 19:42:18 -04:00
*Output*: double numeric value
.Description:
Returns the https://en.wikipedia.org/wiki/Inverse_trigonometric_functions[arcsine] of `numeric_exp` as an angle, expressed in radians.
["source","sql",subs="attributes,macros"]
2018-09-05 18:19:49 -04:00
--------------------------------------------------
2018-09-24 19:42:18 -04:00
include-tagged::{sql-specs}/docs.csv-spec[mathInlineAsin]
2018-09-05 18:19:49 -04:00
--------------------------------------------------
2018-09-24 19:42:18 -04:00
[[sql-functions-math-atan]]
===== `ATAN`
2018-09-05 18:19:49 -04:00
2018-09-24 19:42:18 -04:00
.Synopsis:
[source, sql]
2018-09-05 18:19:49 -04:00
--------------------------------------------------
2018-09-24 19:42:18 -04:00
ATAN(numeric_exp<1>)
2018-09-05 18:19:49 -04:00
--------------------------------------------------
2018-09-24 19:42:18 -04:00
*Input*:
<1> numeric expression
*Output*: double numeric value
.Description:
Returns the https://en.wikipedia.org/wiki/Inverse_trigonometric_functions[arctangent] of `numeric_exp` as an angle, expressed in radians.
2018-09-05 18:19:49 -04:00
2018-09-24 19:42:18 -04:00
["source","sql",subs="attributes,macros"]
2018-09-05 18:19:49 -04:00
--------------------------------------------------
2018-09-24 19:42:18 -04:00
include-tagged::{sql-specs}/docs.csv-spec[mathInlineAtan]
2018-09-05 18:19:49 -04:00
--------------------------------------------------
2018-09-24 19:42:18 -04:00
[[sql-functions-math-atan2]]
===== `ATAN2`
2018-09-05 18:19:49 -04:00
2018-09-24 19:42:18 -04:00
.Synopsis:
[source, sql]
2018-09-05 18:19:49 -04:00
--------------------------------------------------
2018-09-24 19:42:18 -04:00
ATAN2(ordinate<1>, abscisa<2>)
2018-09-05 18:19:49 -04:00
--------------------------------------------------
2018-09-24 19:42:18 -04:00
*Input*:
<1> numeric expression
<2> numeric expression
*Output*: double numeric value
.Description:
Returns the https://en.wikipedia.org/wiki/Atan2[arctangent of the `ordinate` and `abscisa` coordinates] specified as an angle, expressed in radians.
2018-09-05 18:19:49 -04:00
2018-09-24 19:42:18 -04:00
["source","sql",subs="attributes,macros"]
2018-09-05 18:19:49 -04:00
--------------------------------------------------
2018-09-24 19:42:18 -04:00
include-tagged::{sql-specs}/docs.csv-spec[mathInlineAtan2]
2018-09-05 18:19:49 -04:00
--------------------------------------------------
2018-09-24 19:42:18 -04:00
[[sql-functions-math-cos]]
===== `COS`
2018-09-05 18:19:49 -04:00
2018-09-24 19:42:18 -04:00
.Synopsis:
[source, sql]
--------------------------------------------------
COS(numeric_exp<1>)
--------------------------------------------------
*Input*:
<1> numeric expression
*Output*: double numeric value
.Description:
Returns the https://en.wikipedia.org/wiki/Trigonometric_functions#cosine[cosine] of `numeric_exp`, where `numeric_exp` is an angle expressed in radians.
["source","sql",subs="attributes,macros"]
--------------------------------------------------
include-tagged::{sql-specs}/docs.csv-spec[mathInlineCosine]
--------------------------------------------------
[[sql-functions-math-cosh]]
===== `COSH`
.Synopsis:
[source, sql]
--------------------------------------------------
COSH(numeric_exp<1>)
--------------------------------------------------
*Input*:
<1> numeric expression
*Output*: double numeric value
.Description:
Returns the https://en.wikipedia.org/wiki/Hyperbolic_function[hyperbolic cosine] of `numeric_exp`.
["source","sql",subs="attributes,macros"]
--------------------------------------------------
include-tagged::{sql-specs}/docs.csv-spec[mathInlineCosh]
--------------------------------------------------
[[sql-functions-math-cot]]
===== `COT`
.Synopsis:
[source, sql]
2018-09-05 18:19:49 -04:00
--------------------------------------------------
2018-09-24 19:42:18 -04:00
COT(numeric_exp<1>)
2018-09-05 18:19:49 -04:00
--------------------------------------------------
2018-09-24 19:42:18 -04:00
*Input*:
<1> numeric expression
*Output*: double numeric value
.Description:
Returns the https://en.wikipedia.org/wiki/Trigonometric_functions#Cosecant,_secant,_and_cotangent[cotangent] of `numeric_exp`, where `numeric_exp` is an angle expressed in radians.
["source","sql",subs="attributes,macros"]
--------------------------------------------------
include-tagged::{sql-specs}/docs.csv-spec[mathInlineCotangent]
--------------------------------------------------
[[sql-functions-math-degrees]]
===== `DEGREES`
.Synopsis:
[source, sql]
--------------------------------------------------
DEGREES(numeric_exp<1>)
--------------------------------------------------
*Input*:
<1> numeric expression
*Output*: double numeric value
.Description:
Convert from https://en.wikipedia.org/wiki/Radian[radians]
to https://en.wikipedia.org/wiki/Degree_(angle)[degrees].
["source","sql",subs="attributes,macros"]
--------------------------------------------------
include-tagged::{sql-specs}/docs.csv-spec[mathInlineDegrees]
--------------------------------------------------
[[sql-functions-math-radians]]
===== `RADIANS`
.Synopsis:
[source, sql]
--------------------------------------------------
RADIANS(numeric_exp<1>)
--------------------------------------------------
*Input*:
<1> numeric expression
*Output*: double numeric value
.Description:
Convert from https://en.wikipedia.org/wiki/Degree_(angle)[degrees]
to https://en.wikipedia.org/wiki/Radian[radians].
["source","sql",subs="attributes,macros"]
--------------------------------------------------
include-tagged::{sql-specs}/docs.csv-spec[mathInlineRadians]
--------------------------------------------------
[[sql-functions-math-sin]]
===== `SIN`
.Synopsis:
[source, sql]
--------------------------------------------------
SIN(numeric_exp<1>)
--------------------------------------------------
*Input*:
<1> numeric expression
*Output*: double numeric value
.Description:
Returns the https://en.wikipedia.org/wiki/Trigonometric_functions#sine[sine] of `numeric_exp`, where `numeric_exp` is an angle expressed in radians.
["source","sql",subs="attributes,macros"]
--------------------------------------------------
include-tagged::{sql-specs}/docs.csv-spec[mathInlineSine]
--------------------------------------------------
[[sql-functions-math-sinh]]
===== `SINH`
.Synopsis:
[source, sql]
--------------------------------------------------
SINH(numeric_exp<1>)
--------------------------------------------------
*Input*:
<1> numeric expression
*Output*: double numeric value
.Description:
Returns the https://en.wikipedia.org/wiki/Hyperbolic_function[hyperbolic sine] of `numeric_exp`.
["source","sql",subs="attributes,macros"]
--------------------------------------------------
include-tagged::{sql-specs}/docs.csv-spec[mathInlineSinh]
--------------------------------------------------
[[sql-functions-math-tan]]
===== `TAN`
.Synopsis:
[source, sql]
--------------------------------------------------
TAN(numeric_exp<1>)
--------------------------------------------------
*Input*:
<1> numeric expression
*Output*: double numeric value
.Description:
Returns the https://en.wikipedia.org/wiki/Trigonometric_functions#tangent[tangent] of `numeric_exp`, where `numeric_exp` is an angle expressed in radians.
2018-09-05 18:19:49 -04:00
2018-09-24 19:42:18 -04:00
["source","sql",subs="attributes,macros"]
2018-09-05 18:19:49 -04:00
--------------------------------------------------
2018-09-24 19:42:18 -04:00
include-tagged::{sql-specs}/docs.csv-spec[mathInlineTanget]
2018-09-05 18:19:49 -04:00
--------------------------------------------------