Skip to content

Commit 09ac536

Browse files
authored
Merge pull request #184466 from timsander1/master
break apart operators doc
2 parents bf82733 + 3b4ea77 commit 09ac536

9 files changed

+184
-129
lines changed

.openpublishing.redirection.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34398,6 +34398,11 @@
3439834398
"redirect_url": "https://azure.microsoft.com/blog/dear-documentdb-customers-welcome-to-azure-cosmos-db/",
3439934399
"redirect_document_id": false
3440034400
},
34401+
{
34402+
"source_path_from_root": "/articles/documentdb/sql-query-operators.md",
34403+
"redirect_url": "sql-query-logical-operators",
34404+
"redirect_document_id": false
34405+
},
3440134406
{
3440234407
"source_path_from_root": "/articles/search/search-case-studies.md",
3440334408
"redirect_url": "https://azure.microsoft.com/case-studies",

articles/cosmos-db/TOC.yml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -282,12 +282,20 @@
282282
- name: Constants
283283
displayName: object, number,array
284284
href: sql/sql-query-constants.md
285-
- name: Operators
286-
displayName: operators, operator, logical operators, equality, comparison
287-
href: sql/sql-query-operators.md
288285
- name: Scalar expressions
289286
displayName: scalar expressions, scalar
290287
href: sql/sql-query-scalar-expressions.md
288+
- name: Operators
289+
items:
290+
- name: Equality and comparison operators
291+
displayName: equality, comparison, operators
292+
href: sql/sql-query-equality-comparison-operators.md
293+
- name: Logical operators
294+
displayName: logical, and, or, operators
295+
href: sql/sql-query-logical-operators.md
296+
- name: Ternary and coalesce operators
297+
displayName: ternary, coalesce, operators
298+
href: sql/sql-query-ternary-coalesce-operators.md
291299
- name: Functions
292300
items:
293301
- name: User-defined functions
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
---
2+
title: Equality and comparison operators in Azure Cosmos DB
3+
description: Learn about SQL equality and comparison operators supported by Azure Cosmos DB.
4+
author: timsander1
5+
ms.service: cosmos-db
6+
ms.subservice: cosmosdb-sql
7+
ms.topic: conceptual
8+
ms.date: 01/07/2022
9+
ms.author: tisande
10+
11+
---
12+
# Equality and comparison operators in Azure Cosmos DB
13+
[!INCLUDE[appliesto-sql-api](../includes/appliesto-sql-api.md)]
14+
15+
This article details the equality and comparison operators supported by Azure Cosmos DB.
16+
17+
## Understanding equality comparisons
18+
19+
The following table shows the result of equality comparisons in the SQL API between any two JSON types.
20+
21+
| **Op** | **Undefined** | **Null** | **Boolean** | **Number** | **String** | **Object** | **Array** |
22+
|---|---|---|---|---|---|---|---|
23+
| **Undefined** | Undefined | Undefined | Undefined | Undefined | Undefined | Undefined | Undefined |
24+
| **Null** | Undefined | **Ok** | Undefined | Undefined | Undefined | Undefined | Undefined |
25+
| **Boolean** | Undefined | Undefined | **Ok** | Undefined | Undefined | Undefined | Undefined |
26+
| **Number** | Undefined | Undefined | Undefined | **Ok** | Undefined | Undefined | Undefined |
27+
| **String** | Undefined | Undefined | Undefined | Undefined | **Ok** | Undefined | Undefined |
28+
| **Object** | Undefined | Undefined | Undefined | Undefined | Undefined | **Ok** | Undefined |
29+
| **Array** | Undefined | Undefined | Undefined | Undefined | Undefined | Undefined | **Ok** |
30+
31+
For comparison operators such as `>`, `>=`, `!=`, `<`, and `<=`, comparison across types or between two objects or arrays produces `Undefined`.
32+
33+
If the result of the scalar expression is `Undefined`, the item isn't included in the result, because `Undefined` doesn't equal `true`.
34+
35+
For example, the following query's comparison between a number and string value produces `Undefined`. Therefore, the filter does not include any results.
36+
37+
```sql
38+
SELECT *
39+
FROM c
40+
WHERE 7 = 'a'
41+
```
42+
43+
## Next steps
44+
45+
- [Azure Cosmos DB .NET samples](https://github.com/Azure/azure-cosmos-dotnet-v3)
46+
- [Keywords](sql-query-keywords.md)
47+
- [SELECT clause](sql-query-select.md)

articles/cosmos-db/sql/sql-query-linq-to-sql.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ The LINQ provider included with the SQL .NET SDK supports the following operator
9191
- **Array functions**: Supports translation from .NET `Concat`, `Contains`, and `Count` to the equivalent [built-in array functions](sql-query-array-functions.md).
9292
- **Geospatial Extension functions**: Supports translation from stub methods `Distance`, `IsValid`, `IsValidDetailed`, and `Within` to the equivalent [built-in geospatial functions](sql-query-geospatial-query.md).
9393
- **User-Defined Function Extension function**: Supports translation from the stub method [CosmosLinq.InvokeUserDefinedFunction](/dotnet/api/microsoft.azure.cosmos.linq.cosmoslinq.invokeuserdefinedfunction?view=azure-dotnet&preserve-view=true) to the corresponding [user-defined function](sql-query-udfs.md).
94-
- **Miscellaneous**: Supports translation of `Coalesce` and conditional [operators](sql-query-operators.md). Can translate `Contains` to String CONTAINS, ARRAY_CONTAINS, or IN, depending on context.
94+
- **Miscellaneous**: Supports translation of `Coalesce` and [conditional operators](sql-query-logical-operators.md). Can translate `Contains` to String CONTAINS, ARRAY_CONTAINS, or IN, depending on context.
9595

9696
## Examples
9797

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
---
2+
title: Logical operators in Azure Cosmos DB
3+
description: Learn about SQL logical operators supported by Azure Cosmos DB.
4+
author: timsander1
5+
ms.service: cosmos-db
6+
ms.subservice: cosmosdb-sql
7+
ms.topic: conceptual
8+
ms.date: 01/07/2022
9+
ms.author: tisande
10+
11+
---
12+
# Logical operators in Azure Cosmos DB
13+
[!INCLUDE[appliesto-sql-api](../includes/appliesto-sql-api.md)]
14+
15+
This article details the logical operators supported by Azure Cosmos DB.
16+
17+
## Understanding logical (AND, OR and NOT) operators
18+
19+
Logical operators operate on Boolean values. The following tables show the logical truth tables for these operators:
20+
21+
**OR operator**
22+
23+
Returns `true` when either of the conditions is `true`.
24+
25+
| | **True** | **False** | **Undefined** |
26+
| --- | --- | --- | --- |
27+
| **True** |True |True |True |
28+
| **False** |True |False |Undefined |
29+
| **Undefined** |True |Undefined |Undefined |
30+
31+
**AND operator**
32+
33+
Returns `true` when both expressions are `true`.
34+
35+
| | **True** | **False** | **Undefined** |
36+
| --- | --- | --- | --- |
37+
| **True** |True |False |Undefined |
38+
| **False** |False |False |False |
39+
| **Undefined** |Undefined |False |Undefined |
40+
41+
**NOT operator**
42+
43+
Reverses the value of any Boolean expression.
44+
45+
| | **NOT** |
46+
| --- | --- |
47+
| **True** |False |
48+
| **False** |True |
49+
| **Undefined** |Undefined |
50+
51+
**Operator Precedence**
52+
53+
The logical operators `OR`, `AND`, and `NOT` have the precedence level shown below:
54+
55+
| **Operator** | **Priority** |
56+
| --- | --- |
57+
| **NOT** |1 |
58+
| **AND** |2 |
59+
| **OR** |3 |
60+
61+
## * operator
62+
63+
The special operator * projects the entire item as is. When used, it must be the only projected field. A query like `SELECT * FROM Families f` is valid, but `SELECT VALUE * FROM Families f` and `SELECT *, f.id FROM Families f` are not valid.
64+
65+
## Next steps
66+
67+
- [Azure Cosmos DB .NET samples](https://github.com/Azure/azure-cosmos-dotnet-v3)
68+
- [Keywords](sql-query-keywords.md)
69+
- [SELECT clause](sql-query-select.md)

articles/cosmos-db/sql/sql-query-operators.md

Lines changed: 0 additions & 122 deletions
This file was deleted.

articles/cosmos-db/sql/sql-query-scalar-expressions.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,11 @@ The [SELECT clause](sql-query-select.md) supports scalar expressions. A scalar e
6464

6565
- `unary_operator <scalar_expression>`
6666

67-
Represents an operator that is applied to a single value. See [Operators](sql-query-operators.md) section for details.
67+
Represents an operator that is applied to a single value.
6868

6969
- `<scalar_expression> binary_operator <scalar_expression>`
7070

71-
Represents an operator that is applied to two values. See [Operators](sql-query-operators.md) section for details.
71+
Represents an operator that is applied to two values.
7272

7373
- `<scalar_function_expression>`
7474

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
---
2+
title: Ternary and coalesce operators in Azure Cosmos DB
3+
description: Learn about SQL ternary and coalesce operators supported by Azure Cosmos DB.
4+
author: timsander1
5+
ms.service: cosmos-db
6+
ms.subservice: cosmosdb-sql
7+
ms.topic: conceptual
8+
ms.date: 01/07/2022
9+
ms.author: tisande
10+
11+
---
12+
# Ternary and coalesce operators in Azure Cosmos DB
13+
[!INCLUDE[appliesto-sql-api](../includes/appliesto-sql-api.md)]
14+
15+
This article details the ternary and coalesce operators supported by Azure Cosmos DB.
16+
17+
## Understanding ternary and coalesce operators
18+
19+
You can use the Ternary (?) and Coalesce (??) operators to build conditional expressions, as in programming languages like C# and JavaScript.
20+
21+
You can use the ? operator to construct new JSON properties on the fly. For example, the following query classifies grade levels into `elementary` or `other`:
22+
23+
```sql
24+
SELECT (c.grade < 5)? "elementary": "other" AS gradeLevel
25+
FROM Families.children[0] c
26+
```
27+
28+
You can also nest calls to the ? operator, as in the following query:
29+
30+
```sql
31+
SELECT (c.grade < 5)? "elementary": ((c.grade < 9)? "junior": "high") AS gradeLevel
32+
FROM Families.children[0] c
33+
```
34+
35+
As with other query operators, the ? operator excludes items if the referenced properties are missing or the types being compared are different.
36+
37+
Use the ?? operator to efficiently check for a property in an item when querying against semi-structured or mixed-type data. For example, the following query returns `lastName` if present, or `surname` if `lastName` isn't present.
38+
39+
```sql
40+
SELECT f.lastName ?? f.surname AS familyName
41+
FROM Families f
42+
```
43+
44+
## Next steps
45+
46+
- [Azure Cosmos DB .NET samples](https://github.com/Azure/azure-cosmos-dotnet-v3)
47+
- [Keywords](sql-query-keywords.md)
48+
- [SELECT clause](sql-query-select.md)

articles/cosmos-db/sql/sql-query-working-with-json.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ Azure Cosmos DB supports two helpful type checking system functions for `null` a
162162
* [IS_NULL](sql-query-is-null.md) - checks if a property value is `null`
163163
* [IS_DEFINED](sql-query-is-defined.md) - checks if a property value is defined
164164

165-
You can learn about [supported operators](sql-query-operators.md) and their behavior for `null` and `undefined` values.
165+
You can learn about [supported operators](sql-query-equality-comparison-operators.md) and their behavior for `null` and `undefined` values.
166166

167167
## Reserved keywords and special characters in JSON
168168

0 commit comments

Comments
 (0)