Skip to content

Commit 581dba0

Browse files
Merge pull request #221240 from jcocchi/update-distinct-restrictions
Cosmos DB Update SQL distinct keyword restrictions
2 parents 697a646 + 74179c0 commit 581dba0

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

articles/cosmos-db/nosql/query/keywords.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ The results are:
9898
]
9999
```
100100

101-
Queries with an aggregate system function and a subquery with `DISTINCT` are only supported in specific SDK versions. For example, queries with the following shape are only supported in the below specific SDK versions:
101+
Queries with an aggregate system function and a subquery with `DISTINCT` are only supported in specific SDK versions. This is because they require coordination of the results returned from every continuation to create an exact result set. For example, queries with the following shape are only supported in the below specific SDK versions:
102102

103103
```sql
104104
SELECT COUNT(1) FROM (SELECT DISTINCT f.lastName FROM f)
@@ -113,14 +113,15 @@ SELECT COUNT(1) FROM (SELECT DISTINCT f.lastName FROM f)
113113
|Node.js SDK|Unsupported|
114114
|Python SDK|Unsupported|
115115

116-
There are some additional restrictions on queries with an aggregate system function and a subquery with `DISTINCT`. The below queries are unsupported:
116+
There are some additional restrictions on nested queries with `DISTINCT` regardless of SDK version. In these cases, there may be incorrect and inconsistent results because the query would require extra coordination. The below queries are unsupported:
117117

118118
|**Restriction**|**Example**|
119119
|-------|----------------------|
120+
|Nested Subquery|SELECT VALUE f FROM (SELECT DISTINCT c.year FROM c) f|
120121
|WHERE clause in the outer query|SELECT COUNT(1) FROM (SELECT DISTINCT VALUE c.lastName FROM c) AS lastName WHERE lastName = "Smith"|
121122
|ORDER BY clause in the outer query|SELECT VALUE COUNT(1) FROM (SELECT DISTINCT VALUE c.lastName FROM c) AS lastName ORDER BY lastName|
122123
|GROUP BY clause in the outer query|SELECT COUNT(1) as annualCount, d.year FROM (SELECT DISTINCT c.year, c.id FROM c) AS d GROUP BY d.year|
123-
|Nested subquery|SELECT COUNT(1) FROM (SELECT y FROM (SELECT VALUE StringToNumber(SUBSTRING(d.date, 0, 4 FROM (SELECT DISTINCT c.date FROM c) d) AS y WHERE y > 2012)|
124+
|Nested subquery with aggregate system function|SELECT COUNT(1) FROM (SELECT y FROM (SELECT VALUE StringToNumber(SUBSTRING(d.date, 0, 4 FROM (SELECT DISTINCT c.date FROM c) d) AS y WHERE y > 2012)|
124125
|Multiple aggregations|SELECT COUNT(1) as AnnualCount, SUM(d.sales) as TotalSales FROM (SELECT DISTINCT c.year, c.sales, c.id FROM c) AS d|
125126
|COUNT() must have 1 as a parameter|SELECT COUNT(lastName) FROM (SELECT DISTINCT VALUE c.lastName FROM c) AS lastName|
126127

0 commit comments

Comments
 (0)