- 
                Notifications
    You must be signed in to change notification settings 
- Fork 3.3k
Closed
Copy link
Description
In SQL Server 2025 (and an upcoming update of Azure SQL), the JSON_VALUE() function will be improved to support a RETURNING clause, allowing specifying the data type coming out of the JSON property. We currently wrap JSON_VALUE() in a CAST, but this has several issues:
- CAST applies generic string casting without taking into account that the property comes from JSON. While the standard way to represent binary data in JSON is base64 encoding, SQL Server CAST attempts to parse out SQL Server's native format, which fails.
- JSON_VALUE() returns nvarchar(4000)by default, so it's impossible to have larger strings (SQL Server: Support large JSON string properties (>4000) #29477). It's likely that with RETURNING we'd be able to just read out annvarchar(max)(TBC).
- The additional CAST may reduce performance compared to the native RETURNING feature of JSON_VALUE.
Note that JSON_VALUE() and the RETURNING clause is part of the ANSI SQL standard, and is already supported in PostgreSQL 17 (EFCore.PG tracking issue). So we should implement all this as the default behavior in relational, and override to implement the old behavior without RETURNING.
Tentatively assigning to myself as for 10.