Details

    Description

      JSON_ARRAYAGG() doesn't evaluate correct charset.

      reproduce:

      MariaDB [test]> CREATE TABLE t1 (a varchar(5));
      Query OK, 0 rows affected (0.035 sec)
       
      MariaDB [test]> INSERT INTO t1 VALUES ('a'),('ä');
      Query OK, 2 rows affected (0.014 sec)
       
      MariaDB [test]> select * from t1;
      +------+
      | a    |
      +------+
      | a    |
      | ä    |
      +------+
      2 rows in set (0.000 sec)
       
      MariaDB [test]> SELECT JSON_ARRAYAGG(a) FROM t1;
      +------------------+
      | JSON_ARRAYAGG(a) |
      +------------------+
      | ["a","▒"]         |
      +------------------+
      1 row in set (0.001 sec)
       
      MariaDB [test]> SELECT JSON_ARRAY(a) FROM t1;
      +---------------+
      | JSON_ARRAY(a) |
      +---------------+
      | ["a"]         |
      | ["ä"]         |
      +---------------+
      2 rows in set (0.000 sec)
       
      MariaDB [test]> select @@version;
      +--------------------------------------+
      | @@version                            |
      +--------------------------------------+
      | 10.5.8-MariaDB-1:10.5.8+maria~bionic |
      +--------------------------------------+
       
      MariaDB [(none)]> select @@character_set_server,@@character_set_client,@@character_set_results,@@collation_connection;
      +------------------------+------------------------+-------------------------+------------------------+
      | @@character_set_server | @@character_set_client | @@character_set_results | @@collation_connection |
      +------------------------+------------------------+-------------------------+------------------------+
      | utf8mb4                | utf8                   | utf8                    | utf8_general_ci        |
      +------------------------+------------------------+-------------------------+------------------------+
      1 row in set (0.000 sec)
      

      Attachments

        Issue Links

          Activity

            alice Alice Sherepa added a comment -

            MariaDB [test]> set names latin1;
            Query OK, 0 rows affected (0.000 sec)
             
            MariaDB [test]> SELECT JSON_ARRAYAGG('ä');
            +---------------------+
            | JSON_ARRAYAGG('ä')  |
            +---------------------+
            | ["ä"]               |
            +---------------------+
            1 row in set (0.000 sec)
             
            MariaDB [test]> set names utf8;
            Query OK, 0 rows affected (0.000 sec)
             
            MariaDB [test]> SELECT JSON_ARRAYAGG('ä');
            +---------------------+
            | JSON_ARRAYAGG('ä')  |
            +---------------------+
            | ["�"]                |
            +---------------------+
            1 row in set (0.000 sec)
             
            MariaDB [test]> SELECT 'ä';
            +----+
            | ä  |
            +----+
            | ä  |
            +----+
            1 row in set (0.000 sec)
            
            

            alice Alice Sherepa added a comment - MariaDB [test]> set names latin1; Query OK, 0 rows affected (0.000 sec)   MariaDB [test]> SELECT JSON_ARRAYAGG('ä'); +---------------------+ | JSON_ARRAYAGG('ä') | +---------------------+ | ["ä"] | +---------------------+ 1 row in set (0.000 sec)   MariaDB [test]> set names utf8; Query OK, 0 rows affected (0.000 sec)   MariaDB [test]> SELECT JSON_ARRAYAGG('ä'); +---------------------+ | JSON_ARRAYAGG('ä') | +---------------------+ | ["�"] | +---------------------+ 1 row in set (0.000 sec)   MariaDB [test]> SELECT 'ä'; +----+ | ä | +----+ | ä | +----+ 1 row in set (0.000 sec)
            pvgoran Pavel Goran added a comment -

            This bug makes JSON_ARRAYAGG pretty much unusable for working with string data. (It seems to work fine with data from JSON columns, though.)

            pvgoran Pavel Goran added a comment - This bug makes JSON_ARRAYAGG pretty much unusable for working with string data. (It seems to work fine with data from JSON columns, though.)
            pvgoran Pavel Goran added a comment -

            JSON_OBJECTAGG is apparently not affected by this bug. Which allows to use it as a partial work-around (with DISTINCT, ORDER BY and other JSON_OBJECTAGG's aggregation clauses unavailable):

            MariaDB [...]> SELECT JSON_EXTRACT(JSON_OBJECTAGG('1', a), '$.*') FROM t1;
            +---------------------------------------------+
            | JSON_EXTRACT(JSON_OBJECTAGG('1', a), '$.*') |
            +---------------------------------------------+
            | ["a", "ä"]                                  |
            +---------------------------------------------+
            1 row in set (0.000 sec)
             
            MariaDB [...]> select @@version;
            +---------------------+
            | @@version           |
            +---------------------+
            | 10.6.15-MariaDB-log |
            +---------------------+
            1 row in set (0.000 sec)
            

            pvgoran Pavel Goran added a comment - JSON_OBJECTAGG is apparently not affected by this bug. Which allows to use it as a partial work-around (with DISTINCT , ORDER BY and other JSON_OBJECTAGG 's aggregation clauses unavailable): MariaDB [...]> SELECT JSON_EXTRACT(JSON_OBJECTAGG('1', a), '$.*') FROM t1; +---------------------------------------------+ | JSON_EXTRACT(JSON_OBJECTAGG('1', a), '$.*') | +---------------------------------------------+ | ["a", "ä"] | +---------------------------------------------+ 1 row in set (0.000 sec)   MariaDB [...]> select @@version; +---------------------+ | @@version | +---------------------+ | 10.6.15-MariaDB-log | +---------------------+ 1 row in set (0.000 sec)

            People

              serg Sergei Golubchik
              thk Thomas K.
              Votes:
              3 Vote for this issue
              Watchers:
              6 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.