summaryrefslogtreecommitdiff
path: root/mysql-test/main/type_json.test
diff options
context:
space:
mode:
authorMonty <monty@mariadb.org>2019-02-13 19:39:41 +0200
committerMonty <monty@mariadb.org>2019-02-13 19:40:26 +0200
commit0f489494395a8cd6aeaf5943fea63a9e4465cabb (patch)
tree9562c59945740f74a8d15be8bcbaf213b7dc7796 /mysql-test/main/type_json.test
parent22feb179ae166500ec91feec6246c8154e33f9a2 (diff)
downloadmariadb-git-0f489494395a8cd6aeaf5943fea63a9e4465cabb.tar.gz
MDEV-13916 Enforce check constraint on JSON type
When creating a field of type JSON, it will be automatically converted to TEXT with CHECK (json_valid(`a`)), if there wasn't any previous check for the column. Additional things: - Added two bug fixes that was found while testing JSON. These bug fixes has also been pushed to 10.3 (with a test case), but as they where minimal and needed to get this task done and tested, the fixes are repeated here. - CREATE TABLE ... SELECT drops constraints for columns that are both in the create and select part. - If one has both a default expression and check constraint for a column, one can get the error "Expression for field `a` is refering to uninitialized field `a`. - Removed some duplicate MYSQL_PLUGIN_IMPORT symbols
Diffstat (limited to 'mysql-test/main/type_json.test')
-rw-r--r--mysql-test/main/type_json.test35
1 files changed, 35 insertions, 0 deletions
diff --git a/mysql-test/main/type_json.test b/mysql-test/main/type_json.test
index 0cff9366145..bd13dc1fcf4 100644
--- a/mysql-test/main/type_json.test
+++ b/mysql-test/main/type_json.test
@@ -17,12 +17,47 @@ insert t1 values ('[]');
--error ER_CONSTRAINT_FAILED
insert t1 values ('a');
+create or replace table t1(a json not null);
+show create table t1;
+insert t1 values ('[]');
+--error ER_CONSTRAINT_FAILED
+insert t1 values ('a');
+
set timestamp=unix_timestamp('2010:11:12 13:14:15');
create or replace table t1(a json default(json_object('now', now())));
show create table t1;
insert t1 values ();
select * from t1;
+drop table t1;
+
+create table t1 (t json) as select json_quote('foo') as t;
+create table t2 (a json) as select json_quote('foo') as t;
+create table t3 like t1;
+select * from t1;
+show create table t1;
+show create table t2;
+show create table t3;
+drop table t1,t2,t3;
+create table t1 (t json check (length(t) > 0));
+show create table t1;
+drop table t1;
+
+create table t1 (t text) engine=myisam;
+insert into t1 values ("{}"),("");
+--error ER_CONSTRAINT_FAILED
+create table t2 (t json) select t from t1;
+--error ER_NO_SUCH_TABLE
+select * from t2;
+drop table t1;
+
+create or replace table t1(a json default(json_object('now', 1)) check (json_valid(a)));
+insert into t1 values ();
+insert into t1 values ("{}");
+--error ER_CONSTRAINT_FAILED
+insert into t1 values ("xxx");
+select * from t1;
+show create table t1;
drop table t1;
--error ER_PARSE_ERROR