Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 43 additions & 28 deletions mysql-test/main/type_json.result
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,39 @@ create or replace table t1(a json);
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`a`))
`a` json CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
create or replace table t1(a json character set utf8);
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'character set utf8)' at line 1
create or replace table t1(a json default '{a:1}');
create or replace table t1(a json default '{"a":1}');
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT '{a:1}' CHECK (json_valid(`a`))
`a` json CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT '{"a":1}'
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
create or replace table t1(a json not null check (json_valid(a)));
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL CHECK (json_valid(`a`))
`a` json CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL CHECK (json_valid(`a`))
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
insert t1 values ('[]');
insert t1 values ('a');
ERROR 23000: CONSTRAINT `t1.a` failed for `test`.`t1`
ERROR 22007: Incorrect json value: 'a' for column `test`.`t1`.`a` at row 1
create or replace table t1(a json not null);
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL CHECK (json_valid(`a`))
`a` json CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
insert t1 values ('[]');
insert t1 values ('a');
ERROR 23000: CONSTRAINT `t1.a` failed for `test`.`t1`
ERROR 22007: Incorrect json value: 'a' for column `test`.`t1`.`a` at row 1
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;
Table Create Table
t1 CREATE TABLE `t1` (
`a` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT json_object('now',current_timestamp()) CHECK (json_valid(`a`))
`a` json CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT json_object('now',current_timestamp())
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
insert t1 values ();
select * from t1;
Expand All @@ -51,53 +50,59 @@ t
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`t` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`t`))
`t` json CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
show create table t2;
Table Create Table
t2 CREATE TABLE `t2` (
`a` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`a`)),
`a` json CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL,
`t` varchar(38) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
show create table t3;
Table Create Table
t3 CREATE TABLE `t3` (
`t` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`t`))
`t` json CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
drop table t1,t2,t3;
create table t1 (t json check (length(t) > 0));
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`t` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (octet_length(`t`) > 0)
`t` json CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (octet_length(`t`) > 0)
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
drop table t1;
create table t1 (t text) engine=myisam;
insert into t1 values ("{}"),("");
create table t2 (t json) select t from t1;
ERROR 23000: CONSTRAINT `t2.t` failed for `test`.`t2`
Warnings:
Warning 1292 Incorrect json value: '' for column `test`.`t2`.`t` at row 2
select * from t2;
t
{}

