You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/cosmos-db/sql-query-from.md
+12-12Lines changed: 12 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,17 +4,17 @@ description: Learn about the SQL syntax, and example for FROM clause for Azure C
4
4
author: timsander1
5
5
ms.service: cosmos-db
6
6
ms.topic: conceptual
7
-
ms.date: 12/02/2019
7
+
ms.date: -5/08/2020
8
8
ms.author: tisande
9
9
10
10
---
11
11
# FROM clause in Azure Cosmos DB
12
12
13
13
The FROM (`FROM <from_specification>`) clause is optional, unless the source is filtered or projected later in the query. A query like `SELECT * FROM Families` enumerates over the entire `Families` container. You can also use the special identifier ROOT for the container instead of using the container name.
14
14
15
-
The FROM clause enforces the following rules per query:
15
+
The `FROM` clause enforces the following rules per query:
16
16
17
-
* The container can be aliased, such as `SELECT f.id FROM Families AS f` or simply `SELECT f.id FROM Families f`. Here `f` is the alias for `Families`. AS is an optional keyword to [alias](sql-query-aliasing.md) the identifier.
17
+
* The container can be aliased, such as `SELECT f.id FROM Families AS f` or simply `SELECT f.id FROM Families f`. Here `f` is the alias for `Families`. AS is an optional keyword to [alias](sql-query-working-with-json.md#aliasing) the identifier.
18
18
19
19
* Once aliased, the original source name cannot be bound. For example, `SELECT Families.id FROM Families f` is syntactically invalid because the identifier `Families` has been aliased and can't be resolved anymore.
20
20
@@ -25,15 +25,15 @@ The FROM clause enforces the following rules per query:
25
25
```sql
26
26
FROM<from_specification>
27
27
28
-
<from_specification> ::=
28
+
<from_specification> ::=
29
29
<from_source> {[ JOIN<from_source>][,...n]}
30
30
31
-
<from_source> ::=
31
+
<from_source> ::=
32
32
<container_expression> [[AS] input_alias]
33
33
| input_alias IN<container_expression>
34
34
35
-
<container_expression> ::=
36
-
ROOT
35
+
<container_expression> ::=
36
+
ROOT
37
37
| container_name
38
38
| input_alias
39
39
| <container_expression>'.' property_name
@@ -46,9 +46,9 @@ FROM <from_specification>
46
46
47
47
Specifies a data source, with or without an alias. If alias is not specified, it will be inferred from the `<container_expression>` using following rules:
48
48
49
-
- If the expression is a container_name, then container_name will be used as an alias.
49
+
- If the expression is a container_name, then container_name will be used as an alias.
50
50
51
-
- If the expression is `<container_expression>`, then property_name, then property_name will be used as an alias. If the expression is a container_name, then container_name will be used as an alias.
51
+
- If the expression is `<container_expression>`, then property_name, then property_name will be used as an alias. If the expression is a container_name, then container_name will be used as an alias.
52
52
53
53
- AS `input_alias`
54
54
@@ -94,9 +94,9 @@ If a container expression accesses properties or array elements and that value d
94
94
95
95
A container expression may be container-scoped or document-scoped:
96
96
97
-
-An expression is container-scoped, if the underlying source of the container expression is either ROOT or `container_name`. Such an expression represents a set of documents retrieved from the container directly, and is not dependent on the processing of other container expressions.
97
+
- An expression is container-scoped, if the underlying source of the container expression is either ROOT or `container_name`. Such an expression represents a set of documents retrieved from the container directly, and is not dependent on the processing of other container expressions.
98
98
99
-
-An expression is document-scoped, if the underlying source of the container expression is `input_alias` introduced earlier in the query. Such an expression represents a set of documents obtained by evaluating the container expression in the scope of each document belonging to the set associated with the aliased container. The resulting set will be a union of sets obtained by evaluating the container expression for each of the documents in the underlying set.
99
+
- An expression is document-scoped, if the underlying source of the container expression is `input_alias` introduced earlier in the query. Such an expression represents a set of documents obtained by evaluating the container expression in the scope of each document belonging to the set associated with the aliased container. The resulting set will be a union of sets obtained by evaluating the container expression for each of the documents in the underlying set.
100
100
101
101
## Examples
102
102
@@ -142,7 +142,7 @@ The results are:
142
142
]
143
143
```
144
144
145
-
The preceding query used an array as the source, but you can also use an object as the source. The query considers any valid, defined JSON value in the source for inclusion in the result. The following example would exclude `Families` that don’t have an `address.state` value.
145
+
The preceding query used an array as the source, but you can also use an object as the source. The query considers any valid, defined JSON value in the source for inclusion in the result. The following example would exclude `Families` that don't have an `address.state` value.
Copy file name to clipboardExpand all lines: articles/cosmos-db/sql-query-select.md
+1-2Lines changed: 1 addition & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,7 +10,7 @@ ms.author: tisande
10
10
11
11
# SELECT clause in Azure Cosmos DB
12
12
13
-
Every query consists of a SELECT clause and optional [FROM](sql-query-from.md) and [WHERE](sql-query-where.md) clauses, per ANSI SQL standards. Typically, the source in the FROM clause is enumerated, and the WHERE clause applies a filter on the source to retrieve a subset of JSON items. The SELECT clause then projects the requested JSON values in the select list.
13
+
Every query consists of a `SELECT` clause and optional [FROM](sql-query-from.md) and [WHERE](sql-query-where.md) clauses, per ANSI SQL standards. Typically, the source in the `FROM` clause is enumerated, and the `WHERE` clause applies a filter on the source to retrieve a subset of JSON items. The `SELECT` clause then projects the requested JSON values in the select list.
Copy file name to clipboardExpand all lines: articles/cosmos-db/sql-query-working-with-json.md
+15-12Lines changed: 15 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,14 +8,17 @@ ms.date: 05/08/2020
8
8
ms.author: tisande
9
9
---
10
10
11
+
# Working with JSON in Azure Cosmos DB
12
+
11
13
In Azure Cosmos DB's SQL (Core) API, items are stored as JSON. The type system and expressions are restricted to deal only with JSON types. For more information, see the [JSON specification](https://www.json.org/).
12
14
13
15
We'll summarize some important aspects of working with JSON.
14
-
- JSON objects always begin with a `{` left brace and end with a `}` right brace
15
-
- You can have JSON properties [nested](#nested-properties) within one another
16
-
- JSON properties can have arrays values
17
-
- JSON properties are case sensitive
18
-
- JSON properties can have any string value (including spaces or characters that aren't letters)
16
+
17
+
- JSON objects always begin with a `{` left brace and end with a `}` right brace
18
+
- You can have JSON properties [nested](#nested-properties) within one another
19
+
- JSON properties can have arrays values
20
+
- JSON properties are case sensitive
21
+
- JSON properties can have any string value (including spaces or characters that aren't letters)
19
22
20
23
## Nested properties
21
24
@@ -39,7 +42,7 @@ Here's a document with nested JSON:
39
42
40
43
In this case, the `state`, `country`, and `city` properties are all nested within the `address` property.
41
44
42
-
The following example projects two nested properties,`f.address.state` and `f.address.city`.
45
+
The following example projects two nested properties:`f.address.state` and `f.address.city`.
43
46
44
47
```sql
45
48
SELECTf.address.state, f.address.city
@@ -90,7 +93,7 @@ FROM Families f
90
93
WHEREf.children[0].givenName ="Jesse"
91
94
```
92
95
93
-
In most cases however, you'll use a [subquery](sql-query-subquery.md) or [self-join](sql-query-join.md) when working with arrays.
96
+
In most cases, however, you'll use a [subquery](sql-query-subquery.md) or [self-join](sql-query-join.md) when working with arrays.
94
97
95
98
For example, here's a document that shows the bank account balance of a customer over each month during 2020.
96
99
@@ -119,7 +122,7 @@ For example, here's a document that shows the bank account balance of a customer
119
122
}
120
123
```
121
124
122
-
If you wanted to run a query that showed all the customers that had a negative balance at some point during 2020, it would use [EXISTS](sql-query-subquery.md#exists-expression) with a subquery and look like this:
125
+
If you wanted to run a query that showed all the customers that had a negative balance at some point during 2020, it would use [EXISTS](sql-query-subquery.md#exists-expression) with a subquery:
123
126
124
127
```sql
125
128
SELECTc.id
@@ -133,7 +136,7 @@ WHERE EXISTS(
133
136
134
137
## Reserved keywords and special characters in JSON
135
138
136
-
You can access properties using the quoted property operator []. For example, `SELECT c.grade` and `SELECT c["grade"]` are equivalent. This syntax is useful to escape a property that contains spaces, special characters, or has the same name as a SQL keyword or reserved word.
139
+
You can access properties using the quoted property operator `[]`. For example, `SELECT c.grade` and `SELECT c["grade"]` are equivalent. This syntax is useful to escape a property that contains spaces, special characters, or has the same name as a SQL keyword or reserved word.
137
140
138
141
For example, here's a document with a property named `order` and a property `price($)` that contains special characters:
139
142
@@ -229,7 +232,7 @@ You can explicitly alias values in queries. If a query has two properties with t
229
232
230
233
### Examples
231
234
232
-
The AS keyword used for aliasing is optional, as shown in the following example when projecting the second value as `NameInfo`:
235
+
The `AS` keyword used for aliasing is optional, as shown in the following example when projecting the second value as `NameInfo`:
233
236
234
237
```sql
235
238
SELECT
@@ -253,7 +256,7 @@ The results are:
253
256
}]
254
257
```
255
258
256
-
You can't use alias to project a value as a property name with a space, special character, or reserved word. If you wanted to change a value's projection to, for example, have a property name with a space, you could use a [JSON expression](#json-expressions).
259
+
You can't use aliasing to project a value as a property name with a space, special character, or reserved word. If you wanted to change a value's projection to, for example, have a property name with a space, you could use a [JSON expression](#json-expressions).
257
260
258
261
Here's an example:
259
262
@@ -268,5 +271,5 @@ Here's an example:
268
271
## Next steps
269
272
270
273
-[Getting started](sql-query-getting-started.md)
271
-
-[Azure Cosmos DB .NET samples](https://github.com/Azure/azure-cosmos-dotnet-v3)
0 commit comments