Skip to content

JSON schema validation with JSON_SCHEMA_VALID() #52779

@dveeden

Description

@dveeden

This improves MySQL 8.0 compatibility.

The JSON_SCHEMA_VALID() function is mostly useful in combination with a CHECK constraint.

mysql> CREATE TABLE t (
    ->   id INT PRIMARY KEY AUTO_INCREMENT, 
    ->   j JSON,
    ->   CHECK(JSON_SCHEMA_VALID('{"type": "array"}', j))
    -> );
Query OK, 0 rows affected (0.01 sec)

mysql> INSERT INTO t VALUES (1, '[0,1,2,3,4]');
Query OK, 1 row affected (0.01 sec)

mysql> INSERT INTO t VALUES (1, '{}');
ERROR 3819 (HY000): Check constraint 't_chk_1' is violated.

See also:

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions