summaryrefslogtreecommitdiff
path: root/mysql-test/main/type_json.result
blob: 681bd42c4e3b96a2fd1b498b31d38191eba19179 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
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`))
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_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}');
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`))
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_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`))
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
insert t1 values ('[]');
insert t1 values ('a');
ERROR 23000: CONSTRAINT `t1.a` failed for `test`.`t1`
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`))
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
insert t1 values ('[]');
insert t1 values ('a');
ERROR 23000: CONSTRAINT `t1.a` failed for `test`.`t1`
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`))
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
insert t1 values ();
select * from t1;
a
{"now": "2010-11-12 13:14:15"}
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;
t
"foo"
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`))
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_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`)),
  `t` varchar(38) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_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`))
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_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)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_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`
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`
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`))
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_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
#
#
# MDEV-17832 Protocol: extensions for Pluggable types and JSON, GEOMETRY
#
SET NAMES utf8;
CREATE TABLE t1 (
js0 JSON,
js1 TEXT CHECK (JSON_VALID(js1)),
js2 TEXT CHECK (LENGTH(js2) > 0 AND JSON_VALID(js2)),
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	33
def	test	t1	t1	js1	js1	252 (format=json)	196605	0	Y	16	0	33
def	test	t1	t1	js2	js2	252 (format=json)	196605	0	Y	16	0	33
def	test	t1	t1	js3	js3	252	196605	0	Y	16	0	33
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	33
def					JSON_COMPACT(js0)	251 (format=json)	4294967295	0	Y	128	0	33
def					JSON_COMPACT('{}')	253 (format=json)	6	0	Y	0	0	33
js0	JSON_COMPACT(js0)	JSON_COMPACT('{}')
DROP TABLE t1;
#
# MDEV-27361 Hybrid functions with JSON arguments do not send format metadata
#
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	33
def					JSON_COMPACT(a)	251 (format=json)	4294967295	9	Y	128	0	33
def					COALESCE(a)	251 (format=json)	4294967295	9	Y	128	39	33
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	33
def					JSON_ARRAYAGG(a)	252 (format=json)	12582912	11	Y	128	0	33
JSON_ARRAYAGG(1)	JSON_ARRAYAGG(a)
[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	33
def					JSON_OBJECTAGG('a',a)	252 (format=json)	12582912	15	Y	128	0	33
JSON_OBJECTAGG('a','b')	JSON_OBJECTAGG('a',a)
{"a":"b"}	{"a":{"a":"b"}}
DROP TABLE t1;
#
# MDEV-27018 IF and COALESCE lose "json" property
#
SELECT json_object('a', (SELECT json_objectagg(b, c) FROM (SELECT 'b','c') d)) AS j FROM DUAL;
Catalog	Database	Table	Table_alias	Column	Column_alias	Type	Length	Max length	Is_null	Flags	Decimals	Charsetnr
def					j	250 (format=json)	9437283	16	Y	0	39	33
j
{"a": {"b":"c"}}
#
# End of 10.5 tests
#