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

JSON_VALUE returns first value from array not from range

    XMLWordPrintable

Details

    • Bug
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Fixed
    • 10.9(EOL)
    • 10.9.1
    • JSON
    • None

    Description

      Test:

      SET @json1= '[
                   [{"key1": "value1"}, {"key2": "value2"}],
                   [{"key3": "value3"}, {"key1": "value4"}],
                   [{"key1": "value5"}, {"key4": "value6"}, {"key1": "value7"}]
                  ]';
      SELECT JSON_VALUE(@json1, '$[2][1 to 2].key1');
      SELECT JSON_VALUE(@json1, '$[2][1].key1');
      SELECT JSON_VALUE(@json1, '$[2][2].key1');
      

      Expected result:

      SET @json1= '[
                   [{"key1": "value1"}, {"key2": "value2"}],
                   [{"key3": "value3"}, {"key1": "value4"}],
                   [{"key1": "value5"}, {"key4": "value6"}, {"key1": "value7"}]
                  ]';
      SELECT JSON_VALUE(@json1, '$[2][1 to 2].key1');
      JSON_VALUE(@json1, '$[2][1 to 2].key1')
      value7
      SELECT JSON_VALUE(@json1, '$[2][1].key1');
      JSON_VALUE(@json1, '$[2][1].key1')
      NULL
      SELECT JSON_VALUE(@json1, '$[2][2].key1');
      JSON_VALUE(@json1, '$[2][2].key1')
      value7
      

      Actual result:

      SET @json1= '[
                   [{"key1": "value1"}, {"key2": "value2"}],
                   [{"key3": "value3"}, {"key1": "value4"}],
                   [{"key1": "value5"}, {"key4": "value6"}, {"key1": "value7"}]
                  ]';
      SELECT JSON_VALUE(@json1, '$[2][1 to 2].key1');
      JSON_VALUE(@json1, '$[2][1 to 2].key1')
      value5
      SELECT JSON_VALUE(@json1, '$[2][1].key1');
      JSON_VALUE(@json1, '$[2][1].key1')
      NULL
      SELECT JSON_VALUE(@json1, '$[2][2].key1');
      JSON_VALUE(@json1, '$[2][2].key1')
      value7
      

      The same behavior when json contains only arrays:

      SET @json= '[
                   [1.1, {"key1": "value1"}, 3],
                   [false, 5, 6],
                   [7, 8, [9, {"key2": 2}, 11]],
                   [11, 1.34, [14], ["string1", [16, {"key1":[1,2,3,[4,5,6]]}, 18]]],
                   [19, 20]
                  ]';
      SELECT JSON_VALUE(@json, '$[2 to 3][0]');
      JSON_VALUE(@json, '$[2 to 3][0]')
      1.1
      SELECT JSON_VALUE(@json, '$[2][0]');
      JSON_VALUE(@json, '$[2][0]')
      7
      SELECT JSON_VALUE(@json, '$[3][0]');
      JSON_VALUE(@json, '$[3][0]')
      11
      

      "1.1" is the first value in array not first in the specified range.

      Attachments

        Issue Links

          Activity

            People

              rucha174 Rucha Deodhar
              lstartseva Lena Startseva
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Git Integration

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