ClickHouse/doc/reference/en/operators/index.rst

139 lines
2.9 KiB
ReStructuredText
Raw Normal View History

2017-04-26 18:16:31 +00:00
Operators
2017-04-03 19:49:50 +00:00
=========
2017-04-26 18:16:31 +00:00
All operators are transformed to the corresponding functions at the query parsing stage, in accordance with their precedence and associativity.
2017-04-03 19:49:50 +00:00
2017-04-26 18:16:31 +00:00
Access operators
2017-04-03 19:49:50 +00:00
-----------------
2017-04-26 18:16:31 +00:00
``a[N]`` - Access to an array element, arrayElement(a, N) function.
2017-04-03 19:49:50 +00:00
2017-04-26 18:16:31 +00:00
``a.N`` - Access to a tuple element, tupleElement(a, N) function.
2017-04-03 19:49:50 +00:00
2017-04-26 18:16:31 +00:00
Numeric negation operator
2017-04-03 19:49:50 +00:00
----------------------------
2017-04-26 18:16:31 +00:00
``-a`` - negate(a) function
2017-04-03 19:49:50 +00:00
2017-04-26 18:16:31 +00:00
Multiplication and division operators
2017-04-03 19:49:50 +00:00
-----------------------------
2017-04-26 18:16:31 +00:00
``a * b`` - multiply(a, b) function
2017-04-03 19:49:50 +00:00
2017-04-26 18:16:31 +00:00
``a / b`` - divide(a, b) function
2017-04-03 19:49:50 +00:00
2017-04-26 18:16:31 +00:00
``a % b`` - modulo(a, b) function
2017-04-03 19:49:50 +00:00
2017-04-26 18:16:31 +00:00
Addition and subtraction operators
2017-04-03 19:49:50 +00:00
------------------------------
2017-04-26 18:16:31 +00:00
``a + b`` - plus(a, b) function
2017-04-03 19:49:50 +00:00
2017-04-26 18:16:31 +00:00
``a - b`` - minus(a, b) function
2017-04-03 19:49:50 +00:00
2017-04-26 18:16:31 +00:00
Comparison operators
2017-04-03 19:49:50 +00:00
-------------------
2017-04-26 18:16:31 +00:00
``a = b`` - equals(a, b) function
2017-04-03 19:49:50 +00:00
2017-04-26 18:16:31 +00:00
``a == b`` - equals(a, b) function
2017-04-03 19:49:50 +00:00
2017-04-26 18:16:31 +00:00
``a != b`` - notEquals(a, b) function
2017-04-03 19:49:50 +00:00
2017-04-26 18:16:31 +00:00
``a <> b`` - notEquals(a, b) function
2017-04-03 19:49:50 +00:00
2017-04-26 18:16:31 +00:00
``a <= b`` - lessOrEquals(a, b) function
2017-04-03 19:49:50 +00:00
2017-04-26 18:16:31 +00:00
``a >= b`` - greaterOrEquals(a, b) function
2017-04-03 19:49:50 +00:00
2017-04-26 18:16:31 +00:00
``a < b`` - less(a, b) function
2017-04-03 19:49:50 +00:00
2017-04-26 18:16:31 +00:00
``a > b`` - greater(a, b) function
2017-04-03 19:49:50 +00:00
2017-04-26 18:16:31 +00:00
``a LIKE s`` - like(a, b) function
2017-04-03 19:49:50 +00:00
2017-04-26 18:16:31 +00:00
``a NOT LIKE s`` - notLike(a, b) function
2017-04-03 19:49:50 +00:00
2017-04-26 18:16:31 +00:00
``a BETWEEN b AND c`` - equivalent to a >= b AND a <= c
2017-04-03 19:49:50 +00:00
2017-04-26 18:16:31 +00:00
Operators for working with data sets
2017-04-03 19:49:50 +00:00
----------------------------------
2017-04-26 18:16:31 +00:00
*See the section "IN operators".*
2017-04-03 19:49:50 +00:00
2017-04-26 18:16:31 +00:00
``a IN ...`` - in(a, b) function
2017-04-03 19:49:50 +00:00
2017-04-26 18:16:31 +00:00
``a NOT IN ...`` - notIn(a, b) function
2017-04-03 19:49:50 +00:00
2017-04-26 18:16:31 +00:00
``a GLOBAL IN ...`` - globalIn(a, b) function
2017-04-03 19:49:50 +00:00
2017-04-26 18:16:31 +00:00
``a GLOBAL NOT IN ...`` - globalNotIn(a, b) function
2017-04-03 19:49:50 +00:00
2017-04-26 18:16:31 +00:00
Logical negation operator
2017-04-03 19:49:50 +00:00
------------------------------
2017-04-26 18:16:31 +00:00
``NOT a`` - ``not(a)`` function
2017-04-03 19:49:50 +00:00
2017-04-26 18:16:31 +00:00
Logical "AND" operator
2017-04-03 19:49:50 +00:00
-------------------------
2017-04-26 18:16:31 +00:00
``a AND b`` - function ``and(a, b)``
2017-04-03 19:49:50 +00:00
2017-04-26 18:16:31 +00:00
Logical "OR" operator
2017-04-03 19:49:50 +00:00
---------------------------
2017-04-26 18:16:31 +00:00
``a OR b`` - function ``or(a, b)``
2017-04-03 19:49:50 +00:00
2017-04-26 18:16:31 +00:00
Conditional operator
2017-04-03 19:49:50 +00:00
-----------------
2017-04-26 18:16:31 +00:00
``a ? b : c`` - function ``if(a, b, c)``
2017-04-03 19:49:50 +00:00
2017-04-26 18:16:31 +00:00
Conditional expression
2017-04-03 19:49:50 +00:00
------------------
.. code-block:: sql
CASE [x]
WHEN a THEN b
[WHEN ... THEN ...]
ELSE c
END
2017-04-26 18:16:31 +00:00
If x is given - transform(x, [a, ...], [b, ...], c). Otherwise, multiIf(a, b, ..., c).
2017-04-03 19:49:50 +00:00
2017-04-26 18:16:31 +00:00
String concatenation operator
2017-04-03 19:49:50 +00:00
-------------------------
2017-04-26 18:16:31 +00:00
``s1 || s2`` - concat(s1, s2) function
2017-04-03 19:49:50 +00:00
2017-04-26 18:16:31 +00:00
Lambda creation operator
2017-04-03 19:49:50 +00:00
----------------------------------
2017-04-26 18:16:31 +00:00
``x -> expr`` - lambda(x, expr) function
2017-04-03 19:49:50 +00:00
2017-04-26 18:16:31 +00:00
The following operators do not have a priority, since they are brackets:
2017-04-03 19:49:50 +00:00
2017-04-26 18:16:31 +00:00
Array creation operator
2017-04-03 19:49:50 +00:00
--------------------------
2017-04-26 18:16:31 +00:00
``[x1, ...]`` - array(x1, ...) function
2017-04-03 19:49:50 +00:00
2017-04-26 18:16:31 +00:00
Tuple creation operator
2017-04-03 19:49:50 +00:00
-------------------------
2017-04-26 18:16:31 +00:00
``(x1, x2, ...)`` - tuple(x2, x2, ...) function
2017-04-03 19:49:50 +00:00
2017-04-26 18:16:31 +00:00
Associativity
2017-04-03 19:49:50 +00:00
----------------
2017-04-26 18:16:31 +00:00
All binary operators have left associativity. For example, ``'1 + 2 + 3'`` is transformed to ``'plus(plus(1, 2), 3)'``.
Sometimes this doesn't work the way you expect. For example, ``'SELECT 4 > 3 > 2'`` results in ``0``.
2017-04-03 19:49:50 +00:00
2017-04-26 18:16:31 +00:00
For efficiency, the 'and' and 'or' functions accept any number of arguments. The corresponding chains of AND and OR operators are transformed to a single call of these functions.