[MDEV-27358] Table level CHECK(JSON_VALID()) constraint loses JSON property Created: 2021-12-24  Updated: 2023-07-17

Status: Open
Project: MariaDB Server
Component/s: JSON
Affects Version/s: 10.3, 10.4, 10.5, 10.6, 10.7, 10.8
Fix Version/s: 10.5, 10.6

Type: Bug Priority: Major
Reporter: Alexander Barkov Assignee: Alexander Barkov
Resolution: Unresolved Votes: 0
Labels: Compatibility, Oracle

Issue Links:
Relates
relates to MDEV-27350 Complex CHECK constraint loses JSON p... Open
relates to MDEV-27018 IF and COALESCE lose "json" property Closed
relates to MDEV-27359 Crossed JSON_VALID constraint imposes... Open
relates to MDEV-27360 Column level CHECK constraint is not ... Open
relates to MDEV-27370 UNION looses JSON property Open

 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"}}



 Comments   
Comment by Shahriyar Imanov [ 2023-07-17 ]

Has this been fixed?

Generated at Thu Feb 08 09:52:19 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.