<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://docs.foji.io/index.php?action=history&amp;feed=atom&amp;title=Relational_Data_-_Operators</id>
	<title>Relational Data - Operators - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://docs.foji.io/index.php?action=history&amp;feed=atom&amp;title=Relational_Data_-_Operators"/>
	<link rel="alternate" type="text/html" href="https://docs.foji.io/index.php?title=Relational_Data_-_Operators&amp;action=history"/>
	<updated>2026-06-13T08:10:31Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.40.1</generator>
	<entry>
		<id>https://docs.foji.io/index.php?title=Relational_Data_-_Operators&amp;diff=2330&amp;oldid=prev</id>
		<title>Chris.Hansen: Import ClickHouse Docs: Wed Aug 28 2024 14:52:43 GMT-0400 (Eastern Daylight Time)</title>
		<link rel="alternate" type="text/html" href="https://docs.foji.io/index.php?title=Relational_Data_-_Operators&amp;diff=2330&amp;oldid=prev"/>
		<updated>2024-08-28T18:52:43Z</updated>

		<summary type="html">&lt;p&gt;Import ClickHouse Docs: Wed Aug 28 2024 14:52:43 GMT-0400 (Eastern Daylight Time)&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;ClickHouse transforms operators to their corresponding functions at the query parsing stage according to their priority, precedence, and associativity.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;access-operators&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
