Skip to content

Commit

Permalink
IS [NOT] DISTINCT FROM
Browse files Browse the repository at this point in the history
  • Loading branch information
deobald committed Jan 24, 2024
1 parent 1af4b8b commit 972285b
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 10 deletions.
13 changes: 10 additions & 3 deletions docs/print.html
Original file line number Diff line number Diff line change
Expand Up @@ -987,10 +987,13 @@ <h2 id="between"><a class="header" href="#between">BETWEEN</a></h2>
</code></pre>
<p>NOTE: <code>BETWEEN</code> can also be used with <a href="sql/time_queries.html#between">System Time</a>.</p>
<h2 id="boolean-operators"><a class="header" href="#boolean-operators">Boolean Operators</a></h2>
<p><code>WHERE</code> clauses can be modified and combined with standard SQL boolean operators:</p>
<p><code>WHERE</code> and <code>HAVING</code> clauses can be modified and combined with standard SQL boolean operators.</p>
<h3 id="is-is-not-is-not-distinct-from"><a class="header" href="#is-is-not-is-not-distinct-from">IS, IS NOT, IS [NOT] DISTINCT FROM</a></h3>
<p><code>IS</code> and <code>IS NOT</code> behave like <a href="sql/operators.html#comparison"><code>=</code> (<code>==</code>) and <code>&lt;&gt;</code> (<code>!=</code>)</a>, respectively.
They are usually used to augment equality checks to test for <code>NULL</code>,
which is the third boolean value, representing &quot;unknown&quot;.</p>
which is the third boolean value, representing &quot;unknown&quot;.
<code>IS DISTINCT FROM</code> is a synonym for <code>IS NOT</code>.
<code>IS NOT DISTINCT FROM</code> is a synonym for <code>IS</code>.</p>
<ul>
<li>When both sides of <code>IS</code> evaluate to <code>NULL</code> it returns <code>TRUE</code>.</li>
<li>When only one side of <code>IS NOT</code> evaluates to <code>NULL</code> it returns <code>TRUE</code>,</li>
Expand All @@ -999,8 +1002,12 @@ <h2 id="boolean-operators"><a class="header" href="#boolean-operators">Boolean O
</ul>
<pre><code class="language-sql">SELECT * FROM products WHERE product_no IS NULL;
SELECT * FROM products WHERE product_no IS NOT NULL;
SELECT * FROM products WHERE product_no IS 379;
SELECT * FROM products WHERE product_no IS 386;
SELECT * FROM products WHERE product_no IS NOT 444;
</code></pre>
<p>NOTE: The <code>IS \[NOT\] DISTINCT FROM</code> form is provided for SQL specification
compatibility and is not recommended, as it tends to be verbose and confusing.</p>
<h3 id="not-and-or"><a class="header" href="#not-and-or">NOT, AND, OR</a></h3>
<p><code>NOT</code> can be prefixed to any clause to negate it:</p>
<pre><code class="language-sql">SELECT * FROM products WHERE NOT (name = 'Coffee');
</code></pre>
Expand Down
2 changes: 1 addition & 1 deletion docs/searchindex.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/searchindex.json

Large diffs are not rendered by default.

13 changes: 10 additions & 3 deletions docs/sql/operators.html
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,13 @@ <h2 id="between"><a class="header" href="#between">BETWEEN</a></h2>
</code></pre>
<p>NOTE: <code>BETWEEN</code> can also be used with <a href="time_queries.html#between">System Time</a>.</p>
<h2 id="boolean-operators"><a class="header" href="#boolean-operators">Boolean Operators</a></h2>
<p><code>WHERE</code> clauses can be modified and combined with standard SQL boolean operators:</p>
<p><code>WHERE</code> and <code>HAVING</code> clauses can be modified and combined with standard SQL boolean operators.</p>
<h3 id="is-is-not-is-not-distinct-from"><a class="header" href="#is-is-not-is-not-distinct-from">IS, IS NOT, IS [NOT] DISTINCT FROM</a></h3>
<p><code>IS</code> and <code>IS NOT</code> behave like <a href="operators.html#comparison"><code>=</code> (<code>==</code>) and <code>&lt;&gt;</code> (<code>!=</code>)</a>, respectively.
They are usually used to augment equality checks to test for <code>NULL</code>,
which is the third boolean value, representing &quot;unknown&quot;.</p>
which is the third boolean value, representing &quot;unknown&quot;.
<code>IS DISTINCT FROM</code> is a synonym for <code>IS NOT</code>.
<code>IS NOT DISTINCT FROM</code> is a synonym for <code>IS</code>.</p>
<ul>
<li>When both sides of <code>IS</code> evaluate to <code>NULL</code> it returns <code>TRUE</code>.</li>
<li>When only one side of <code>IS NOT</code> evaluates to <code>NULL</code> it returns <code>TRUE</code>,</li>
Expand All @@ -209,8 +212,12 @@ <h2 id="boolean-operators"><a class="header" href="#boolean-operators">Boolean O
</ul>
<pre><code class="language-sql">SELECT * FROM products WHERE product_no IS NULL;
SELECT * FROM products WHERE product_no IS NOT NULL;
SELECT * FROM products WHERE product_no IS 379;
SELECT * FROM products WHERE product_no IS 386;
SELECT * FROM products WHERE product_no IS NOT 444;
</code></pre>
<p>NOTE: The <code>IS \[NOT\] DISTINCT FROM</code> form is provided for SQL specification
compatibility and is not recommended, as it tends to be verbose and confusing.</p>
<h3 id="not-and-or"><a class="header" href="#not-and-or">NOT, AND, OR</a></h3>
<p><code>NOT</code> can be prefixed to any clause to negate it:</p>
<pre><code class="language-sql">SELECT * FROM products WHERE NOT (name = 'Coffee');
</code></pre>
Expand Down
14 changes: 12 additions & 2 deletions src/sql/operators.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,15 @@ NOTE: `BETWEEN` can also be used with [System Time](time_queries.md#between).

## Boolean Operators

`WHERE` clauses can be modified and combined with standard SQL boolean operators:
`WHERE` and `HAVING` clauses can be modified and combined with standard SQL boolean operators.

### IS, IS NOT, IS \[NOT\] DISTINCT FROM

`IS` and `IS NOT` behave like [`=` (`==`) and `<>` (`!=`)](operators.md#comparison), respectively.
They are usually used to augment equality checks to test for `NULL`,
which is the third boolean value, representing "unknown".
`IS DISTINCT FROM` is a synonym for `IS NOT`.
`IS NOT DISTINCT FROM` is a synonym for `IS`.

* When both sides of `IS` evaluate to `NULL` it returns `TRUE`.
* When only one side of `IS NOT` evaluates to `NULL` it returns `TRUE`,
Expand All @@ -47,9 +51,15 @@ which is the third boolean value, representing "unknown".
```sql
SELECT * FROM products WHERE product_no IS NULL;
SELECT * FROM products WHERE product_no IS NOT NULL;
SELECT * FROM products WHERE product_no IS 379;
SELECT * FROM products WHERE product_no IS 386;
SELECT * FROM products WHERE product_no IS NOT 444;
```

NOTE: The `IS \[NOT\] DISTINCT FROM` form is provided for SQL specification
compatibility and is not recommended, as it tends to be verbose and confusing.

### NOT, AND, OR

`NOT` can be prefixed to any clause to negate it:

```sql
Expand Down

0 comments on commit 972285b

Please sign in to comment.