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

Table level CHECK(JSON_VALID()) constraint loses JSON property

    XMLWordPrintable

Details

    Description

      DROP TABLE IF EXISTS t1;
      CREATE TABLE t1 (
        a VARCHAR(1000),
        CONSTRAINT ensure_a_json CHECK (json_valid(a))
      );
      INSERT INTO t1 VALUES ('{"x": "y"}');
      SELECT JSON_OBJECT('a', a) FROM t1;
      

      +-------------------------+
      | JSON_OBJECT('a', a)     |
      +-------------------------+
      | {"a": "{\"x\": \"y\"}"} |
      +-------------------------+
      

      Notice, it did not recognize that the column is JSON and escapes it as plain text.

      If I run a similar script with Oracle, JSON is recognized and does not get escaped:

      DROP TABLE t1;
      CREATE TABLE t1 (
        a VARCHAR(1000),
        CONSTRAINT ensure_a_json CHECK (a IS JSON)
      );
      INSERT INTO t1 VALUES ('{"x": "y"}');
      SELECT JSON_OBJECT('a' VALUE a) FROM t1;
      

      JSON_OBJECT('A'VALUEA)
      {"a":{"x": "y"}}
      

      Attachments

        Issue Links

          Activity

            People

              bar Alexander Barkov
              bar Alexander Barkov
              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.