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

Derived table with JSON_ARRAYAGG

    XMLWordPrintable

Details

    • Bug
    • Status: Confirmed (View Workflow)
    • Major
    • Resolution: Unresolved
    • 11.5.2
    • 10.5, 10.6, 10.11, 11.4, 11.7
    • JSON, Optimizer
    • None
    • mariadb:11.5.2 docker image

    Description

      CREATE OR REPLACE TABLE test (
      	id INT,
      	name VARCHAR(255),
      	attribute VARCHAR(255)
      );
       
      INSERT INTO test (id, name, attribute) VALUES
      (1, 'John Doe', 'height: 6ft'),
      (1, 'John Doe', 'age: 30'),
      (2, 'Jane Smith', 'height: 5.5ft'),
      (2, 'Jane Smith', 'age: 28'),
      (3, 'Alice Johnson', 'height: 5.7ft'),
      (3, 'Alice Johnson', 'age: 35'),
      (4, 'Bob Brown', 'height: 6.1ft'),
      (4, 'Bob Brown', 'age: 40'),
      (5, 'Charlie Davis', 'height: 5.9ft'),
      (5, 'Charlie Davis', 'age: 32');
       
       
      SELECT id, name, attr FROM (
      	SELECT id, name, JSON_ARRAYAGG(attribute ORDER BY attribute) attr FROM test GROUP BY id, name
      ) t
      WHERE JSON_VALUE(attr, '$[0]') = 'age: 30';
      -- returns empty result
       
      SELECT id, name, attr, JSON_VALUE(attr, '$[0]') = 'age: 30' as v FROM (
      	SELECT id, name, JSON_ARRAYAGG(attribute ORDER BY attribute) attr FROM test GROUP BY id, name
      ) t
      HAVING v = 1;
      -- returns one result
       
      CREATE OR REPLACE TEMPORARY TABLE tmp
      SELECT id, name, JSON_ARRAYAGG(attribute ORDER BY attribute) attr FROM test GROUP BY id, name;
       
      SELECT * FROM tmp WHERE JSON_VALUE(attr, '$[0]') = 'age: 30';
      -- returns one result
      

      I expect the first select statement to return one result

      Attachments

        Issue Links

          Activity

            People

              Johnston Rex Johnston
              Micke Mikael Nilsson
              Votes:
              0 Vote for this issue
              Watchers:
              3 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.