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

JSON casting using JSON_COMPACT doesn't always work with values from subqueries

    XMLWordPrintable

Details

    Description

      Given this test data

      CREATE TABLE json_test (a JSON, b JSON);
       
      INSERT INTO json_test VALUES ("[1,2,3]", '{"a":"foo"}');
      

      I can observe the following behavior:

      MariaDB [bugs]> SELECT JSON_OBJECT("a", JSON_COMPACT(a)) FROM (SELECT * FROM json_test) AS json_test_values;
      +-----------------------------------+
      | JSON_OBJECT("a", JSON_COMPACT(a)) |
      +-----------------------------------+
      | {"a": [1,2,3]}                    |
      +-----------------------------------+
      

      MariaDB [bugs]> SELECT JSON_OBJECT("a", JSON_COMPACT(a), "b", b) FROM (SELECT * FROM json_test) AS json_test_values;
      +-------------------------------------------+
      | JSON_OBJECT("a", JSON_COMPACT(a), "b", b) |
      +-------------------------------------------+
      | {"a": "[1,2,3]", "b": "{\"a\":\"foo\"}"}  |
      +-------------------------------------------+
      

      MariaDB [bugs]> SELECT JSON_OBJECT("a", JSON_COMPACT(a), "b", JSON_COMPACT(b)) FROM (SELECT * FROM json_test) AS json_test_values;
      +---------------------------------------------------------+
      | JSON_OBJECT("a", JSON_COMPACT(a), "b", JSON_COMPACT(b)) |
      +---------------------------------------------------------+
      | {"a": [1,2,3], "b": {"a":"foo"}}                        |
      +---------------------------------------------------------+
      

      The output of `JSON_COMPACT(a)` is sometimes treated as JSON and sometimes as a plain string

      Attachments

        Activity

          People

            anel Anel Husakovic
            pprkut Heinz Wiesinger
            Votes:
            1 Vote for this issue
            Watchers:
            7 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.