Skip to content

Commit 4aad9a3

Browse files
authored
Merge pull request #104669 from KalyanChanumolu-MSFT/patch-22
(AzureCXP) MicrosoftDocs/azure-docs- Adding new section for reserved keywords
2 parents 3e49db5 + e56dbca commit 4aad9a3

File tree

1 file changed

+45
-1
lines changed

1 file changed

+45
-1
lines changed

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

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,53 @@ The results are:
164164
}
165165
}]
166166
```
167+
## Reserved keywords and special characters
168+
169+
If your data contains properties with the same names as reserved keywords such as "order" or "Group" then the queries against these documents will result in syntax errors. You should explicitly include the property in `[]` character to run the query successfully.
170+
171+
For example, here's a document with a property named `order` and a property `price($)` that contains special characters:
172+
173+
```json
174+
{
175+
"id": "AndersenFamily",
176+
"order": [
177+
{
178+
"orderId": "12345",
179+
"productId": "A17849",
180+
"price($)": 59.33
181+
}
182+
],
183+
"creationDate": 1431620472,
184+
"isRegistered": true
185+
}
186+
```
187+
188+
If you run a queries that includes the `order` property or `price($)` property, you will receive a syntax error.
189+
190+
```sql
191+
SELECT * FROM c where c.order.orderid = "12345"
192+
```
193+
```sql
194+
SELECT * FROM c where c.order.price($) > 50
195+
```
196+
The result is:
197+
198+
`
199+
Syntax error, incorrect syntax near 'order'
200+
`
201+
202+
You should rewrite the same queries as below:
203+
204+
```sql
205+
SELECT * FROM c WHERE c["order"].orderId = "12345"
206+
```
207+
208+
```sql
209+
SELECT * FROM c WHERE c["order"]["price($)"] > 50
210+
```
167211

168212
## Next steps
169213

170214
- [Getting started](sql-query-getting-started.md)
171215
- [Azure Cosmos DB .NET samples](https://github.com/Azure/azure-cosmos-dotnet-v3)
172-
- [WHERE clause](sql-query-where.md)
216+
- [WHERE clause](sql-query-where.md)

0 commit comments

Comments
 (0)