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

Squared brackets missing from JSON_ARRAYAGG when used in a view

Details

    • Bug
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Fixed
    • 10.5.1, 10.5
    • 10.5.4
    • JSON
    • None
    • Win 10

    Description

      When JSON_ARRAYAGG is used in a view, querying that view results in missing [ and ] brackets.

      create or replace view dummy as (
       
        select  json_arrayagg(json_object(
                 "type", "permPeriod",
                 "id", ID
               )) as JSON_DATA
        
        from TEST
       
        group by COL1
      )
       
      select * from dummy 
      

      gives:

      {"type": "permPeriod", "id": 7},{"type": "permPeriod", "id": 8}
      

      instead of:

      [{"type": "permPeriod", "id": 7},{"type": "permPeriod", "id": 8}]
      

      Attachments

        Issue Links

          Activity

            alice Alice Sherepa added a comment -

            Thanks for the report!
            Reproducible on 10.5

            create table t1 (i int,id int);
            insert into t1 values (7,7),(7,8);
             
            create view v1 as
              ( select json_arrayagg(json_object( "type", "permperiod", "id", id )) as json_data
               from t1
               group by i);
             
            show create view v1;
             
            select * from v1 ;
             
            select json_arrayagg(json_object( "type", "permperiod", "id", id )) as json_data
            from t1
            group by i ;
             
            drop view v1;
            drop table t1;
            

            MariaDB [test]> show create view v1;
            +------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------+----------------------+
            | View | Create View                                                                                                                                                                                                             | character_set_client | collation_connection |
            +------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------+----------------------+
            | v1   | CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS (select group_concat(json_object('type','permPeriod','id',`t1`.`id`) separator ',') AS `JSON_DATA` from `t1` group by `t1`.`i`) | utf8                 | utf8_general_ci      |
            +------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------+----------------------+
            1 row in set (0.001 sec)
             
            MariaDB [test]> select * from v1 ;
            +-----------------------------------------------------------------+
            | JSON_DATA                                                       |
            +-----------------------------------------------------------------+
            | {"type": "permPeriod", "id": 7},{"type": "permPeriod", "id": 8} |
            +-----------------------------------------------------------------+
            1 row in set (0.002 sec)
             
            MariaDB [test]> SELECT json_arrayagg(json_object( "type", "permPeriod", "id", ID )) AS JSON_DATA
                -> FROM t1
                -> GROUP BY i ;
            +-------------------------------------------------------------------+
            | JSON_DATA                                                         |
            +-------------------------------------------------------------------+
            | [{"type": "permPeriod", "id": 7},{"type": "permPeriod", "id": 8}] |
            +-------------------------------------------------------------------+
            1 row in set (0.004 sec)
            

            alice Alice Sherepa added a comment - Thanks for the report! Reproducible on 10.5 create table t1 (i int ,id int ); insert into t1 values (7,7),(7,8);   create view v1 as ( select json_arrayagg(json_object( "type" , "permperiod" , "id" , id )) as json_data from t1 group by i);   show create view v1;   select * from v1 ;   select json_arrayagg(json_object( "type" , "permperiod" , "id" , id )) as json_data from t1 group by i ;   drop view v1; drop table t1; MariaDB [test]> show create view v1; +------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------+----------------------+ | View | Create View | character_set_client | collation_connection | +------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------+----------------------+ | v1 | CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS (select group_concat(json_object('type','permPeriod','id',`t1`.`id`) separator ',') AS `JSON_DATA` from `t1` group by `t1`.`i`) | utf8 | utf8_general_ci | +------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------+----------------------+ 1 row in set (0.001 sec)   MariaDB [test]> select * from v1 ; +-----------------------------------------------------------------+ | JSON_DATA | +-----------------------------------------------------------------+ | {"type": "permPeriod", "id": 7},{"type": "permPeriod", "id": 8} | +-----------------------------------------------------------------+ 1 row in set (0.002 sec)   MariaDB [test]> SELECT json_arrayagg(json_object( "type", "permPeriod", "id", ID )) AS JSON_DATA -> FROM t1 -> GROUP BY i ; +-------------------------------------------------------------------+ | JSON_DATA | +-------------------------------------------------------------------+ | [{"type": "permPeriod", "id": 7},{"type": "permPeriod", "id": 8}] | +-------------------------------------------------------------------+ 1 row in set (0.004 sec)
            holyfoot Alexey Botchkov added a comment - https://github.com/MariaDB/server/commit/07daf735422403d2336df65ccc3f808d76b28497
            Diderik Jeroen Diderik added a comment - - edited

            I might be mistaken, but after upgrading my MariaDB to 10.5.8, this issue is back again?
            I am not using it in a view, but just a regular select:

            SELECT
            trid,
            JSON_ARRAYAGG(
            JSON_OBJECT(
            'teid', teid,
            'tename', tename,
            'trid', trid,
            'trname', trname,
            'medium', temedium,
            'contacttype', te.tecontacttype,
            'stoptype', te.testop,
            'contactid', te.tecontactid,
            'templateid', tt.ttid,
            'templatename', tt.ttname,
            'templatesubject', tt.ttsubject,
            'templatetext', tt.tttext
            )
            ) as trevents
            FROM trackingrules tr
            RIGHT JOIN trackingevents te ON te.tetrid = tr.trid AND te.teactive = 1 AND te.temedium > 0
            LEFT JOIN trackingtemplates tt ON tt.ttid = te.tetemplateid
            WHERE tr.trisactive = 1
            GROUP BY trid

            Diderik Jeroen Diderik added a comment - - edited I might be mistaken, but after upgrading my MariaDB to 10.5.8, this issue is back again? I am not using it in a view, but just a regular select: SELECT trid, JSON_ARRAYAGG( JSON_OBJECT( 'teid', teid, 'tename', tename, 'trid', trid, 'trname', trname, 'medium', temedium, 'contacttype', te.tecontacttype, 'stoptype', te.testop, 'contactid', te.tecontactid, 'templateid', tt.ttid, 'templatename', tt.ttname, 'templatesubject', tt.ttsubject, 'templatetext', tt.tttext ) ) as trevents FROM trackingrules tr RIGHT JOIN trackingevents te ON te.tetrid = tr.trid AND te.teactive = 1 AND te.temedium > 0 LEFT JOIN trackingtemplates tt ON tt.ttid = te.tetemplateid WHERE tr.trisactive = 1 GROUP BY trid
            alice Alice Sherepa added a comment -

            Diderik, probably your problem is the same as MDEV-23004

            alice Alice Sherepa added a comment - Diderik , probably your problem is the same as MDEV-23004

            People

              holyfoot Alexey Botchkov
              fathert Tim Fathers
              Votes:
              0 Vote for this issue
              Watchers:
              5 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.