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

Crossed JSON_VALID constraint imposes JSON property to a wrong column

    XMLWordPrintable

Details

    • Bug
    • Status: Open (View Workflow)
    • Major
    • Resolution: Unresolved
    • 10.5, 10.6, 10.3(EOL), 10.4(EOL), 10.7(EOL), 10.8(EOL)
    • 10.5, 10.6
    • JSON
    • None

    Description

      Notice, in the CREATE statement below the constraint belonging to the column b:

      • Says that the column a is JSON
      • Says nothing that the column b itself is JSON

      However, the constraint actually imposes JSON format on the column b rather than column a.

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

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

      Notice:

      • a was treated as text
      • b was treated as JSON

      It's opposite to what the CHECK constraint says!

      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.