Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON schema validation with JSON_SCHEMA_VALID() #52779

Closed
Tracked by #7968
dveeden opened this issue Apr 20, 2024 · 0 comments · Fixed by #52780
Closed
Tracked by #7968

JSON schema validation with JSON_SCHEMA_VALID() #52779

dveeden opened this issue Apr 20, 2024 · 0 comments · Fixed by #52780
Assignees
Labels
compatibility-mysql8 This is a compatibility issue with MySQL 8.0(but NOT 5.7) component/json sig/execution SIG execution type/compatibility type/enhancement

Comments

@dveeden
Copy link
Contributor

dveeden commented Apr 20, 2024

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:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compatibility-mysql8 This is a compatibility issue with MySQL 8.0(but NOT 5.7) component/json sig/execution SIG execution type/compatibility type/enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant