Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support the new RETURNING clause in JSON_VALUE() in the upcoming SQL Server 2025 #35729

Open
roji opened this issue Mar 5, 2025 · 1 comment

Comments

@roji
Copy link
Member

roji commented Mar 5, 2025

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 an nvarchar(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.

@roji
Copy link
Member Author

roji commented Mar 6, 2025

Note: implemented for PostgreSQL in npgsql/efcore.pg#3490, without any relational support for now; when the SQL Server support is available, I'll compare and see what's common etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant