Skip to content

Commit 76d467c

Browse files
authored
Merge pull request #115867 from timsander1/master
add case insensitive system functions
2 parents 990e222 + de1cc4c commit 76d467c

File tree

5 files changed

+29
-13
lines changed

5 files changed

+29
-13
lines changed

articles/cosmos-db/index-overview.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,11 @@ Azure Cosmos DB currently supports three kinds of indexes.
9393
SELECT * FROM c WHERE IS_DEFINED(c.property)
9494
```
9595

96-
- String prefix matches (CONTAINS keyword will not leverage the range index):
96+
- String system functions:
97+
98+
```sql
99+
SELECT * FROM c WHERE CONTAINS(c.property, "value")
100+
```
97101

98102
```sql
99103
SELECT * FROM c WHERE STARTSWITH(c.property, "value")

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,18 @@ description: Learn about how the CONTAINS SQL system function in Azure Cosmos DB
44
author: ginamr
55
ms.service: cosmos-db
66
ms.topic: conceptual
7-
ms.date: 03/03/2020
7+
ms.date: 05/20/2020
88
ms.author: girobins
99
ms.custom: query-reference
1010
---
1111
# CONTAINS (Azure Cosmos DB)
12+
1213
Returns a Boolean indicating whether the first string expression contains the second.
1314

1415
## Syntax
1516

1617
```sql
17-
CONTAINS(<str_expr1>, <str_expr2>)
18+
CONTAINS(<str_expr1>, <str_expr2> [, <bool_expr>])
1819
```
1920

2021
## Arguments
@@ -24,6 +25,9 @@ CONTAINS(<str_expr1>, <str_expr2>)
2425

2526
*str_expr2*
2627
Is the string expression to find.
28+
29+
*bool_expr*
30+
Optional value for ignoring case. When set to true, CONTAINS will do a case-insensitive search. When unspecified, this value is false.
2731

2832
## Return types
2933

@@ -34,7 +38,7 @@ CONTAINS(<str_expr1>, <str_expr2>)
3438
The following example checks if "abc" contains "ab" and if "abc" contains "d".
3539

3640
```sql
37-
SELECT CONTAINS("abc", "ab") AS c1, CONTAINS("abc", "d") AS c2
41+
SELECT CONTAINS("abc", "ab") AS c1, CONTAINS("abc", "d") AS c2
3842
```
3943

4044
Here is the result set.
@@ -45,7 +49,7 @@ SELECT CONTAINS("abc", "ab") AS c1, CONTAINS("abc", "d") AS c2
4549

4650
## Remarks
4751

48-
This system function will not utilize the index.
52+
This system function will benefit from a [range index](index-policy.md#includeexclude-strategy).
4953

5054
## Next steps
5155

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,18 @@ description: Learn about the ENDSWITH SQL system function in Azure Cosmos DB to
44
author: ginamr
55
ms.service: cosmos-db
66
ms.topic: conceptual
7-
ms.date: 03/03/2020
7+
ms.date: 05/20/2020
88
ms.author: girobins
99
ms.custom: query-reference
1010
---
1111
# ENDSWITH (Azure Cosmos DB)
12+
1213
Returns a Boolean indicating whether the first string expression ends with the second.
1314

1415
## Syntax
1516

1617
```sql
17-
ENDSWITH(<str_expr1>, <str_expr2>)
18+
ENDSWITH(<str_expr1>, <str_expr2> [, <bool_expr>])
1819
```
1920

2021
## Arguments
@@ -23,7 +24,10 @@ ENDSWITH(<str_expr1>, <str_expr2>)
2324
Is a string expression.
2425

2526
*str_expr2*
26-
Is a string expression to be compared to the end of *str_expr1*.
27+
Is a string expression to be compared to the end of *str_expr1*.
28+
29+
*bool_expr*
30+
Optional value for ignoring case. When set to true, ENDSWITH will do a case-insensitive search. When unspecified, this value is false.
2731

2832
## Return types
2933

@@ -45,7 +49,7 @@ SELECT ENDSWITH("abc", "b") AS e1, ENDSWITH("abc", "bc") AS e2
4549

4650
## Remarks
4751

48-
This system function will not utilize the index.
52+
This system function will benefit from a [range index](index-policy.md#includeexclude-strategy).
4953

5054
## Next steps
5155

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,18 @@ description: Learn about SQL system function STARTSWITH in Azure Cosmos DB.
44
author: ginamr
55
ms.service: cosmos-db
66
ms.topic: conceptual
7-
ms.date: 09/13/2019
7+
ms.date: 05/20/2020
88
ms.author: girobins
99
ms.custom: query-reference
1010
---
1111
# STARTSWITH (Azure Cosmos DB)
12+
1213
Returns a Boolean indicating whether the first string expression starts with the second.
1314

1415
## Syntax
1516

1617
```sql
17-
STARTSWITH(<str_expr1>, <str_expr2>)
18+
STARTSWITH(<str_expr1>, <str_expr2> [, <bool_expr>])
1819
```
1920

2021
## Arguments
@@ -25,6 +26,9 @@ STARTSWITH(<str_expr1>, <str_expr2>)
2526
*str_expr2*
2627
Is a string expression to be compared to the beginning of *str_expr1*.
2728

29+
*bool_expr*
30+
Optional value for ignoring case. When set to true, STARTSWITH will do a case-insensitive search. When unspecified, this value is false.
31+
2832
## Return types
2933

3034
Returns a Boolean expression.

articles/cosmos-db/troubleshoot-query-performance.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,15 +194,15 @@ If an expression can be translated into a range of string values, it can use the
194194

195195
Here's the list of some common string functions that can use the index:
196196

197-
- STARTSWITH(str_expr, str_expr)
197+
- STARTSWITH(str_expr1, str_expr2, bool_expr)
198+
- CONTAINS(str_expr, str_expr, bool_expr)
198199
- LEFT(str_expr, num_expr) = str_expr
199200
- SUBSTRING(str_expr, num_expr, num_expr) = str_expr, but only if the first num_expr is 0
200201

201202
Following are some common system functions that don't use the index and must load each document:
202203

203204
| **System function** | **Ideas for optimization** |
204205
| --------------------------------------- |------------------------------------------------------------ |
205-
| CONTAINS | Use Azure Search for full-text search. |
206206
| UPPER/LOWER | Instead of using the system function to normalize data for comparisons, normalize the casing upon insertion. A query like ```SELECT * FROM c WHERE UPPER(c.name) = 'BOB'``` becomes ```SELECT * FROM c WHERE c.name = 'BOB'```. |
207207
| Mathematical functions (non-aggregates) | If you need to compute a value frequently in your query, consider storing the value as a property in your JSON document. |
208208

0 commit comments

Comments
 (0)