math.asciidoc 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707
  1. [role="xpack"]
  2. [testenv="basic"]
  3. [[sql-functions-math]]
  4. === Mathematical Functions
  5. All math and trigonometric functions require their input (where applicable)
  6. to be numeric.
  7. [[sql-functions-math-generic]]
  8. [float]
  9. === Generic
  10. [[sql-functions-math-abs]]
  11. ==== `ABS`
  12. .Synopsis:
  13. [source, sql]
  14. --------------------------------------------------
  15. ABS(numeric_exp<1>)
  16. --------------------------------------------------
  17. *Input*:
  18. <1> numeric expression
  19. *Output*: numeric
  20. .Description:
  21. Returns the https://en.wikipedia.org/wiki/Absolute_value[absolute value] of `numeric_exp`. The return type is the same as the input type.
  22. ["source","sql",subs="attributes,macros"]
  23. --------------------------------------------------
  24. include-tagged::{sql-specs}/docs/docs.csv-spec[abs]
  25. --------------------------------------------------
  26. [[sql-functions-math-cbrt]]
  27. ==== `CBRT`
  28. .Synopsis:
  29. [source, sql]
  30. --------------------------------------------------
  31. CBRT(numeric_exp<1>)
  32. --------------------------------------------------
  33. *Input*:
  34. <1> numeric expression
  35. *Output*: double numeric value
  36. .Description:
  37. Returns the https://en.wikipedia.org/wiki/Cube_root[cube root] of `numeric_exp`.
  38. ["source","sql",subs="attributes,macros"]
  39. --------------------------------------------------
  40. include-tagged::{sql-specs}/docs/docs.csv-spec[mathInlineCbrtWithNegativeValue]
  41. --------------------------------------------------
  42. [[sql-functions-math-ceil]]
  43. ==== `CEIL/CEILING`
  44. .Synopsis:
  45. [source, sql]
  46. --------------------------------------------------
  47. CEIL(numeric_exp<1>)
  48. --------------------------------------------------
  49. *Input*:
  50. <1> numeric expression
  51. *Output*: integer or long numeric value
  52. .Description:
  53. Returns the smallest integer greater than or equal to `numeric_exp`.
  54. ["source","sql",subs="attributes,macros"]
  55. --------------------------------------------------
  56. include-tagged::{sql-specs}/docs/docs.csv-spec[mathInlineCeiling]
  57. --------------------------------------------------
  58. [[sql-functions-math-e]]
  59. ==== `E`
  60. .Synopsis:
  61. [source, sql]
  62. --------------------------------------------------
  63. E()
  64. --------------------------------------------------
  65. *Input*: _none_
  66. *Output*: `2.718281828459045`
  67. .Description:
  68. Returns https://en.wikipedia.org/wiki/E_%28mathematical_constant%29[Euler's number].
  69. ["source","sql",subs="attributes,macros"]
  70. --------------------------------------------------
  71. include-tagged::{sql-specs}/docs/docs.csv-spec[mathEulersNumber]
  72. --------------------------------------------------
  73. [[sql-functions-math-exp]]
  74. ==== `EXP`
  75. .Synopsis:
  76. [source, sql]
  77. --------------------------------------------------
  78. EXP(numeric_exp<1>)
  79. --------------------------------------------------
  80. *Input*:
  81. <1> float numeric expression
  82. *Output*: double numeric value
  83. .Description:
  84. Returns https://en.wikipedia.org/wiki/Exponential_function[Euler's number at the power] of `numeric_exp` e^numeric_exp^.
  85. ["source","sql",subs="attributes,macros"]
  86. --------------------------------------------------
  87. include-tagged::{sql-specs}/docs/docs.csv-spec[mathExpInline]
  88. --------------------------------------------------
  89. [[sql-functions-math-expm1]]
  90. ==== `EXPM1`
  91. .Synopsis:
  92. [source, sql]
  93. --------------------------------------------------
  94. EXPM1(numeric_exp<1>)
  95. --------------------------------------------------
  96. *Input*:
  97. <1> float numeric expression
  98. *Output*: double numeric value
  99. .Description:
  100. 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).
  101. ["source","sql",subs="attributes,macros"]
  102. --------------------------------------------------
  103. include-tagged::{sql-specs}/docs/docs.csv-spec[mathExpm1Inline]
  104. --------------------------------------------------
  105. [[sql-functions-math-floor]]
  106. ==== `FLOOR`
  107. .Synopsis:
  108. [source, sql]
  109. --------------------------------------------------
  110. FLOOR(numeric_exp<1>)
  111. --------------------------------------------------
  112. *Input*:
  113. <1> numeric expression
  114. *Output*: integer or long numeric value
  115. .Description:
  116. Returns the largest integer less than or equal to `numeric_exp`.
  117. ["source","sql",subs="attributes,macros"]
  118. --------------------------------------------------
  119. include-tagged::{sql-specs}/docs/docs.csv-spec[mathInlineFloor]
  120. --------------------------------------------------
  121. [[sql-functions-math-log]]
  122. ==== `LOG`
  123. .Synopsis:
  124. [source, sql]
  125. --------------------------------------------------
  126. LOG(numeric_exp<1>)
  127. --------------------------------------------------
  128. *Input*:
  129. <1> numeric expression
  130. *Output*: double numeric value
  131. .Description:
  132. Returns the https://en.wikipedia.org/wiki/Natural_logarithm[natural logarithm] of `numeric_exp`.
  133. ["source","sql",subs="attributes,macros"]
  134. --------------------------------------------------
  135. include-tagged::{sql-specs}/docs/docs.csv-spec[mathInlineLog]
  136. --------------------------------------------------
  137. [[sql-functions-math-log10]]
  138. ==== `LOG10`
  139. .Synopsis:
  140. [source, sql]
  141. --------------------------------------------------
  142. LOG10(numeric_exp<1>)
  143. --------------------------------------------------
  144. *Input*:
  145. <1> numeric expression
  146. *Output*: double numeric value
  147. .Description:
  148. Returns the https://en.wikipedia.org/wiki/Common_logarithm[base 10 logarithm] of `numeric_exp`.
  149. ["source","sql",subs="attributes,macros"]
  150. --------------------------------------------------
  151. include-tagged::{sql-specs}/docs/docs.csv-spec[mathInlineLog10]
  152. --------------------------------------------------
  153. [[sql-functions-math-pi]]
  154. ==== `PI`
  155. .Synopsis:
  156. [source, sql]
  157. --------------------------------------------------
  158. PI()
  159. --------------------------------------------------
  160. *Input*: _none_
  161. *Output*: `3.141592653589793`
  162. .Description:
  163. Returns https://en.wikipedia.org/wiki/Pi[PI number].
  164. ["source","sql",subs="attributes,macros"]
  165. --------------------------------------------------
  166. include-tagged::{sql-specs}/docs/docs.csv-spec[mathPINumber]
  167. --------------------------------------------------
  168. [[sql-functions-math-power]]
  169. ==== `POWER`
  170. .Synopsis:
  171. [source, sql]
  172. --------------------------------------------------
  173. POWER(numeric_exp<1>, integer_exp<2>)
  174. --------------------------------------------------
  175. *Input*:
  176. <1> numeric expression
  177. <2> integer expression
  178. *Output*: double numeric value
  179. .Description:
  180. Returns the value of `numeric_exp` to the power of `integer_exp`.
  181. ["source","sql",subs="attributes,macros"]
  182. --------------------------------------------------
  183. include-tagged::{sql-specs}/docs/docs.csv-spec[mathInlinePowerPositive]
  184. --------------------------------------------------
  185. ["source","sql",subs="attributes,macros"]
  186. --------------------------------------------------
  187. include-tagged::{sql-specs}/docs/docs.csv-spec[mathInlinePowerNegative]
  188. --------------------------------------------------
  189. [[sql-functions-math-random]]
  190. ==== `RANDOM/RAND`
  191. .Synopsis:
  192. [source, sql]
  193. --------------------------------------------------
  194. RANDOM(seed<1>)
  195. --------------------------------------------------
  196. *Input*:
  197. <1> numeric expression
  198. *Output*: double numeric value
  199. .Description:
  200. Returns a random double using the given seed.
  201. ["source","sql",subs="attributes,macros"]
  202. --------------------------------------------------
  203. include-tagged::{sql-specs}/docs/docs.csv-spec[mathRandom]
  204. --------------------------------------------------
  205. [[sql-functions-math-round]]
  206. ==== `ROUND`
  207. .Synopsis:
  208. [source, sql]
  209. ----
  210. ROUND(numeric_exp<1>[, integer_exp<2>])
  211. ----
  212. *Input*:
  213. <1> numeric expression
  214. <2> integer expression; optional
  215. *Output*: numeric
  216. .Description:
  217. Returns `numeric_exp` rounded to `integer_exp` places right of the decimal point. If `integer_exp` is negative,
  218. `numeric_exp` is rounded to |`integer_exp`| places to the left of the decimal point. If `integer_exp` is omitted,
  219. the function will perform as if `integer_exp` would be 0. The returned numeric data type is the same as the data type
  220. of `numeric_exp`.
  221. ["source","sql",subs="attributes,macros"]
  222. --------------------------------------------------
  223. include-tagged::{sql-specs}/docs/docs.csv-spec[mathRoundWithPositiveParameter]
  224. --------------------------------------------------
  225. ["source","sql",subs="attributes,macros"]
  226. --------------------------------------------------
  227. include-tagged::{sql-specs}/docs/docs.csv-spec[mathRoundWithNegativeParameter]
  228. --------------------------------------------------
  229. [[sql-functions-math-sign]]
  230. ==== `SIGN/SIGNUM`
  231. .Synopsis:
  232. [source, sql]
  233. --------------------------------------------------
  234. SIGN(numeric_exp<1>)
  235. --------------------------------------------------
  236. *Input*:
  237. <1> numeric expression
  238. *Output*: [-1, 0, 1]
  239. .Description:
  240. 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.
  241. ["source","sql",subs="attributes,macros"]
  242. --------------------------------------------------
  243. include-tagged::{sql-specs}/docs/docs.csv-spec[mathInlineSign]
  244. --------------------------------------------------
  245. [[sql-functions-math-sqrt]]
  246. ==== `SQRT`
  247. .Synopsis:
  248. [source, sql]
  249. --------------------------------------------------
  250. SQRT(numeric_exp<1>)
  251. --------------------------------------------------
  252. *Input*:
  253. <1> numeric expression
  254. *Output*: double numeric value
  255. .Description:
  256. Returns https://en.wikipedia.org/wiki/Square_root[square root] of `numeric_exp`.
  257. ["source","sql",subs="attributes,macros"]
  258. --------------------------------------------------
  259. include-tagged::{sql-specs}/docs/docs.csv-spec[mathInlineSqrt]
  260. --------------------------------------------------
  261. [[sql-functions-math-truncate]]
  262. ==== `TRUNCATE`
  263. .Synopsis:
  264. [source, sql]
  265. ----
  266. TRUNCATE(numeric_exp<1>[, integer_exp<2>])
  267. ----
  268. *Input*:
  269. <1> numeric expression
  270. <2> integer expression; optional
  271. *Output*: numeric
  272. .Description:
  273. Returns `numeric_exp` truncated to `integer_exp` places right of the decimal point. If `integer_exp` is negative,
  274. `numeric_exp` is truncated to |`integer_exp`| places to the left of the decimal point. If `integer_exp` is omitted,
  275. the function will perform as if `integer_exp` would be 0. The returned numeric data type is the same as the data type
  276. of `numeric_exp`.
  277. ["source","sql",subs="attributes,macros"]
  278. --------------------------------------------------
  279. include-tagged::{sql-specs}/docs/docs.csv-spec[mathTruncateWithPositiveParameter]
  280. --------------------------------------------------
  281. ["source","sql",subs="attributes,macros"]
  282. --------------------------------------------------
  283. include-tagged::{sql-specs}/docs/docs.csv-spec[mathTruncateWithNegativeParameter]
  284. --------------------------------------------------
  285. [[sql-functions-math-trigonometric]]
  286. [float]
  287. === Trigonometric
  288. [[sql-functions-math-acos]]
  289. ==== `ACOS`
  290. .Synopsis:
  291. [source, sql]
  292. --------------------------------------------------
  293. ACOS(numeric_exp<1>)
  294. --------------------------------------------------
  295. *Input*:
  296. <1> numeric expression
  297. *Output*: double numeric value
  298. .Description:
  299. Returns the https://en.wikipedia.org/wiki/Inverse_trigonometric_functions[arccosine] of `numeric_exp` as an angle, expressed in radians.
  300. ["source","sql",subs="attributes,macros"]
  301. --------------------------------------------------
  302. include-tagged::{sql-specs}/docs/docs.csv-spec[mathInlineAcos]
  303. --------------------------------------------------
  304. [[sql-functions-math-asin]]
  305. ==== `ASIN`
  306. .Synopsis:
  307. [source, sql]
  308. --------------------------------------------------
  309. ASIN(numeric_exp<1>)
  310. --------------------------------------------------
  311. *Input*:
  312. <1> numeric expression
  313. *Output*: double numeric value
  314. .Description:
  315. Returns the https://en.wikipedia.org/wiki/Inverse_trigonometric_functions[arcsine] of `numeric_exp` as an angle, expressed in radians.
  316. ["source","sql",subs="attributes,macros"]
  317. --------------------------------------------------
  318. include-tagged::{sql-specs}/docs/docs.csv-spec[mathInlineAsin]
  319. --------------------------------------------------
  320. [[sql-functions-math-atan]]
  321. ==== `ATAN`
  322. .Synopsis:
  323. [source, sql]
  324. --------------------------------------------------
  325. ATAN(numeric_exp<1>)
  326. --------------------------------------------------
  327. *Input*:
  328. <1> numeric expression
  329. *Output*: double numeric value
  330. .Description:
  331. Returns the https://en.wikipedia.org/wiki/Inverse_trigonometric_functions[arctangent] of `numeric_exp` as an angle, expressed in radians.
  332. ["source","sql",subs="attributes,macros"]
  333. --------------------------------------------------
  334. include-tagged::{sql-specs}/docs/docs.csv-spec[mathInlineAtan]
  335. --------------------------------------------------
  336. [[sql-functions-math-atan2]]
  337. ==== `ATAN2`
  338. .Synopsis:
  339. [source, sql]
  340. --------------------------------------------------
  341. ATAN2(ordinate<1>, abscisa<2>)
  342. --------------------------------------------------
  343. *Input*:
  344. <1> numeric expression
  345. <2> numeric expression
  346. *Output*: double numeric value
  347. .Description:
  348. Returns the https://en.wikipedia.org/wiki/Atan2[arctangent of the `ordinate` and `abscisa` coordinates] specified as an angle, expressed in radians.
  349. ["source","sql",subs="attributes,macros"]
  350. --------------------------------------------------
  351. include-tagged::{sql-specs}/docs/docs.csv-spec[mathInlineAtan2]
  352. --------------------------------------------------
  353. [[sql-functions-math-cos]]
  354. ==== `COS`
  355. .Synopsis:
  356. [source, sql]
  357. --------------------------------------------------
  358. COS(numeric_exp<1>)
  359. --------------------------------------------------
  360. *Input*:
  361. <1> numeric expression
  362. *Output*: double numeric value
  363. .Description:
  364. Returns the https://en.wikipedia.org/wiki/Trigonometric_functions#cosine[cosine] of `numeric_exp`, where `numeric_exp` is an angle expressed in radians.
  365. ["source","sql",subs="attributes,macros"]
  366. --------------------------------------------------
  367. include-tagged::{sql-specs}/docs/docs.csv-spec[mathInlineCosine]
  368. --------------------------------------------------
  369. [[sql-functions-math-cosh]]
  370. ==== `COSH`
  371. .Synopsis:
  372. [source, sql]
  373. --------------------------------------------------
  374. COSH(numeric_exp<1>)
  375. --------------------------------------------------
  376. *Input*:
  377. <1> numeric expression
  378. *Output*: double numeric value
  379. .Description:
  380. Returns the https://en.wikipedia.org/wiki/Hyperbolic_function[hyperbolic cosine] of `numeric_exp`.
  381. ["source","sql",subs="attributes,macros"]
  382. --------------------------------------------------
  383. include-tagged::{sql-specs}/docs/docs.csv-spec[mathInlineCosh]
  384. --------------------------------------------------
  385. [[sql-functions-math-cot]]
  386. ==== `COT`
  387. .Synopsis:
  388. [source, sql]
  389. --------------------------------------------------
  390. COT(numeric_exp<1>)
  391. --------------------------------------------------
  392. *Input*:
  393. <1> numeric expression
  394. *Output*: double numeric value
  395. .Description:
  396. 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.
  397. ["source","sql",subs="attributes,macros"]
  398. --------------------------------------------------
  399. include-tagged::{sql-specs}/docs/docs.csv-spec[mathInlineCotangent]
  400. --------------------------------------------------
  401. [[sql-functions-math-degrees]]
  402. ==== `DEGREES`
  403. .Synopsis:
  404. [source, sql]
  405. --------------------------------------------------
  406. DEGREES(numeric_exp<1>)
  407. --------------------------------------------------
  408. *Input*:
  409. <1> numeric expression
  410. *Output*: double numeric value
  411. .Description:
  412. Convert from https://en.wikipedia.org/wiki/Radian[radians]
  413. to https://en.wikipedia.org/wiki/Degree_(angle)[degrees].
  414. ["source","sql",subs="attributes,macros"]
  415. --------------------------------------------------
  416. include-tagged::{sql-specs}/docs/docs.csv-spec[mathInlineDegrees]
  417. --------------------------------------------------
  418. [[sql-functions-math-radians]]
  419. ==== `RADIANS`
  420. .Synopsis:
  421. [source, sql]
  422. --------------------------------------------------
  423. RADIANS(numeric_exp<1>)
  424. --------------------------------------------------
  425. *Input*:
  426. <1> numeric expression
  427. *Output*: double numeric value
  428. .Description:
  429. Convert from https://en.wikipedia.org/wiki/Degree_(angle)[degrees]
  430. to https://en.wikipedia.org/wiki/Radian[radians].
  431. ["source","sql",subs="attributes,macros"]
  432. --------------------------------------------------
  433. include-tagged::{sql-specs}/docs/docs.csv-spec[mathInlineRadians]
  434. --------------------------------------------------
  435. [[sql-functions-math-sin]]
  436. ==== `SIN`
  437. .Synopsis:
  438. [source, sql]
  439. --------------------------------------------------
  440. SIN(numeric_exp<1>)
  441. --------------------------------------------------
  442. *Input*:
  443. <1> numeric expression
  444. *Output*: double numeric value
  445. .Description:
  446. Returns the https://en.wikipedia.org/wiki/Trigonometric_functions#sine[sine] of `numeric_exp`, where `numeric_exp` is an angle expressed in radians.
  447. ["source","sql",subs="attributes,macros"]
  448. --------------------------------------------------
  449. include-tagged::{sql-specs}/docs/docs.csv-spec[mathInlineSine]
  450. --------------------------------------------------
  451. [[sql-functions-math-sinh]]
  452. ==== `SINH`
  453. .Synopsis:
  454. [source, sql]
  455. --------------------------------------------------
  456. SINH(numeric_exp<1>)
  457. --------------------------------------------------
  458. *Input*:
  459. <1> numeric expression
  460. *Output*: double numeric value
  461. .Description:
  462. Returns the https://en.wikipedia.org/wiki/Hyperbolic_function[hyperbolic sine] of `numeric_exp`.
  463. ["source","sql",subs="attributes,macros"]
  464. --------------------------------------------------
  465. include-tagged::{sql-specs}/docs/docs.csv-spec[mathInlineSinh]
  466. --------------------------------------------------
  467. [[sql-functions-math-tan]]
  468. ==== `TAN`
  469. .Synopsis:
  470. [source, sql]
  471. --------------------------------------------------
  472. TAN(numeric_exp<1>)
  473. --------------------------------------------------
  474. *Input*:
  475. <1> numeric expression
  476. *Output*: double numeric value
  477. .Description:
  478. Returns the https://en.wikipedia.org/wiki/Trigonometric_functions#tangent[tangent] of `numeric_exp`, where `numeric_exp` is an angle expressed in radians.
  479. ["source","sql",subs="attributes,macros"]
  480. --------------------------------------------------
  481. include-tagged::{sql-specs}/docs/docs.csv-spec[mathInlineTanget]
  482. --------------------------------------------------