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

JSON_EXTRACT returns result in document and not in path order

    XMLWordPrintable

Details

    • Bug
    • Status: Confirmed (View Workflow)
    • Major
    • Resolution: Unresolved
    • 10.5.5, 10.2(EOL), 10.3(EOL), 10.4(EOL), 10.5(EOL)
    • 10.6
    • None
    • None

    Description

      Consider the following:

      > SELECT JSON_EXTRACT('{ "a":1, "b":2}', '$.b', '$.a');
      +-----------------------------------------------+
      | JSON_EXTRACT('{ "a":1, "b":2}', '$.b', '$.a') |
      +-----------------------------------------------+
      | [1, 2]                                        |
      +-----------------------------------------------+
      1 row in set (0.000 sec)
       
      MariaDB [(none)]> SELECT JSON_EXTRACT('{ "a":1, "b":2}', '$.a', '$.b');
      +-----------------------------------------------+
      | JSON_EXTRACT('{ "a":1, "b":2}', '$.a', '$.b') |
      +-----------------------------------------------+
      | [1, 2]                                        |
      +-----------------------------------------------+
      1 row in set (0.000 sec)
      

      The selected field values are returned in the order in which they appear in the document, and not in the order of the path arguments given to JSON_EXTRACT.

      The documentation at https://dev.mysql.com/doc/refman/8.0/en/json-search-functions.html#function_json-extract states If it is possible that those arguments could return multiple values, the matched values are autowrapped as an array, in the order corresponding to the paths that produced them.

      Indeed, unless that is done, multiple path arguments cannot be used, as you will not know which returned value corresponds to which path.

      Attachments

        Activity

          People

            rucha174 Rucha Deodhar
            johan.wikman Johan Wikman
            Votes:
            0 Vote for this issue
            Watchers:
            6 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.