Skip to content

Commit

Permalink
Added documentation for the Spaceship Operator (<=>) (#14214)
Browse files Browse the repository at this point in the history
* Added documentation for the Spaceship Operator (<=>)

* Fix Prettier formatting issues

* Added Spaceship Operator (<=>) to the list of Comparision Operators

* Update docs/source/user-guide/sql/operators.md

Co-authored-by: Oleks V <[email protected]>

* Update docs/source/user-guide/sql/operators.md

Co-authored-by: Oleks V <[email protected]>

---------

Co-authored-by: Oleks V <[email protected]>
  • Loading branch information
Spaarsh and comphead authored Jan 21, 2025
1 parent 2f28327 commit 2aff98e
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions docs/source/user-guide/sql/operators.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ Modulo (remainder)
- [<= (less than or equal to)](#op_le)
- [> (greater than)](#op_gt)
- [>= (greater than or equal to)](#op_ge)
- [<=> (three-way comparison, alias for IS NOT DISTINCT FROM)](#op_spaceship)
- [IS DISTINCT FROM](#is-distinct-from)
- [IS NOT DISTINCT FROM](#is-not-distinct-from)
- [~ (regex match)](#op_re_match)
Expand Down Expand Up @@ -207,6 +208,48 @@ Greater Than or Equal To
+----------------------+
```

(op_spaceship)=

### `<=>`

Three-way comparison operator. A NULL-safe operator that returns true if both operands are equal or both are NULL, false otherwise.

```sql
> SELECT NULL <=> NULL;
+--------------------------------+
| NULL IS NOT DISTINCT FROM NULL |
+--------------------------------+
| true |
+--------------------------------+
```

```sql
> SELECT 1 <=> NULL;
+------------------------------------+
| Int64(1) IS NOT DISTINCT FROM NULL |
+------------------------------------+
| false |
+------------------------------------+
```

```sql
> SELECT 1 <=> 2;
+----------------------------------------+
| Int64(1) IS NOT DISTINCT FROM Int64(2) |
+----------------------------------------+
| false |
+----------------------------------------+
```

```sql
> SELECT 1 <=> 1;
+----------------------------------------+
| Int64(1) IS NOT DISTINCT FROM Int64(1) |
+----------------------------------------+
| true |
+----------------------------------------+
```

### `IS DISTINCT FROM`

Guarantees the result of a comparison is `true` or `false` and not an empty set
Expand Down

0 comments on commit 2aff98e

Please sign in to comment.