Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-25148

Unexpected success and result set upon erroneous JSON_VALUE call

    XMLWordPrintable

Details

    • Bug
    • Status: Stalled (View Workflow)
    • Major
    • Resolution: Unresolved
    • 10.2, 10.3, 10.4, 10.5, 10.6
    • 10.4, 10.5
    • JSON
    • None

    Description

      10.2 ba7d86a6

      MariaDB [test]> select json_value('{"a":[1,2]}', '$.a[*]');
      +-------------------------------------+
      | json_value('{"a":[1,2]}', '$.a[*]') |
      +-------------------------------------+
      | 1                                   |
      +-------------------------------------+
      1 row in set (0.000 sec)
      

      So, the provided path refers to two values, of which the function picks up one and returns it. It is a wrong result, the expected result is an error. The standard is very specific about it:

      JSON_VALUE expects that the SQL/JSON path expression will return one SQL/JSON item; the ON EMPTY clause can be used to handle missing data (no SQL/JSON items) gracefully. More than one SQL/JSON item is an error.

      MySQL returns NULL, which implies an error:

      MySQL 8.0.23

      MySQL [test]> select json_value('{"a":[1,2]}', '$.a[*]');
      +-------------------------------------+
      | json_value('{"a":[1,2]}', '$.a[*]') |
      +-------------------------------------+
      | NULL                                |
      +-------------------------------------+
      1 row in set (0.000 sec)
      

      Attachments

        Activity

          People

            rucha174 Rucha Deodhar
            elenst Elena Stepanova
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Git Integration

                Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.