|
| 1 | +create or replace table t1(a json); |
| 2 | +show create table t1; |
| 3 | +Table Create Table |
| 4 | +t1 CREATE TABLE `t1` ( |
| 5 | + `a` json CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL |
| 6 | +) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci |
| 7 | +create or replace table t1(a json character set utf8); |
| 8 | +show create table t1; |
| 9 | +Table Create Table |
| 10 | +t1 CREATE TABLE `t1` ( |
| 11 | + `a` json CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL |
| 12 | +) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci |
| 13 | +create or replace table t1(a json default '{a:1}'); |
| 14 | +show create table t1; |
| 15 | +Table Create Table |
| 16 | +t1 CREATE TABLE `t1` ( |
| 17 | + `a` json CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT '{a:1}' |
| 18 | +) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci |
| 19 | +create or replace table t1(a json not null); |
| 20 | +show create table t1; |
| 21 | +Table Create Table |
| 22 | +t1 CREATE TABLE `t1` ( |
| 23 | + `a` json CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL |
| 24 | +) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci |
| 25 | +insert t1 values ('[]'); |
| 26 | +insert t1 values ('a'); |
| 27 | +set timestamp=unix_timestamp('2010:11:12 13:14:15'); |
| 28 | +create or replace table t1(a json default(json_object('now', now()))); |
| 29 | +show create table t1; |
| 30 | +Table Create Table |
| 31 | +t1 CREATE TABLE `t1` ( |
| 32 | + `a` json CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT json_object('now',current_timestamp()) |
| 33 | +) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci |
| 34 | +insert t1 values (); |
| 35 | +select * from t1; |
| 36 | +a |
| 37 | +{"now": "2010-11-12 13:14:15"} |
| 38 | +drop table t1; |
| 39 | +create table t1 (t json) as select json_quote('foo') as t; |
| 40 | +create table t2 (a json) as select json_quote('foo') as t; |
| 41 | +create table t3 like t1; |
| 42 | +select * from t1; |
| 43 | +t |
| 44 | +"foo" |
| 45 | +show create table t1; |
| 46 | +Table Create Table |
| 47 | +t1 CREATE TABLE `t1` ( |
| 48 | + `t` json CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL |
| 49 | +) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci |
| 50 | +show create table t2; |
| 51 | +Table Create Table |
| 52 | +t2 CREATE TABLE `t2` ( |
| 53 | + `a` json CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL, |
| 54 | + `t` varchar(38) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL |
| 55 | +) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci |
| 56 | +show create table t3; |
| 57 | +Table Create Table |
| 58 | +t3 CREATE TABLE `t3` ( |
| 59 | + `t` json CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL |
| 60 | +) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci |
| 61 | +drop table t1,t2,t3; |
| 62 | +create table t1 (t json check (length(t) > 0)); |
| 63 | +show create table t1; |
| 64 | +Table Create Table |
| 65 | +t1 CREATE TABLE `t1` ( |
| 66 | + `t` json CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (octet_length(`t`) > 0) |
| 67 | +) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci |
| 68 | +drop table t1; |
| 69 | +create table t1 (t text) engine=myisam; |
| 70 | +insert into t1 values ("{}"),(""); |
| 71 | +create table t2 (t json) select t from t1; |
| 72 | +select * from t2; |
| 73 | +t |
| 74 | +{} |
| 75 | + |
| 76 | +drop table t1, t2; |
| 77 | +create or replace table t1(a json default(json_object('now', 1)) check (json_valid(a))); |
| 78 | +insert into t1 values (); |
| 79 | +insert into t1 values ("{}"); |
| 80 | +insert into t1 values ("xxx"); |
| 81 | +ERROR 23000: CONSTRAINT `t1.a` failed for `test`.`t1` |
| 82 | +select * from t1; |
| 83 | +a |
| 84 | +{"now": 1} |
| 85 | +{} |
| 86 | +show create table t1; |
| 87 | +Table Create Table |
| 88 | +t1 CREATE TABLE `t1` ( |
| 89 | + `a` json CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT json_object('now',1) CHECK (json_valid(`a`)) |
| 90 | +) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci |
| 91 | +drop table t1; |
| 92 | +# |
| 93 | +# Start of 10.5 tests |
| 94 | +# |
| 95 | +# |
| 96 | +# MDEV-17832 Protocol: extensions for Pluggable types and JSON, GEOMETRY |
| 97 | +# |
| 98 | +SET NAMES utf8; |
| 99 | +CREATE TABLE t1 ( |
| 100 | +js0 JSON, |
| 101 | +js1 TEXT CHECK (JSON_VALID(js1)), |
| 102 | +js2 TEXT CHECK (LENGTH(js2) > 0 AND JSON_VALID(js2)), |
| 103 | +js3 TEXT CHECK (LENGTH(js2) > 0 OR JSON_VALID(js2)) |
| 104 | +) CHARACTER SET utf8; |
| 105 | +SELECT * FROM t1; |
| 106 | +Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr |
| 107 | +def test t1 t1 js0 js0 252 4294967295 0 Y 144 0 192 |
| 108 | +def test t1 t1 js1 js1 252 (format=json) 196605 0 Y 16 0 192 |
| 109 | +def test t1 t1 js2 js2 252 (format=json) 196605 0 Y 16 0 192 |
| 110 | +def test t1 t1 js3 js3 252 196605 0 Y 16 0 192 |
| 111 | +js0 js1 js2 js3 |
| 112 | +SELECT js0, JSON_COMPACT(js0), JSON_COMPACT('{}') FROM t1; |
| 113 | +Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr |
| 114 | +def test t1 t1 js0 js0 252 4294967295 0 Y 144 0 192 |
| 115 | +def JSON_COMPACT(js0) 251 (format=json) 4294967295 0 Y 128 0 192 |
| 116 | +def JSON_COMPACT('{}') 253 (format=json) 6 0 Y 0 0 192 |
| 117 | +js0 JSON_COMPACT(js0) JSON_COMPACT('{}') |
| 118 | +DROP TABLE t1; |
| 119 | +# |
| 120 | +# MDEV-27361 Hybrid functions with JSON arguments do not send format metadata |
| 121 | +# |
| 122 | +CREATE TABLE t1 (a JSON); |
| 123 | +INSERT INTO t1 VALUES ('{"a":"b"}'); |
| 124 | +SELECT a, JSON_COMPACT(a), COALESCE(a) FROM t1; |
| 125 | +Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr |
| 126 | +def test t1 t1 a a 252 4294967295 9 Y 144 0 192 |
| 127 | +def JSON_COMPACT(a) 251 (format=json) 4294967295 9 Y 128 0 192 |
| 128 | +def COALESCE(a) 251 4294967295 9 Y 128 39 192 |
| 129 | +a JSON_COMPACT(a) COALESCE(a) |
| 130 | +{"a":"b"} {"a":"b"} {"a":"b"} |
| 131 | +SELECT JSON_ARRAYAGG(1), JSON_ARRAYAGG(a) FROM t1; |
| 132 | +Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr |
| 133 | +def JSON_ARRAYAGG(1) 252 (format=json) 9437184 3 Y 0 0 192 |
| 134 | +def JSON_ARRAYAGG(a) 252 (format=json) 12582912 17 Y 128 0 192 |
| 135 | +JSON_ARRAYAGG(1) JSON_ARRAYAGG(a) |
| 136 | +[1] ["{\"a\":\"b\"}"] |
| 137 | +SELECT JSON_OBJECTAGG('a','b'), JSON_OBJECTAGG('a',a) FROM t1; |
| 138 | +Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr |
| 139 | +def JSON_OBJECTAGG('a','b') 252 (format=json) 9437184 9 Y 0 0 192 |
| 140 | +def JSON_OBJECTAGG('a',a) 252 (format=json) 12582912 21 Y 128 0 192 |
| 141 | +JSON_OBJECTAGG('a','b') JSON_OBJECTAGG('a',a) |
| 142 | +{"a":"b"} {"a":"{\"a\":\"b\"}"} |
| 143 | +DROP TABLE t1; |
| 144 | +# |
| 145 | +# MDEV-27018 IF and COALESCE lose "json" property |
| 146 | +# |
| 147 | +SELECT json_object('a', (SELECT json_objectagg(b, c) FROM (SELECT 'b','c') d)) AS j FROM DUAL; |
| 148 | +Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr |
| 149 | +def j 250 (format=json) 9437310 16 Y 0 39 192 |
| 150 | +j |
| 151 | +{"a": {"b":"c"}} |
| 152 | +# |
| 153 | +# MDEV-26506 Over-quoted JSON when combining JSON_ARRAYAGG with JSON_OBJECT |
| 154 | +# |
| 155 | +# maintain JSON property through internal temporary tables |
| 156 | +create table t1 (a varchar(30)); |
| 157 | +insert into t1 values ('root'); |
| 158 | +select json_object('attr2',o) from (select a, json_arrayagg(json_object('attr1', a)) as o from t1) u; |
| 159 | +json_object('attr2',o) |
| 160 | +{"attr2": [{"attr1": "root"}]} |
| 161 | +drop table t1; |
| 162 | +create view v1 as select json_object(_latin1 'a', _latin1'b') as v1_json; |
| 163 | +select v1_json from v1; |
| 164 | +v1_json |
| 165 | +{"a": "b"} |
| 166 | +select json_arrayagg(v1_json) from v1; |
| 167 | +json_arrayagg(v1_json) |
| 168 | +[{"a": "b"}] |
| 169 | +drop view v1; |
| 170 | +# |
| 171 | +# End of 10.5 tests |
| 172 | +# |
0 commit comments