Skip to content

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

Description

@roji

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.

Activity

  1. added this to the 10.0.0 milestone on Mar 5, 2025
  2. self-assigned this
    on Mar 5, 2025
  3. roji commented on Mar 6, 2025

    @roji
    MemberAuthor

    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.

  4. added theissue type on Jun 15, 2025
  5. added 3 commits that reference this issue on Jul 28, 2025
    d05f596
    4997eeb
    6b62059
  6. added a commit that references this issue on Jul 31, 2025
    9437369
  7. added a commit that references this issue on Jul 31, 2025
    91d41df
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions