Skip to content

Commit bd287a1

Browse files
authored
Merge pull request #116409 from timsander1/master
add string equals system function
2 parents 02878e3 + fde8aa8 commit bd287a1

File tree

6 files changed

+129
-16
lines changed

6 files changed

+129
-16
lines changed

articles/cosmos-db/TOC.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,9 @@
373373
- name: STARTSWITH
374374
displayName: STARTSWITH, starts with, built-in functions
375375
href: sql-query-startswith.md
376+
- name: STRINGEQUALS
377+
displayName: STRINGEQUALS, equals, case-insensitive
378+
href: sql-query-stringequals.md
376379
- name: StringToArray
377380
displayName: StringToArray, string to array, built-in functions
378381
href: sql-query-stringtoarray.md

articles/cosmos-db/index-overview.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
---
22
title: Indexing in Azure Cosmos DB
33
description: Understand how indexing works in Azure Cosmos DB, different kinds of indexes such as Range, Spatial, composite indexes supported.
4-
author: ThomasWeiss
4+
author: timsander1
55
ms.service: cosmos-db
66
ms.topic: conceptual
7-
ms.date: 04/13/2020
8-
ms.author: thweiss
7+
ms.date: 05/21/2020
8+
ms.author: tisande
99
---
1010

1111
# Indexing in Azure Cosmos DB - Overview
@@ -100,7 +100,7 @@ Azure Cosmos DB currently supports three kinds of indexes.
100100
```
101101

102102
```sql
103-
SELECT * FROM c WHERE STARTSWITH(c.property, "value")
103+
SELECT * FROM c WHERE STRINGEQUALS(c.property, "value")
104104
```
105105

106106
- `ORDER BY` queries:

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

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: CONTAINS in Azure Cosmos DB query language
2+
title: Contains in Azure Cosmos DB query language
33
description: Learn about how the CONTAINS SQL system function in Azure Cosmos DB returns a Boolean indicating whether the first string expression contains the second
44
author: ginamr
55
ms.service: cosmos-db
@@ -35,22 +35,42 @@ CONTAINS(<str_expr1>, <str_expr2> [, <bool_expr>])
3535

3636
## Examples
3737

38-
The following example checks if "abc" contains "ab" and if "abc" contains "d".
38+
The following example checks if "abc" contains "ab" and if "abc" contains "A".
3939

4040
```sql
41-
SELECT CONTAINS("abc", "ab") AS c1, CONTAINS("abc", "d") AS c2
41+
SELECT CONTAINS("abc", "ab", false) AS c1, CONTAINS("abc", "A", false) AS c2, CONTAINS("abc", "A", true) AS c3
4242
```
4343

4444
Here is the result set.
4545

4646
```json
47-
[{"c1": true, "c2": false}]
47+
[
48+
{
49+
"c1": true,
50+
"c2": false,
51+
"c3": true
52+
}
53+
]
4854
```
4955

5056
## Remarks
5157

5258
This system function will benefit from a [range index](index-policy.md#includeexclude-strategy).
5359

60+
The RU consumption of Contains will increase as the cardinality of the property in the system function increases. In other words, if you are checking whether a property value contains a certain string, the query RU charge will depend on the number of possible values for that property.
61+
62+
For example, consider two properties: town and country. The cardinality of town is 5,000 and the cardinality of country is 200. Here are two example queries:
63+
64+
```sql
65+
SELECT * FROM c WHERE CONTAINS(c.town, "Red", false)
66+
```
67+
68+
```sql
69+
SELECT * FROM c WHERE CONTAINS(c.country, "States", false)
70+
```
71+
72+
The first query will likely use more RUs than the second query because the cardinality of town is higher than country.
73+
5474
## Next steps
5575

5676
- [String functions Azure Cosmos DB](sql-query-string-functions.md)

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

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: ENDSWITH in Azure Cosmos DB query language
2+
title: EndsWith in Azure Cosmos DB query language
33
description: Learn about the ENDSWITH SQL system function in Azure Cosmos DB to return a Boolean indicating whether the first string expression ends with the second
44
author: ginamr
55
ms.service: cosmos-db
@@ -35,22 +35,42 @@ ENDSWITH(<str_expr1>, <str_expr2> [, <bool_expr>])
3535

3636
## Examples
3737

38-
The following example returns the "abc" ends with "b" and "bc".
38+
The following example checks if the string "abc" ends with "b" and "bC".
3939

4040
```sql
41-
SELECT ENDSWITH("abc", "b") AS e1, ENDSWITH("abc", "bc") AS e2
41+
SELECT ENDSWITH("abc", "b", false) AS e1, ENDSWITH("abc", "bC", false) AS e2, ENDSWITH("abc", "bC", true) AS e3
4242
```
4343

4444
Here is the result set.
4545

4646
```json
47-
[{"e1": false, "e2": true}]
47+
[
48+
{
49+
"e1": false,
50+
"e2": false,
51+
"e3": true
52+
}
53+
]
4854
```
4955

5056
## Remarks
5157

5258
This system function will benefit from a [range index](index-policy.md#includeexclude-strategy).
5359

60+
The RU consumption of EndsWith will increase as the cardinality of the property in the system function increases. In other words, if you are checking whether a property value ends with a certain string, the query RU charge will depend on the number of possible values for that property.
61+
62+
For example, consider two properties: town and country. The cardinality of town is 5,000 and the cardinality of country is 200. Here are two example queries:
63+
64+
```sql
65+
SELECT * FROM c WHERE ENDSWITH(c.town, "York", false)
66+
```
67+
68+
```sql
69+
SELECT * FROM c WHERE ENDSWITH(c.country, "States", false)
70+
```
71+
72+
The first query will likely use more RUs than the second query because the cardinality of town is higher than country.
73+
5474
## Next steps
5575

5676
- [String functions Azure Cosmos DB](sql-query-string-functions.md)

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: STARTSWITH in Azure Cosmos DB query language
2+
title: StartsWith in Azure Cosmos DB query language
33
description: Learn about SQL system function STARTSWITH in Azure Cosmos DB.
44
author: ginamr
55
ms.service: cosmos-db
@@ -35,16 +35,22 @@ STARTSWITH(<str_expr1>, <str_expr2> [, <bool_expr>])
3535

3636
## Examples
3737

38-
The following example checks if the string "abc" begins with "b" and "a".
38+
The following example checks if the string "abc" begins with "b" and "A".
3939

4040
```sql
41-
SELECT STARTSWITH("abc", "b") AS s1, STARTSWITH("abc", "a") AS s2
41+
SELECT STARTSWITH("abc", "b", false) AS s1, STARTSWITH("abc", "A", false) AS s2, STARTSWITH("abc", "A", true) AS s3
4242
```
4343

4444
Here is the result set.
4545

4646
```json
47-
[{"s1": false, "s2": true}]
47+
[
48+
{
49+
"s1": false,
50+
"s2": false,
51+
"s3": true
52+
}
53+
]
4854
```
4955

5056
## Remarks
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
---
2+
title: StringEquals in Azure Cosmos DB query language
3+
description: Learn about how the StringEquals SQL system function in Azure Cosmos DB returns a Boolean indicating whether the first string expression matches the second
4+
author: timsander1
5+
ms.service: cosmos-db
6+
ms.topic: conceptual
7+
ms.date: 05/20/2020
8+
ms.author: tisande
9+
ms.custom: query-reference
10+
---
11+
# STRINGEQUALS (Azure Cosmos DB)
12+
13+
Returns a Boolean indicating whether the first string expression matches the second.
14+
15+
## Syntax
16+
17+
```sql
18+
STRINGEQUALS(<str_expr1>, <str_expr2> [, <bool_expr>])
19+
```
20+
21+
## Arguments
22+
23+
*str_expr1*
24+
Is the first string expression to compare.
25+
26+
*str_expr2*
27+
Is the second string expression to compare.
28+
29+
*bool_expr*
30+
Optional value for ignoring case. When set to true, StringEquals will do a case-insensitive search. When unspecified, this value is false.
31+
32+
## Return types
33+
34+
Returns a Boolean expression.
35+
36+
## Examples
37+
38+
The following example checks if "abc" matches "abc" and if "abc" matches "ABC".
39+
40+
```sql
41+
SELECT STRINGEQUALS("abc", "abc", false) AS c1, STRINGEQUALS("abc", "ABC", false) AS c2, STRINGEQUALS("abc", "ABC", true) AS c3
42+
```
43+
44+
Here is the result set.
45+
46+
```json
47+
[
48+
{
49+
"c1": true,
50+
"c2": false,
51+
"c3": true
52+
}
53+
]
54+
```
55+
56+
## Remarks
57+
58+
This system function will benefit from a [range index](index-policy.md#includeexclude-strategy).
59+
60+
## Next steps
61+
62+
- [String functions Azure Cosmos DB](sql-query-string-functions.md)
63+
- [System functions Azure Cosmos DB](sql-query-system-functions.md)
64+
- [Introduction to Azure Cosmos DB](introduction.md)

0 commit comments

Comments
 (0)