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

Extracting value from a JSON array using JSON_EXTRACT inconsistent among versions

    XMLWordPrintable

Details

    • Bug
    • Status: Closed (View Workflow)
    • Minor
    • Resolution: Duplicate
    • 10.9.0, 10.10.2
    • N/A
    • JSON
    • None
    • mac os monterey v12.1

    Description

      Step1: Create table

      CREATE TABLE IF NOT EXISTS brands (
      name VARCHAR(255) NOT NULL,
      sold longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL
      );

      Step2: Insert values into table

      INSERT INTO brands (name, sold)
      VALUES
      ('test', '[

      {"id":"0","name":"0","count":5000}

      ,

      {"id":"1","name":"1","count":5000}

      ]'),
      ('test2', '[

      {"id":"0","name":"0","count":10000}

      ,

      {"id":"1","name":"1","count":10000}

      ]'),
      ('test3', '[

      {"id":"0","name":"0","count":15000}

      ,

      {"id":"1","name":"1","count":15000}

      ]'),
      ('test4', '[

      {"id":"0","name":"0","count":700}

      ,

      {"id":"1","name":"1","count":700}

      ]');

      Step3: Extract values using query

      SELECT name, JSON_EXTRACT(sold, '$[*].count') as cnt FROM brands;

      Output is incorrect when running V10.9 and above:

      name cnt
      test [5000, 5000]
      test 10000
      test 15000
      test 700

      Output is correct when running V10.8 and below:

      name cnt
      test [5000, 5000]
      test [10000, 10000]
      test [15000, 15000]
      test [700, 700]

      Test fiddle here: https://dbfiddle.uk/0A5oD29V

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              Unmasking8770 AR
              Votes:
              0 Vote for this issue
              Watchers:
              2 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.