== Access Operators ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;a[N]&amp;lt;/code&amp;gt; – Access to an element of an array. The &amp;lt;code&amp;gt;arrayElement(a, N)&amp;lt;/code&amp;gt; function.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;a.N&amp;lt;/code&amp;gt; – Access to a tuple element. The &amp;lt;code&amp;gt;tupleElement(a, N)&amp;lt;/code&amp;gt; function.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;numeric-negation-operator&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
== Numeric Negation Operator ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;-a&amp;lt;/code&amp;gt; – The &amp;lt;code&amp;gt;negate (a)&amp;lt;/code&amp;gt; function.&lt;br /&gt;
&lt;br /&gt;
For tuple negation: [[Relational_Data_-_Functions_-_Tuple_Functions#tuplenegate|tupleNegate]].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;multiplication-and-division-operators&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
== Multiplication and Division Operators ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;a * b&amp;lt;/code&amp;gt; – The &amp;lt;code&amp;gt;multiply (a, b)&amp;lt;/code&amp;gt; function.&lt;br /&gt;
&lt;br /&gt;
For multiplying tuple by number: [[Relational_Data_-_Functions_-_Tuple_Functions#tuplemultiplybynumber|tupleMultiplyByNumber]], for scalar product: [[Relational_Data_-_Functions_-_Tuple_Functions#dotproduct|dotProduct]].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;a / b&amp;lt;/code&amp;gt; – The &amp;lt;code&amp;gt;divide(a, b)&amp;lt;/code&amp;gt; function.&lt;br /&gt;
&lt;br /&gt;
For dividing tuple by number: [[Relational_Data_-_Functions_-_Tuple_Functions#tupledividebynumber|tupleDivideByNumber]].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;a % b&amp;lt;/code&amp;gt; – The &amp;lt;code&amp;gt;modulo(a, b)&amp;lt;/code&amp;gt; function.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;addition-and-subtraction-operators&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
== Addition and Subtraction Operators ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;a + b&amp;lt;/code&amp;gt; – The &amp;lt;code&amp;gt;plus(a, b)&amp;lt;/code&amp;gt; function.&lt;br /&gt;
&lt;br /&gt;
For tuple addiction: [[Relational_Data_-_Functions_-_Tuple_Functions#tupleplus|tuplePlus]].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;a - b&amp;lt;/code&amp;gt; – The &amp;lt;code&amp;gt;minus(a, b)&amp;lt;/code&amp;gt; function.&lt;br /&gt;
&lt;br /&gt;
For tuple subtraction: [[Relational_Data_-_Functions_-_Tuple_Functions#tupleminus|tupleMinus]].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;comparison-operators&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
== Comparison Operators ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;equals-function&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
=== equals function ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;a = b&amp;lt;/code&amp;gt; – The &amp;lt;code&amp;gt;equals(a, b)&amp;lt;/code&amp;gt; function.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;a == b&amp;lt;/code&amp;gt; – The &amp;lt;code&amp;gt;equals(a, b)&amp;lt;/code&amp;gt; function.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;notequals-function&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
=== notEquals function ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;a != b&amp;lt;/code&amp;gt; – The &amp;lt;code&amp;gt;notEquals(a, b)&amp;lt;/code&amp;gt; function.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;a &amp;amp;lt;&amp;amp;gt; b&amp;lt;/code&amp;gt; – The &amp;lt;code&amp;gt;notEquals(a, b)&amp;lt;/code&amp;gt; function.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;lessorequals-function&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
=== lessOrEquals function ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;a &amp;amp;lt;= b&amp;lt;/code&amp;gt; – The &amp;lt;code&amp;gt;lessOrEquals(a, b)&amp;lt;/code&amp;gt; function.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;greaterorequals-function&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
=== greaterOrEquals function ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;a &amp;amp;gt;= b&amp;lt;/code&amp;gt; – The &amp;lt;code&amp;gt;greaterOrEquals(a, b)&amp;lt;/code&amp;gt; function.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;less-function&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
=== less function ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;a &amp;amp;lt; b&amp;lt;/code&amp;gt; – The &amp;lt;code&amp;gt;less(a, b)&amp;lt;/code&amp;gt; function.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;greater-function&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
=== greater function ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;a &amp;amp;gt; b&amp;lt;/code&amp;gt; – The &amp;lt;code&amp;gt;greater(a, b)&amp;lt;/code&amp;gt; function.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;like-function&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
=== like function ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;a LIKE s&amp;lt;/code&amp;gt; – The &amp;lt;code&amp;gt;like(a, b)&amp;lt;/code&amp;gt; function.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;notlike-function&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
=== notLike function ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;a NOT LIKE s&amp;lt;/code&amp;gt; – The &amp;lt;code&amp;gt;notLike(a, b)&amp;lt;/code&amp;gt; function.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;ilike-function&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
=== ilike function ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;a ILIKE s&amp;lt;/code&amp;gt; – The &amp;lt;code&amp;gt;ilike(a, b)&amp;lt;/code&amp;gt; function.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;between-function&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
=== BETWEEN function ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;a BETWEEN b AND c&amp;lt;/code&amp;gt; – The same as &amp;lt;code&amp;gt;a &amp;amp;gt;= b AND a &amp;amp;lt;= c&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;a NOT BETWEEN b AND c&amp;lt;/code&amp;gt; – The same as &amp;lt;code&amp;gt;a &amp;amp;lt; b OR a &amp;amp;gt; c&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;operators-for-working-with-data-sets&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
== Operators for Working with Data Sets ==&lt;br /&gt;
&lt;br /&gt;
See [[Relational_Data_-_Operators_-_In|IN operators]] and [[Relational_Data_-_Operators_-_Exists|EXISTS]] operator.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;in-function&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
=== in function ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;a IN ...&amp;lt;/code&amp;gt; – The &amp;lt;code&amp;gt;in(a, b)&amp;lt;/code&amp;gt; function.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;notin-function&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
=== notIn function ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;a NOT IN ...&amp;lt;/code&amp;gt; – The &amp;lt;code&amp;gt;notIn(a, b)&amp;lt;/code&amp;gt; function.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;globalin-function&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
=== globalIn function ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;a GLOBAL IN ...&amp;lt;/code&amp;gt; – The &amp;lt;code&amp;gt;globalIn(a, b)&amp;lt;/code&amp;gt; function.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;globalnotin-function&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
=== globalNotIn function ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;a GLOBAL NOT IN ...&amp;lt;/code&amp;gt; – The &amp;lt;code&amp;gt;globalNotIn(a, b)&amp;lt;/code&amp;gt; function.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;in-subquery-function&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
=== in subquery function ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;a = ANY (subquery)&amp;lt;/code&amp;gt; – The &amp;lt;code&amp;gt;in(a, subquery)&amp;lt;/code&amp;gt; function.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;notin-subquery-function&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
=== notIn subquery function ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;a != ANY (subquery)&amp;lt;/code&amp;gt; – The same as &amp;lt;code&amp;gt;a NOT IN (SELECT singleValueOrNull(*) FROM subquery)&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;in-subquery-function-1&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
=== in subquery function ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;a = ALL (subquery)&amp;lt;/code&amp;gt; – The same as &amp;lt;code&amp;gt;a IN (SELECT singleValueOrNull(*) FROM subquery)&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;notin-subquery-function-1&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
=== notIn subquery function ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;a != ALL (subquery)&amp;lt;/code&amp;gt; – The &amp;lt;code&amp;gt;notIn(a, subquery)&amp;lt;/code&amp;gt; function.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Examples&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Query with ALL:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;SELECT number AS a FROM numbers(10) WHERE a &amp;gt; ALL (SELECT number FROM numbers(3, 3));&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Result:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;text&amp;quot;&amp;gt;┌─a─┐&lt;br /&gt;
│ 6 │&lt;br /&gt;
│ 7 │&lt;br /&gt;
│ 8 │&lt;br /&gt;
│ 9 │&lt;br /&gt;
└───┘&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Query with ANY:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;SELECT number AS a FROM numbers(10) WHERE a &amp;gt; ANY (SELECT number FROM numbers(3, 3));&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Result:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;text&amp;quot;&amp;gt;┌─a─┐&lt;br /&gt;
│ 4 │&lt;br /&gt;
│ 5 │&lt;br /&gt;
│ 6 │&lt;br /&gt;
│ 7 │&lt;br /&gt;
│ 8 │&lt;br /&gt;
│ 9 │&lt;br /&gt;
└───┘&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;span id=&amp;quot;operators-for-working-with-dates-and-times&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
== Operators for Working with Dates and Times ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;extract&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
=== EXTRACT ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;EXTRACT(part FROM date);&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Extract parts from a given date. For example, you can retrieve a month from a given date, or a second from a time.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;part&amp;lt;/code&amp;gt; parameter specifies which part of the date to retrieve. The following values are available:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;DAY&amp;lt;/code&amp;gt; — The day of the month. Possible values: 1–31.&lt;br /&gt;
* &amp;lt;code&amp;gt;MONTH&amp;lt;/code&amp;gt; — The number of a month. Possible values: 1–12.&lt;br /&gt;
* &amp;lt;code&amp;gt;YEAR&amp;lt;/code&amp;gt; — The year.&lt;br /&gt;
* &amp;lt;code&amp;gt;SECOND&amp;lt;/code&amp;gt; — The second. Possible values: 0–59.&lt;br /&gt;
* &amp;lt;code&amp;gt;MINUTE&amp;lt;/code&amp;gt; — The minute. Possible values: 0–59.&lt;br /&gt;
* &amp;lt;code&amp;gt;HOUR&amp;lt;/code&amp;gt; — The hour. Possible values: 0–23.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;part&amp;lt;/code&amp;gt; parameter is case-insensitive.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;date&amp;lt;/code&amp;gt; parameter specifies the date or the time to process. Either [[Relational_Data_-_Data_Types_-_Date|Date]] or [[Relational_Data_-_Data_Types_-_Datetime|DateTime]] type is supported.&lt;br /&gt;
&lt;br /&gt;
Examples:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;SELECT EXTRACT(DAY FROM toDate(&amp;#039;2017-06-15&amp;#039;));&lt;br /&gt;
SELECT EXTRACT(MONTH FROM toDate(&amp;#039;2017-06-15&amp;#039;));&lt;br /&gt;
SELECT EXTRACT(YEAR FROM toDate(&amp;#039;2017-06-15&amp;#039;));&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
In the following example we create a table and insert into it a value with the &amp;lt;code&amp;gt;DateTime&amp;lt;/code&amp;gt; type.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;CREATE TABLE test.Orders&lt;br /&gt;
(&lt;br /&gt;
    OrderId UInt64,&lt;br /&gt;
    OrderName String,&lt;br /&gt;
    OrderDate DateTime&lt;br /&gt;
)&lt;br /&gt;
ENGINE = Log;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;INSERT INTO test.Orders VALUES (1, &amp;#039;Jarlsberg Cheese&amp;#039;, toDateTime(&amp;#039;2008-10-11 13:23:44&amp;#039;));&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;SELECT&lt;br /&gt;
    toYear(OrderDate) AS OrderYear,&lt;br /&gt;
    toMonth(OrderDate) AS OrderMonth,&lt;br /&gt;
    toDayOfMonth(OrderDate) AS OrderDay,&lt;br /&gt;
    toHour(OrderDate) AS OrderHour,&lt;br /&gt;
    toMinute(OrderDate) AS OrderMinute,&lt;br /&gt;
    toSecond(OrderDate) AS OrderSecond&lt;br /&gt;
FROM test.Orders;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;text&amp;quot;&amp;gt;┌─OrderYear─┬─OrderMonth─┬─OrderDay─┬─OrderHour─┬─OrderMinute─┬─OrderSecond─┐&lt;br /&gt;
│      2008 │         10 │       11 │        13 │          23 │          44 │&lt;br /&gt;
└───────────┴────────────┴──────────┴───────────┴─────────────┴─────────────┘&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
You can see more examples in [https://github.com/ClickHouse/ClickHouse/blob/master/tests/queries/0_stateless/00619_extract.sql tests].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;interval&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
=== INTERVAL ===&lt;br /&gt;
&lt;br /&gt;
Creates an [https://clickhouse.com/docs/en/sql-reference/data-types/special-data-types/interval Interval]-type value that should be used in arithmetical operations with [[Relational_Data_-_Data_Types_-_Date|Date]] and [[Relational_Data_-_Data_Types_-_Datetime|DateTime]]-type values.&lt;br /&gt;
&lt;br /&gt;
Types of intervals: - &amp;lt;code&amp;gt;SECOND&amp;lt;/code&amp;gt; - &amp;lt;code&amp;gt;MINUTE&amp;lt;/code&amp;gt; - &amp;lt;code&amp;gt;HOUR&amp;lt;/code&amp;gt; - &amp;lt;code&amp;gt;DAY&amp;lt;/code&amp;gt; - &amp;lt;code&amp;gt;WEEK&amp;lt;/code&amp;gt; - &amp;lt;code&amp;gt;MONTH&amp;lt;/code&amp;gt; - &amp;lt;code&amp;gt;QUARTER&amp;lt;/code&amp;gt; - &amp;lt;code&amp;gt;YEAR&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can also use a string literal when setting the &amp;lt;code&amp;gt;INTERVAL&amp;lt;/code&amp;gt; value. For example, &amp;lt;code&amp;gt;INTERVAL 1 HOUR&amp;lt;/code&amp;gt; is identical to the &amp;lt;code&amp;gt;INTERVAL &amp;#039;1 hour&amp;#039;&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;INTERVAL &amp;#039;1&amp;#039; hour&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;tip&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Intervals with different types can’t be combined. You can’t use expressions like &amp;lt;code&amp;gt;INTERVAL 4 DAY 1 HOUR&amp;lt;/code&amp;gt;. Specify intervals in units that are smaller or equal to the smallest unit of the interval, for example, &amp;lt;code&amp;gt;INTERVAL 25 HOUR&amp;lt;/code&amp;gt;. You can use consecutive operations, like in the example below.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
Examples:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;SELECT now() AS current_date_time, current_date_time + INTERVAL 4 DAY + INTERVAL 3 HOUR;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;text&amp;quot;&amp;gt;┌───current_date_time─┬─plus(plus(now(), toIntervalDay(4)), toIntervalHour(3))─┐&lt;br /&gt;
│ 2020-11-03 22:09:50 │                                    2020-11-08 01:09:50 │&lt;br /&gt;
└─────────────────────┴────────────────────────────────────────────────────────┘&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;SELECT now() AS current_date_time, current_date_time + INTERVAL &amp;#039;4 day&amp;#039; + INTERVAL &amp;#039;3 hour&amp;#039;;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;text&amp;quot;&amp;gt;┌───current_date_time─┬─plus(plus(now(), toIntervalDay(4)), toIntervalHour(3))─┐&lt;br /&gt;
│ 2020-11-03 22:12:10 │                                    2020-11-08 01:12:10 │&lt;br /&gt;
└─────────────────────┴────────────────────────────────────────────────────────┘&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;SELECT now() AS current_date_time, current_date_time + INTERVAL &amp;#039;4&amp;#039; day + INTERVAL &amp;#039;3&amp;#039; hour;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;text&amp;quot;&amp;gt;┌───current_date_time─┬─plus(plus(now(), toIntervalDay(&amp;#039;4&amp;#039;)), toIntervalHour(&amp;#039;3&amp;#039;))─┐&lt;br /&gt;
│ 2020-11-03 22:33:19 │                                        2020-11-08 01:33:19 │&lt;br /&gt;
└─────────────────────┴────────────────────────────────────────────────────────────┘&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
You can work with dates without using &amp;lt;code&amp;gt;INTERVAL&amp;lt;/code&amp;gt;, just by adding or subtracting seconds, minutes, and hours. For example, an interval of one day can be set by adding &amp;lt;code&amp;gt;60*60*24&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;note&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;INTERVAL&amp;lt;/code&amp;gt; syntax or &amp;lt;code&amp;gt;addDays&amp;lt;/code&amp;gt; function are always preferred. Simple addition or subtraction (syntax like &amp;lt;code&amp;gt;now() + ...&amp;lt;/code&amp;gt;) doesn’t consider time settings. For example, daylight saving time.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
Examples:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;SELECT toDateTime(&amp;#039;2014-10-26 00:00:00&amp;#039;, &amp;#039;Asia/Istanbul&amp;#039;) AS time, time + 60 * 60 * 24 AS time_plus_24_hours, time + toIntervalDay(1) AS time_plus_1_day;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;text&amp;quot;&amp;gt;┌────────────────time─┬──time_plus_24_hours─┬─────time_plus_1_day─┐&lt;br /&gt;
│ 2014-10-26 00:00:00 │ 2014-10-26 23:00:00 │ 2014-10-27 00:00:00 │&lt;br /&gt;
└─────────────────────┴─────────────────────┴─────────────────────┘&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;See Also&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
* [https://clickhouse.com/docs/en/sql-reference/data-types/special-data-types/interval Interval] data type&lt;br /&gt;
* [[Relational_Data_-_Functions_-_Type_Conversion_Functions#function-tointerval|toInterval]] type conversion functions&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;logical-and-operator&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
== Logical AND Operator ==&lt;br /&gt;
&lt;br /&gt;
Syntax &amp;lt;code&amp;gt;SELECT a AND b&amp;lt;/code&amp;gt; — calculates logical conjunction of &amp;lt;code&amp;gt;a&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;b&amp;lt;/code&amp;gt; with the function [[Relational_Data_-_Functions_-_Logical_Functions#logical-and-function|and]].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;logical-or-operator&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
== Logical OR Operator ==&lt;br /&gt;
&lt;br /&gt;
Syntax &amp;lt;code&amp;gt;SELECT a OR b&amp;lt;/code&amp;gt; — calculates logical disjunction of &amp;lt;code&amp;gt;a&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;b&amp;lt;/code&amp;gt; with the function [[Relational_Data_-_Functions_-_Logical_Functions#logical-or-function|or]].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;logical-negation-operator&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
== Logical Negation Operator ==&lt;br /&gt;
&lt;br /&gt;
Syntax &amp;lt;code&amp;gt;SELECT NOT a&amp;lt;/code&amp;gt; — calculates logical negation of &amp;lt;code&amp;gt;a&amp;lt;/code&amp;gt; with the function [[Relational_Data_-_Functions_-_Logical_Functions#logical-not-function|not]].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;conditional-operator&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
== Conditional Operator ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;a ? b : c&amp;lt;/code&amp;gt; – The &amp;lt;code&amp;gt;if(a, b, c)&amp;lt;/code&amp;gt; function.&lt;br /&gt;
&lt;br /&gt;
Note:&lt;br /&gt;
&lt;br /&gt;
The conditional operator calculates the values of b and c, then checks whether condition a is met, and then returns the corresponding value. If &amp;lt;code&amp;gt;b&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;C&amp;lt;/code&amp;gt; is an [[Relational_Data_-_Functions_-_Array_Join#functions_arrayjoin|arrayJoin()]] function, each row will be replicated regardless of the “a” condition.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;conditional-expression&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
== Conditional Expression ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;CASE [x]&lt;br /&gt;
    WHEN a THEN b&lt;br /&gt;
    [WHEN ... THEN ...]&lt;br /&gt;
    [ELSE c]&lt;br /&gt;
END&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
If &amp;lt;code&amp;gt;x&amp;lt;/code&amp;gt; is specified, then &amp;lt;code&amp;gt;transform(x, [a, ...], [b, ...], c)&amp;lt;/code&amp;gt; function is used. Otherwise – &amp;lt;code&amp;gt;multiIf(a, b, ..., c)&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
If there is no &amp;lt;code&amp;gt;ELSE c&amp;lt;/code&amp;gt; clause in the expression, the default value is &amp;lt;code&amp;gt;NULL&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;transform&amp;lt;/code&amp;gt; function does not work with &amp;lt;code&amp;gt;NULL&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;concatenation-operator&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
== Concatenation Operator ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;s1 || s2&amp;lt;/code&amp;gt; – The &amp;lt;code&amp;gt;concat(s1, s2) function.&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;lambda-creation-operator&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
== Lambda Creation Operator ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;x -&amp;amp;gt; expr&amp;lt;/code&amp;gt; – The &amp;lt;code&amp;gt;lambda(x, expr) function.&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The following operators do not have a priority since they are brackets:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;array-creation-operator&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
== Array Creation Operator ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;[x1, ...]&amp;lt;/code&amp;gt; – The &amp;lt;code&amp;gt;array(x1, ...) function.&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;tuple-creation-operator&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
== Tuple Creation Operator ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;(x1, x2, ...)&amp;lt;/code&amp;gt; – The &amp;lt;code&amp;gt;tuple(x2, x2, ...) function.&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;associativity&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
== Associativity ==&lt;br /&gt;
&lt;br /&gt;
All binary operators have left associativity. For example, &amp;lt;code&amp;gt;1 + 2 + 3&amp;lt;/code&amp;gt; is transformed to &amp;lt;code&amp;gt;plus(plus(1, 2), 3)&amp;lt;/code&amp;gt;. Sometimes this does not work the way you expect. For example, &amp;lt;code&amp;gt;SELECT 4 &amp;amp;gt; 2 &amp;amp;gt; 3&amp;lt;/code&amp;gt; will result in 0.&lt;br /&gt;
&lt;br /&gt;
For efficiency, the &amp;lt;code&amp;gt;and&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;or&amp;lt;/code&amp;gt; functions accept any number of arguments. The corresponding chains of &amp;lt;code&amp;gt;AND&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;OR&amp;lt;/code&amp;gt; operators are transformed into a single call of these functions.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;checking-for-null&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
== Checking for &amp;lt;code&amp;gt;NULL&amp;lt;/code&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
ClickHouse supports the &amp;lt;code&amp;gt;IS NULL&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;IS NOT NULL&amp;lt;/code&amp;gt; operators.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;is_null&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
=== IS NULL ===&lt;br /&gt;
&lt;br /&gt;
* For [[Relational_Data_-_Data_Types_-_Nullable|Nullable]] type values, the &amp;lt;code&amp;gt;IS NULL&amp;lt;/code&amp;gt; operator returns:&lt;br /&gt;
** &amp;lt;code&amp;gt;1&amp;lt;/code&amp;gt;, if the value is &amp;lt;code&amp;gt;NULL&amp;lt;/code&amp;gt;.&lt;br /&gt;
** &amp;lt;code&amp;gt;0&amp;lt;/code&amp;gt; otherwise.&lt;br /&gt;
* For other values, the &amp;lt;code&amp;gt;IS NULL&amp;lt;/code&amp;gt; operator always returns &amp;lt;code&amp;gt;0&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Can be optimized by enabling the [https://clickhouse.com/docs/en/operations/settings/settings#optimize-functions-to-subcolumns optimize_functions_to_subcolumns] setting. With &amp;lt;code&amp;gt;optimize_functions_to_subcolumns = 1&amp;lt;/code&amp;gt; the function reads only [[Relational_Data_-_Data_Types_-_Nullable#finding-null|null]] subcolumn instead of reading and processing the whole column data. The query &amp;lt;code&amp;gt;SELECT n IS NULL FROM table&amp;lt;/code&amp;gt; transforms to &amp;lt;code&amp;gt;SELECT n.null FROM TABLE&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- --&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;SELECT x+100 FROM t_null WHERE y IS NULL&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;text&amp;quot;&amp;gt;┌─plus(x, 100)─┐&lt;br /&gt;
│          101 │&lt;br /&gt;
└──────────────┘&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;span id=&amp;quot;is_not_null&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
=== IS NOT NULL ===&lt;br /&gt;
&lt;br /&gt;
* For [[Relational_Data_-_Data_Types_-_Nullable|Nullable]] type values, the &amp;lt;code&amp;gt;IS NOT NULL&amp;lt;/code&amp;gt; operator returns:&lt;br /&gt;
** &amp;lt;code&amp;gt;0&amp;lt;/code&amp;gt;, if the value is &amp;lt;code&amp;gt;NULL&amp;lt;/code&amp;gt;.&lt;br /&gt;
** &amp;lt;code&amp;gt;1&amp;lt;/code&amp;gt; otherwise.&lt;br /&gt;
* For other values, the &amp;lt;code&amp;gt;IS NOT NULL&amp;lt;/code&amp;gt; operator always returns &amp;lt;code&amp;gt;1&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- --&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;SELECT * FROM t_null WHERE y IS NOT NULL&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;text&amp;quot;&amp;gt;┌─x─┬─y─┐&lt;br /&gt;
│ 2 │ 3 │&lt;br /&gt;
└───┴───┘&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Can be optimized by enabling the [https://clickhouse.com/docs/en/operations/settings/settings#optimize-functions-to-subcolumns optimize_functions_to_subcolumns] setting. With &amp;lt;code&amp;gt;optimize_functions_to_subcolumns = 1&amp;lt;/code&amp;gt; the function reads only [[Relational_Data_-_Data_Types_-_Nullable#finding-null|null]] subcolumn instead of reading and processing the whole column data. The query &amp;lt;code&amp;gt;SELECT n IS NOT NULL FROM table&amp;lt;/code&amp;gt; transforms to &amp;lt;code&amp;gt;SELECT NOT n.null FROM TABLE&amp;lt;/code&amp;gt;.&lt;br /&gt;
[[Category:Relational_Data]]&lt;/div&gt;</summary>
		<author><name>Chris.Hansen</name></author>
	</entry>
</feed>