Skip to content

Commit f99b5eb

Browse files
authored
Merge pull request #246066 from seesharprun/cosmos-populate-nosql-9
Cosmos DB | Add NoSQL query functions #11
2 parents 6970f99 + 77f1779 commit f99b5eb

File tree

5 files changed

+166
-364
lines changed

5 files changed

+166
-364
lines changed
Lines changed: 36 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,95 +1,58 @@
11
---
2-
title: StringToArray in Azure Cosmos DB query language
3-
description: Learn about SQL system function StringToArray in Azure Cosmos DB.
4-
author: ginamr
2+
title: StringToArray
3+
titleSuffix: Azure Cosmos DB for NoSQL
4+
description: An Azure Cosmos DB for NoSQL system function that returns a string expression converted to an array.
5+
author: jcodella
6+
ms.author: jacodel
7+
ms.reviewer: sidandrews
58
ms.service: cosmos-db
69
ms.subservice: nosql
7-
ms.topic: conceptual
8-
ms.date: 03/03/2020
9-
ms.author: girobins
10-
ms.custom: query-reference, ignite-2022
10+
ms.topic: reference
11+
ms.date: 07/24/2023
12+
ms.custom: query-reference
1113
---
12-
# StringToArray (Azure Cosmos DB)
14+
15+
# StringToArray (NoSQL query)
16+
1317
[!INCLUDE[NoSQL](../../includes/appliesto-nosql.md)]
1418

