OpenSearch/docs/reference/sql/functions/operators.asciidoc
Marios Trivyzas 032bcf99d6
SQL: Implement :: cast operator (#38774)
`<expression>::<dataType>` is a simplified altenative syntax to
`CAST(<expression> AS <dataType> which exists in PostgreSQL and
provides an improved user experience and possibly more compact
SQL queries.

Fixes: #38717
2019-02-12 16:54:14 +02:00

147 lines
4.7 KiB
Plaintext

[role="xpack"]
[testenv="basic"]
[[sql-operators]]
=== Comparison Operators
Boolean operator for comparing against one or multiple expressions.
* Equality (`=`)
["source","sql",subs="attributes,callouts,macros"]
--------------------------------------------------
include-tagged::{sql-specs}/filter.sql-spec[whereFieldEquality]
--------------------------------------------------
* Null safe Equality (`<=>`)
["source","sql",subs="attributes,callouts,macros"]
--------------------------------------------------
include-tagged::{sql-specs}/docs.csv-spec[nullEqualsCompareWithNull]
--------------------------------------------------
["source","sql",subs="attributes,callouts,macros"]
--------------------------------------------------
include-tagged::{sql-specs}/docs.csv-spec[nullEqualsCompareTwoNulls]
--------------------------------------------------
* 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]
--------------------------------------------------
* `IN (<value1>, <value2>, ...)`
["source","sql",subs="attributes,callouts,macros"]
--------------------------------------------------
include-tagged::{sql-specs}/filter.sql-spec[whereWithInAndMultipleValues]
--------------------------------------------------
[[sql-operators-logical]]
=== Logical Operators
Boolean operator for evaluating one or two expressions.
* `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]
--------------------------------------------------
[[sql-operators-math]]
=== Math Operators
Perform mathematical operations affecting one or two values.
The result is a value of numeric type.
* 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] or Remainder(`%`)
["source","sql",subs="attributes,callouts,macros"]
--------------------------------------------------
include-tagged::{sql-specs}/arithmetic.sql-spec[mod]
--------------------------------------------------
[[sql-operators-cast]]
=== Cast Operators
* Cast (`::`)
`::` provides an alternative syntax to the <<sql-functions-type-conversion-cast>> function.
["source","sql",subs="attributes,callouts,macros"]
--------------------------------------------------
include-tagged::{sql-specs}/docs.csv-spec[conversionStringToLongCastOperator]
--------------------------------------------------