From 2aff98e002ce6d48008b8bbe2b38ee644a6d5c20 Mon Sep 17 00:00:00 2001 From: Spaarsh <67336892+Spaarsh@users.noreply.github.com> Date: Tue, 21 Jan 2025 22:23:51 +0530 Subject: [PATCH] Added documentation for the Spaceship Operator (<=>) (#14214) * 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 * Update docs/source/user-guide/sql/operators.md Co-authored-by: Oleks V --------- Co-authored-by: Oleks V --- docs/source/user-guide/sql/operators.md | 43 +++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/docs/source/user-guide/sql/operators.md b/docs/source/user-guide/sql/operators.md index b0263ebe989a..51f1a26d0b61 100644 --- a/docs/source/user-guide/sql/operators.md +++ b/docs/source/user-guide/sql/operators.md @@ -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) @@ -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