`CHECK` constraints on virtual columns silently dropped
zachmu opened this issue · comments
Zach Musgrave commented
Repro:
% dolt sql
# Welcome to the DoltSQL shell.
# Statements must be terminated with ';'.
# "exit" or "quit" (or Ctrl-D) to exit.
new3/main*> create table json_index (a int primary key, b json);
new3/main*> alter table json_index add column vcol int as (b->>"$.field");
new3/main*> alter table json_index add constraint check (vcol > 0);
new3/main*> show create table json_index;
+------------+--------------------------------------------------------------------------------+
| Table | Create Table |
+------------+--------------------------------------------------------------------------------+
| json_index | CREATE TABLE `json_index` ( |
| | `a` int NOT NULL, |
| | `b` json, |
| | `vcol` int GENERATED ALWAYS AS (json_unquote(json_extract(`b`, '$.field'))), |
| | PRIMARY KEY (`a`) |
| | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin |
+------------+--------------------------------------------------------------------------------+
1 row in set (0.01 sec)
The check is silently ignored, and values in violation can be inserted:
new3/main*> insert into json_index (a, b) values (1, '{"field": -1}');
(ok)
Correctly errors in MySQL:
mysql> insert into json_index (a, b) values (1, '{"field": -1}');
ERROR 3819 (HY000): Check constraint 'json_index_chk_1' is violated.