| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707 | [role="xpack"][testenv="basic"][[sql-functions-math]]=== Math Functionsbeta[]All math and trigonometric functions require their input (where applicable)to be numeric.==== Generic[[sql-functions-math-abs]]===== `ABS`.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>)CEILING(numeric_exp<2>)--------------------------------------------------*Input*:<1> numeric expression<2> 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*:<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"]--------------------------------------------------include-tagged::{sql-specs}/docs.csv-spec[mathExpm1Inline]--------------------------------------------------[[sql-functions-math-floor]]===== `FLOOR`.Synopsis:[source, sql]--------------------------------------------------FLOOR(numeric_exp<1>)--------------------------------------------------*Input*:<1> numeric expression*Output*: integer or long numeric value.Description:Returns the largest integer less than or equal to `numeric_exp`.["source","sql",subs="attributes,macros"]--------------------------------------------------include-tagged::{sql-specs}/docs.csv-spec[mathInlineFloor]--------------------------------------------------[[sql-functions-math-log]]===== `LOG`.Synopsis:[source, sql]--------------------------------------------------LOG(numeric_exp<1>)--------------------------------------------------*Input*:<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"]--------------------------------------------------include-tagged::{sql-specs}/docs.csv-spec[mathInlineLog]--------------------------------------------------[[sql-functions-math-log10]]===== `LOG10`.Synopsis:[source, sql]--------------------------------------------------LOG10(numeric_exp<1>)--------------------------------------------------*Input*:<1> numeric expression*Output*: double numeric value.Description:Returns the https://en.wikipedia.org/wiki/Common_logarithm[base 10 logarithm] of `numeric_exp`.["source","sql",subs="attributes,macros"]--------------------------------------------------include-tagged::{sql-specs}/docs.csv-spec[mathInlineLog10]--------------------------------------------------[[sql-functions-math-pi]]===== `PI`.Synopsis:[source, sql]--------------------------------------------------PI()--------------------------------------------------*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]--------------------------------------------------[[sql-functions-math-random]]===== `RANDOM`.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]--------------------------------------------------[[sql-functions-math-round]]===== `ROUND`.Synopsis:[source, sql]----ROUND(numeric_exp<1>[, integer_exp<2>])----*Input*:<1> numeric expression<2> integer expression; optional*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`.["source","sql",subs="attributes,macros"]--------------------------------------------------include-tagged::{sql-specs}/docs.csv-spec[mathRoundWithPositiveParameter]--------------------------------------------------["source","sql",subs="attributes,macros"]--------------------------------------------------include-tagged::{sql-specs}/docs.csv-spec[mathRoundWithNegativeParameter]--------------------------------------------------[[sql-functions-math-sign]]===== `SIGN`.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"]--------------------------------------------------include-tagged::{sql-specs}/docs.csv-spec[mathInlineSign]--------------------------------------------------[[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`.Synopsis:[source, sql]----TRUNCATE(numeric_exp<1>[, integer_exp<2>])----*Input*:<1> numeric expression<2> integer expression; optional*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`.["source","sql",subs="attributes,macros"]--------------------------------------------------include-tagged::{sql-specs}/docs.csv-spec[mathTruncateWithPositiveParameter]--------------------------------------------------["source","sql",subs="attributes,macros"]--------------------------------------------------include-tagged::{sql-specs}/docs.csv-spec[mathTruncateWithNegativeParameter]--------------------------------------------------==== Trigonometric[[sql-functions-math-acos]]===== `ACOS`.Synopsis:[source, sql]--------------------------------------------------ACOS(numeric_exp<1>)--------------------------------------------------*Input*:<1> numeric expression*Output*: double numeric value.Description: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"]--------------------------------------------------include-tagged::{sql-specs}/docs.csv-spec[mathInlineAcos]--------------------------------------------------[[sql-functions-math-asin]]===== `ASIN`.Synopsis:[source, sql]--------------------------------------------------ASIN(numeric_exp<1>)--------------------------------------------------*Input*:<1> numeric expression*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"]--------------------------------------------------include-tagged::{sql-specs}/docs.csv-spec[mathInlineAsin]--------------------------------------------------[[sql-functions-math-atan]]===== `ATAN`.Synopsis:[source, sql]--------------------------------------------------ATAN(numeric_exp<1>)--------------------------------------------------*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.["source","sql",subs="attributes,macros"]--------------------------------------------------include-tagged::{sql-specs}/docs.csv-spec[mathInlineAtan]--------------------------------------------------[[sql-functions-math-atan2]]===== `ATAN2`.Synopsis:[source, sql]--------------------------------------------------ATAN2(ordinate<1>, abscisa<2>)--------------------------------------------------*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.["source","sql",subs="attributes,macros"]--------------------------------------------------include-tagged::{sql-specs}/docs.csv-spec[mathInlineAtan2]--------------------------------------------------[[sql-functions-math-cos]]===== `COS`.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]--------------------------------------------------COT(numeric_exp<1>)--------------------------------------------------*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.["source","sql",subs="attributes,macros"]--------------------------------------------------include-tagged::{sql-specs}/docs.csv-spec[mathInlineTanget]--------------------------------------------------
 |