drop table t1, t2;
create table t1 (t text) engine=myisam;
insert into t1 values (""),("{}");
create table t2 (t json) select t from t1;
ERROR 22007: Incorrect json value: '' for column `test`.`t2`.`t` at row 1
select * from t2;
ERROR 42S02: Table 'test.t2' doesn't exist
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 ("{}");
insert into t1 values ("xxx");
ERROR 23000: CONSTRAINT `t1.a` failed for `test`.`t1`
ERROR 22007: Incorrect json value: 'xxx' for column `test`.`t1`.`a` at row 1
select * from t1;
a
{"now": 1}
{}
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT json_object('now',1) CHECK (json_valid(`a`))
`a` json CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT json_object('now',1) CHECK (json_valid(`a`))
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
drop table t1;
select cast('{a:1}' as text);
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'text)' at line 1
select cast('{a:1}' as json);
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'json)' at line 1
#
# Start of 10.5 tests
#
Expand All @@ -113,14 +118,14 @@ js3 TEXT CHECK (LENGTH(js2) > 0 OR JSON_VALID(js2))
) CHARACTER SET utf8;
SELECT * FROM t1;
Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr
def test t1 t1 js0 js0 252 (format=json) 4294967295 0 Y 144 0 192
def test t1 t1 js0 js0 252 4294967295 0 Y 144 0 192
def test t1 t1 js1 js1 252 (format=json) 196605 0 Y 16 0 192
def test t1 t1 js2 js2 252 (format=json) 196605 0 Y 16 0 192
def test t1 t1 js3 js3 252 196605 0 Y 16 0 192
js0 js1 js2 js3
SELECT js0, JSON_COMPACT(js0), JSON_COMPACT('{}') FROM t1;
Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr
def test t1 t1 js0 js0 252 (format=json) 4294967295 0 Y 144 0 192
def test t1 t1 js0 js0 252 4294967295 0 Y 144 0 192
def JSON_COMPACT(js0) 251 (format=json) 4294967295 0 Y 128 0 192
def JSON_COMPACT('{}') 253 (format=json) 6 0 Y 0 0 192
js0 JSON_COMPACT(js0) JSON_COMPACT('{}')
Expand All @@ -132,23 +137,23 @@ CREATE TABLE t1 (a JSON);
INSERT INTO t1 VALUES ('{"a":"b"}');
SELECT a, JSON_COMPACT(a), COALESCE(a) FROM t1;
Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr
def test t1 t1 a a 252 (format=json) 4294967295 9 Y 144 0 192
def test t1 t1 a a 252 4294967295 9 Y 144 0 192
def JSON_COMPACT(a) 251 (format=json) 4294967295 9 Y 128 0 192
def COALESCE(a) 251 (format=json) 4294967295 9 Y 128 39 192
def COALESCE(a) 251 4294967295 9 Y 128 39 192
a JSON_COMPACT(a) COALESCE(a)
{"a":"b"} {"a":"b"} {"a":"b"}
SELECT JSON_ARRAYAGG(1), JSON_ARRAYAGG(a) FROM t1;
Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr
def JSON_ARRAYAGG(1) 252 (format=json) 9437184 3 Y 0 0 192
def JSON_ARRAYAGG(a) 252 (format=json) 12582912 11 Y 128 0 192
def JSON_ARRAYAGG(a) 252 (format=json) 12582912 17 Y 128 0 192
JSON_ARRAYAGG(1) JSON_ARRAYAGG(a)
[1] [{"a":"b"}]
[1] ["{\"a\":\"b\"}"]
SELECT JSON_OBJECTAGG('a','b'), JSON_OBJECTAGG('a',a) FROM t1;
Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr
def JSON_OBJECTAGG('a','b') 252 (format=json) 9437184 9 Y 0 0 192
def JSON_OBJECTAGG('a',a) 252 (format=json) 12582912 15 Y 128 0 192
def JSON_OBJECTAGG('a',a) 252 (format=json) 12582912 21 Y 128 0 192
JSON_OBJECTAGG('a','b') JSON_OBJECTAGG('a',a)
{"a":"b"} {"a":{"a":"b"}}
{"a":"b"} {"a":"{\"a\":\"b\"}"}
DROP TABLE t1;
#
# MDEV-27018 IF and COALESCE lose "json" property
Expand Down Expand Up @@ -176,6 +181,16 @@ select json_arrayagg(v1_json) from v1;
json_arrayagg(v1_json)
[{"a": "b"}]
drop view v1;
create table t1 (a json);
insert into t1 values (777);
insert into t1 values (123.45);
insert into t1 values (true);
select * from t1;
a
777
123.45
1
drop table t1;
#
# End of 10.5 tests
#
33 changes: 23 additions & 10 deletions mysql-test/main/type_json.test
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@
create or replace table t1(a json);
show create table t1;

--error ER_PARSE_ERROR
create or replace table t1(a json character set utf8);

create or replace table t1(a json default '{a:1}');
create or replace table t1(a json default '{"a":1}');
show create table t1;


create or replace table t1(a json not null check (json_valid(a)));
show create table t1;
insert t1 values ('[]');
--error ER_CONSTRAINT_FAILED
--error ER_TRUNCATED_WRONG_VALUE
insert t1 values ('a');

create or replace table t1(a json not null);
show create table t1;
insert t1 values ('[]');
--error ER_CONSTRAINT_FAILED
--error ER_TRUNCATED_WRONG_VALUE
insert t1 values ('a');

set timestamp=unix_timestamp('2010:11:12 13:14:15');
Expand All @@ -45,7 +45,13 @@ 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;
select * from t2;
drop table t1, t2;

create table t1 (t text) engine=myisam;
insert into t1 values (""),("{}");
--error ER_TRUNCATED_WRONG_VALUE
create table t2 (t json) select t from t1;
--error ER_NO_SUCH_TABLE
select * from t2;
Expand All @@ -54,16 +60,16 @@ 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
--error ER_TRUNCATED_WRONG_VALUE
insert into t1 values ("xxx");
select * from t1;
show create table t1;
drop table t1;

--error ER_PARSE_ERROR
select cast('{a:1}' as text);
--error ER_PARSE_ERROR
select cast('{a:1}' as json);
#--error ER_PARSE_ERROR
#select cast('{a:1}' as text);
#--error ER_PARSE_ERROR
#select cast('{a:1}' as json);

--echo #
--echo # Start of 10.5 tests
Expand Down Expand Up @@ -135,6 +141,13 @@ select v1_json from v1;
select json_arrayagg(v1_json) from v1;
drop view v1;

create table t1 (a json);
insert into t1 values (777);
insert into t1 values (123.45);
insert into t1 values (true);
select * from t1;
drop table t1;

--echo #
--echo # End of 10.5 tests
--echo #
Loading
Loading