OpenSearch/docs/en/sql/functions/index.asciidoc

259 lines
8.7 KiB
Plaintext
Raw Normal View History

[[sql-functions]]
== Functions and Operators
=== Comparison Operators
Elasticsearch SQL supports the following comparison operators:
* Equality (`=`)
["source","sql",subs="attributes,callouts,macros"]
--------------------------------------------------
include-tagged::{sql-specs}/filter.sql-spec[whereFieldEquality]
--------------------------------------------------
* Inequality (`<>` or `!=`)
["source","sql",subs="attributes,callouts,macros"]
--------------------------------------------------
include-tagged::{sql-specs}/filter.sql-spec[whereFieldNonEquality]
--------------------------------------------------
* Comparison (`<`, `<=`, `>`, `>=`)
["source","sql",subs="attributes,callouts,macros"]
--------------------------------------------------
include-tagged::{sql-specs}/filter.sql-spec[whereFieldLessThan]
--------------------------------------------------
* `BETWEEN`
["source","sql",subs="attributes,callouts,macros"]
--------------------------------------------------
include-tagged::{sql-specs}/filter.sql-spec[whereBetween]
--------------------------------------------------
* `IS NULL`/`IS NOT NULL`
["source","sql",subs="attributes,callouts,macros"]
--------------------------------------------------
include-tagged::{sql-specs}/filter.sql-spec[whereIsNotNullAndIsNull]
--------------------------------------------------
=== Logical Operators
Elasticsearch SQL supports the following logical operators:
* `AND`
["source","sql",subs="attributes,callouts,macros"]
--------------------------------------------------
include-tagged::{sql-specs}/filter.sql-spec[whereFieldAndComparison]
--------------------------------------------------
* `OR`
["source","sql",subs="attributes,callouts,macros"]
--------------------------------------------------
include-tagged::{sql-specs}/filter.sql-spec[whereFieldOrComparison]
--------------------------------------------------
* `NOT`
["source","sql",subs="attributes,callouts,macros"]
--------------------------------------------------
include-tagged::{sql-specs}/filter.sql-spec[whereFieldEqualityNot]
--------------------------------------------------
=== Math Operators
Elasticsearch SQL supports the following math operators:
* Add (`+`)
["source","sql",subs="attributes,callouts,macros"]
--------------------------------------------------
include-tagged::{sql-specs}/arithmetic.sql-spec[plus]
--------------------------------------------------
* Subtract (infix `-`)
["source","sql",subs="attributes,callouts,macros"]
--------------------------------------------------
include-tagged::{sql-specs}/arithmetic.sql-spec[minus]
--------------------------------------------------
* Negate (unary `-`)
["source","sql",subs="attributes,callouts,macros"]
--------------------------------------------------
include-tagged::{sql-specs}/arithmetic.sql-spec[unaryMinus]
--------------------------------------------------
* Multiply (`*`)
["source","sql",subs="attributes,callouts,macros"]
--------------------------------------------------
include-tagged::{sql-specs}/arithmetic.sql-spec[multiply]
--------------------------------------------------
* Divide (`/`)
["source","sql",subs="attributes,callouts,macros"]
--------------------------------------------------
include-tagged::{sql-specs}/arithmetic.sql-spec[divide]
--------------------------------------------------
* https://en.wikipedia.org/wiki/Modulo_operation[Modulo] (`%`)
["source","sql",subs="attributes,callouts,macros"]
--------------------------------------------------
include-tagged::{sql-specs}/arithmetic.sql-spec[mod]
--------------------------------------------------
=== Math Functions
==== Basic
* https://en.wikipedia.org/wiki/Absolute_value[Absolute value] (`ABS`)
["source","sql",subs="attributes,callouts,macros"]
--------------------------------------------------
include-tagged::{sql-specs}/math.sql-spec[abs]
--------------------------------------------------
* https://en.wikipedia.org/wiki/Rounding#Round_half_up[Round] (`ROUND`)
TODO make the example in the tests presentable
NOTE: This rounds "half up" meaning that `ROUND(-1.5)` results in `-1`.
* https://en.wikipedia.org/wiki/Floor_and_ceiling_functions[Ceiling] (`CEIL`)
TODO make the example in the tests presentable
* https://en.wikipedia.org/wiki/Floor_and_ceiling_functions[Floor] (`FLOOR`)
TODO make the example in the tests presentable
* https://en.wikipedia.org/wiki/Natural_logarithm[Natural logarithm] (`LOG`)
["source","sql",subs="attributes,callouts,macros"]
--------------------------------------------------
include-tagged::{sql-specs}/math.sql-spec[log]
--------------------------------------------------
* https://en.wikipedia.org/wiki/Logarithm[Logarithm] base 10 (`LOG10`)
["source","sql",subs="attributes,callouts,macros"]
--------------------------------------------------
include-tagged::{sql-specs}/math.sql-spec[log10]
--------------------------------------------------
* https://en.wikipedia.org/wiki/Square_root[Square root] (`SQRT`)
["source","sql",subs="attributes,callouts,macros"]
--------------------------------------------------
include-tagged::{sql-specs}/math.sql-spec[sqrt]
--------------------------------------------------
* https://en.wikipedia.org/wiki/Cube_root[Cube root] (`CBRT`)
TODO make the example in the tests presentable
* https://en.wikipedia.org/wiki/Exponential_function[e^x^] (`EXP`)
["source","sql",subs="attributes,callouts,macros"]
--------------------------------------------------
include-tagged::{sql-specs}/math.sql-spec[exp]
--------------------------------------------------
* https://docs.oracle.com/javase/8/docs/api/java/lang/Math.html#expm1-double-[e^x^ - 1] (`EXPM1`)
["source","sql",subs="attributes,callouts,macros"]
--------------------------------------------------
include-tagged::{sql-specs}/math.sql-spec[expm1]
--------------------------------------------------
==== Trigonometric
* Convert from https://en.wikipedia.org/wiki/Radian[radians]
to https://en.wikipedia.org/wiki/Degree_(angle)[degrees] (`DEGREES`)
["source","sql",subs="attributes,callouts,macros"]
--------------------------------------------------
include-tagged::{sql-specs}/math.sql-spec[degrees]
--------------------------------------------------
* Convert from https://en.wikipedia.org/wiki/Degree_(angle)[degrees]
to https://en.wikipedia.org/wiki/Radian[radians] (`RADIANS`)
["source","sql",subs="attributes,callouts,macros"]
--------------------------------------------------
include-tagged::{sql-specs}/math.sql-spec[degrees]
--------------------------------------------------
* https://en.wikipedia.org/wiki/Trigonometric_functions#sine[Sine] (`SIN`)
["source","sql",subs="attributes,callouts,macros"]
--------------------------------------------------
include-tagged::{sql-specs}/math.sql-spec[sin]
--------------------------------------------------
* https://en.wikipedia.org/wiki/Trigonometric_functions#cosine[Cosine] (`COS`)
["source","sql",subs="attributes,callouts,macros"]
--------------------------------------------------
include-tagged::{sql-specs}/math.sql-spec[cos]
--------------------------------------------------
* https://en.wikipedia.org/wiki/Trigonometric_functions#tangent[Tangent] (`TAN`)
["source","sql",subs="attributes,callouts,macros"]
--------------------------------------------------
include-tagged::{sql-specs}/math.sql-spec[tan]
--------------------------------------------------
* https://en.wikipedia.org/wiki/Inverse_trigonometric_functions[Arc sine] (`ASIN`)
["source","sql",subs="attributes,callouts,macros"]
--------------------------------------------------
include-tagged::{sql-specs}/math.sql-spec[asin]
--------------------------------------------------
* https://en.wikipedia.org/wiki/Inverse_trigonometric_functions[Arc cosine] (`ACOS`)
["source","sql",subs="attributes,callouts,macros"]
--------------------------------------------------
include-tagged::{sql-specs}/math.sql-spec[acos]
--------------------------------------------------
* https://en.wikipedia.org/wiki/Inverse_trigonometric_functions[Arc tangent] (`ATAN`)
["source","sql",subs="attributes,callouts,macros"]
--------------------------------------------------
include-tagged::{sql-specs}/math.sql-spec[atan]
--------------------------------------------------
* https://en.wikipedia.org/wiki/Hyperbolic_function[Hyperbolic sine] (`SINH`)
["source","sql",subs="attributes,callouts,macros"]
--------------------------------------------------
include-tagged::{sql-specs}/math.sql-spec[sinh]
--------------------------------------------------
* https://en.wikipedia.org/wiki/Hyperbolic_function[Hyperbolic cosine] (`COSH`)
["source","sql",subs="attributes,callouts,macros"]
--------------------------------------------------
include-tagged::{sql-specs}/math.sql-spec[cosh]
--------------------------------------------------
// conversion
// date time
// aggregate
// geospatial