15-
Returns expression translated to an Array. If expression can't be translated, returns undefined.
16-
19+
Converts a string expression to an array.
20+
1721
## Syntax
18-
22+
1923
```sql
20-
StringToArray(<str_expr>)
21-
```
22-
23-
## Arguments
24-
25-
*str_expr*
26-
Is a string expression to be parsed as a JSON Array expression.
27-
28-
## Return types
29-
30-
Returns an array expression or undefined.
31-
32-
## Remarks
33-
Nested string values must be written with double quotes to be valid JSON. For details on the JSON format, see [json.org](https://json.org/). This system function won't utilize the index.
34-
35-
## Examples
36-
37-
The following example shows how `StringToArray` behaves across different types.
38-
39-
The following are examples with valid input.
40-
41-
```sql
42-
SELECT
43-
StringToArray('[]') AS a1,
44-
StringToArray("[1,2,3]") AS a2,
45-
StringToArray("[\"str\",2,3]") AS a3,
46-
StringToArray('[["5","6","7"],["8"],["9"]]') AS a4,
47-
StringToArray('[1,2,3, "[4,5,6]",[7,8]]') AS a5
24+
StringToArray(<string_expr>)
4825
```
4926

50-
Here's the result set.
27+
## Arguments
5128

52-
```json
53-
[{"a1": [], "a2": [1,2,3], "a3": ["str",2,3], "a4": [["5","6","7"],["8"],["9"]], "a5": [1,2,3,"[4,5,6]",[7,8]]}]
54-
```
29+
| | Description |
30+
| --- | --- |
31+
| **`string_expr`** | A string expression. |
5532

56-
The following examples illustrate invalid input:
57-
58-
- Single quotes within the array aren't valid JSON.
59-
- Even though they're valid within a query, they won't parse to valid arrays.
60-
- Strings within the array string must either be escaped "[\\"\\"]" or the surrounding quote must be single '[""]'.
33+
## Return types
6134

62-
```sql
63-
SELECT
64-
StringToArray("['5','6','7']")
65-
```
35+
Returns an array.
6636

67-
Here's the result set.
37+
## Examples
38+
39+
The following example illustrates how this function works with various inputs.
6840

69-
```json
70-
[{}]
71-
```
41+
:::code language="sql" source="~/cosmos-db-nosql-query-samples/scripts/stringtoarray/query.sql" highlight="2-8":::
7242

73-
The following are examples of invalid input.
74-
75-
The expression passed will be parsed as a JSON array; the following don't evaluate to type array and thus return undefined.
76-
77-
```sql
78-
SELECT
79-
StringToArray("["),
80-
StringToArray("1"),
81-
StringToArray(NaN),
82-
StringToArray(false),
83-
StringToArray(undefined)
84-
```
43+
:::code language="json" source="~/cosmos-db-nosql-query-samples/scripts/stringtoarray/result.json":::
8544

86-
Here's the result set.
45+
## Remarks
8746

88-
```json
89-
[{}]
90-
```
47+
- This function doesn't use the index.
48+
- If the expression can't be converted, the function returns `undefined`.
49+
- Nested string values must be written with double quotes to be valid.
50+
- Single quotes within the array aren't valid JSON. Even though single quotes are valid within a query, they don't parse to valid arrays. Strings within the array string must either be escaped `\"` or the surrounding quote must be a single quote.
51+
52+
> [!NOTE]
53+
> For more information on the JSON format, see [https://json.org](https://json.org/).
9154
9255
## Next steps
9356

9457
- [System functions Azure Cosmos DB](system-functions.yml)
95-
- [Introduction to Azure Cosmos DB](../../introduction.md)
58+
- [`StringToObject`](stringtoobject.md)
Lines changed: 31 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,93 +1,56 @@
11
---
2-
title: StringToBoolean in Azure Cosmos DB query language
3-
description: Learn about SQL system function StringToBoolean in Azure Cosmos DB.
4-
author: ginamr
2+
title: StringToBoolean
3+
titleSuffix: Azure Cosmos DB for NoSQL
4+
description: An Azure Cosmos DB for NoSQL system function that returns a string expression converted to a boolean.
5+
author: jcodella
6+
ms.author: jacodel
7+
ms.reviewer: sidandrews
58
ms.service: cosmos-db
69
ms.subservice: nosql
7-
ms.topic: conceptual
8-
ms.date: 03/03/2020
9-
ms.author: girobins
10-
ms.custom: query-reference, ignite-2022
10+
ms.topic: reference
11+
ms.date: 07/24/2023
12+
ms.custom: query-reference
1113
---
12-
# StringToBoolean (Azure Cosmos DB)
14+
15+
# StringToBoolean (NoSQL query)
16+
1317
[!INCLUDE[NoSQL](../../includes/appliesto-nosql.md)]
1418

15-
Returns expression translated to a Boolean. If expression can't be translated, returns undefined.
19+
Converts a string expression to a boolean.
1620

1721
## Syntax
1822

1923
```sql
20-
StringToBoolean(<str_expr>)
21-
```
22-
23-
## Arguments
24-
25-
*str_expr*
26-
Is a string expression to be parsed as a Boolean expression.
27-
28-
## Return types
29-
30-
Returns a Boolean expression or undefined.
31-
32-
## Examples
33-
34-
The following example shows how `StringToBoolean` behaves across different types.
35-
36-
The following are examples with valid input.
37-
38-
Whitespace is allowed only before or after `true`/`false`.
39-
40-
```sql
41-
SELECT
42-
StringToBoolean("true") AS b1,
43-
StringToBoolean(" false") AS b2,
44-
StringToBoolean("false ") AS b3
45-
```
46-
47-
Here's the result set.
48-
49-
```json
50-
[{"b1": true, "b2": false, "b3": false}]
24+
StringToBoolean(<string_expr>)
5125
```
5226

53-
The following are examples with invalid input.
27+
## Arguments
5428

55-
Booleans are case sensitive and must be written with all lowercase characters such as `true` and `false`.
29+
| | Description |
30+
| --- | --- |
31+
| **`string_expr`** | A string expression. |
5632

57-
```sql
58-
SELECT
59-
StringToBoolean("TRUE"),
60-
StringToBoolean("False")
61-
```
33+
## Return types
6234

63-
Here's the result set.
35+
Returns a boolean value.
6436

65-
```json
66-
[{}]
67-
```
68-
69-
The expression passed will be parsed as a Boolean expression; these inputs don't evaluate to type Boolean and thus return undefined.
37+
## Examples
38+
39+
The following example illustrates how this function works with various data types.
7040

71-
```sql
72-
SELECT
73-
StringToBoolean("null"),
74-
StringToBoolean(undefined),
75-
StringToBoolean(NaN),
76-
StringToBoolean(false),
77-
StringToBoolean(true)
78-
```
41+
:::code language="sql" source="~/cosmos-db-nosql-query-samples/scripts/stringtoboolean/query.sql" highlight="2-8":::
7942

80-
Here's the result set.
81-
82-
```json
83-
[{}]
84-
```
43+
:::code language="json" source="~/cosmos-db-nosql-query-samples/scripts/stringtoboolean/result.json":::
8544

8645
## Remarks
8746

88-
This system function won't utilize the index.
47+
- This function doesn't use the index.
48+
- If the expression can't be converted, the function returns `undefined`.
49+
50+
> [!NOTE]
51+
> For more information on the JSON format, see [https://json.org](https://json.org/).
8952
9053
## Next steps
9154

9255
- [System functions Azure Cosmos DB](system-functions.yml)
93-
- [Introduction to Azure Cosmos DB](../../introduction.md)
56+
- [`StringToNumber`](stringtonumber.md)
Lines changed: 32 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,92 +1,56 @@
11
---
2-
title: StringToNull in Azure Cosmos DB query language
3-
description: Learn about SQL system function StringToNull in Azure Cosmos DB.
4-
author: ginamr
2+
title: StringToNull
3+
titleSuffix: Azure Cosmos DB for NoSQL
4+
description: An Azure Cosmos DB for NoSQL system function that returns a string expression converted to null.
5+
author: jcodella
6+
ms.author: jacodel
7+
ms.reviewer: sidandrews
58
ms.service: cosmos-db
69
ms.subservice: nosql
7-
ms.topic: conceptual
8-
ms.date: 03/03/2020
9-
ms.author: girobins
10-
ms.custom: query-reference, ignite-2022
10+
ms.topic: reference
11+
ms.date: 07/24/2023
12+
ms.custom: query-reference
1113
---
12-
# StringToNull (Azure Cosmos DB)
14+
15+
# StringToNull (NoSQL query)
16+
1317
[!INCLUDE[NoSQL](../../includes/appliesto-nosql.md)]
1418

15-
Returns expression translated to null. If expression can't be translated, returns undefined.
19+
Converts a string expression to `null`.
1620

1721
## Syntax
18-
19-
```sql
20-
StringToNull(<str_expr>)
21-
```
22-
23-
## Arguments
24-
25-
*str_expr*
26-
Is a string expression to be parsed as a null expression.
27-
28-
## Return types
29-
30-
Returns a null expression or undefined.
31-
32-
## Examples
33-
34-
The following example shows how `StringToNull` behaves across different types.
3522

36-
The following are examples with valid input.
23+
```sql
24+
StringToNull(<string_expr>)
25+
```
3726

38-
Whitespace is allowed only before or after "null".
27+
## Arguments
3928

40-
```sql
41-
SELECT
42-
StringToNull("null") AS n1,
43-
StringToNull(" null ") AS n2,
44-
IS_NULL(StringToNull("null ")) AS n3
45-
```
46-
47-
Here's the result set.
48-
49-
```json
50-
[{"n1": null, "n2": null, "n3": true}]
51-
```
29+
| | Description |
30+
| --- | --- |
31+
| **`string_expr`** | A string expression. |
5232

53-
The following are examples with invalid input.
33+
## Return types
5434

55-
Null is case sensitive and must be written with all lowercase characters such as `null`.
35+
Returns a `null`.
5636

57-
```sql
58-
SELECT
59-
StringToNull("NULL"),
60-
StringToNull("Null")
61-
```
62-
63-
Here's the result set.
37+
## Examples
6438

65-
```json
66-
[{}]
67-
```
39+
The following example illustrates how this function works with various data types.
6840

69-
The expression passed will be parsed as a null expression; these inputs don't evaluate to type null and thus return undefined.
41+
:::code language="sql" source="~/cosmos-db-nosql-query-samples/scripts/stringtonull/query.sql" highlight="2-9":::
7042

71-
```sql
72-
SELECT
73-
StringToNull("true"),
74-
StringToNull(false),
75-
StringToNull(undefined),
76-
StringToNull(NaN)
77-
```
78-
79-
Here's the result set.
80-
81-
```json
82-
[{}]
83-
```
43+
:::code language="json" source="~/cosmos-db-nosql-query-samples/scripts/stringtonull/result.json":::
8444

8545
## Remarks
8646

87-
This system function won't utilize the index.
47+
- This function doesn't use the index.
48+
- If the expression can't be converted, the function returns `undefined`.
49+
50+
> [!NOTE]
51+
> For more information on the JSON format, see [https://json.org](https://json.org/).
8852
8953
## Next steps
9054

9155
- [System functions Azure Cosmos DB](system-functions.yml)
92-
- [Introduction to Azure Cosmos DB](../../introduction.md)
56+
- [`StringToBoolean`](stringtoboolean.md)

0 commit comments

Comments
 (0)