Query/JSON: consider improvements to SQL we generate when we access element in collection mapped to JSON
- Dominant language
- C#
- Stars
- 14.8k
- Forks
- 3.4k
- PR merge metrics
- PR metrics pending
Description
Currently when we access element in JSON, if it's a constant it gets directly incorporated into JSON path, however for parametes/columns/complex expressions we cast the resulting expression to string type and stitch it together with the rest of JSON path, which looks ugly, e.g.:
```sql
JSON_QUERY([j].[OwnedCollectionRoot],'$[0].OwnedCollectionBranch[' + CAST(@__prm_0 AS nvarchar(max)) + ']')
```
```sql
JSON_QUERY([j].[OwnedCollectionRoot],'$[' + CAST([j].[Id] AS nvarchar(max)) + ']')
```
```sql
JSON_VALUE([j].[OwnedCollectionRoot],'$[' + CAST((
SELECT MAX([j].[Id])
FROM [JsonEntitiesBasic] AS [j]) AS nvarchar(max)) + '].Name')
```
we could consider improving that, perhaps use subquery?
Contributor guide
Assessment
This issue has not been assessed yet.