925 lines
39 KiB
Plaintext
925 lines
39 KiB
Plaintext
select json_object('k', -1) > json_object('k', 2);
|
|
json_object('k', -1) > json_object('k', 2)
|
|
0
|
|
select json_object('k', -1) < json_object('k', 2);
|
|
json_object('k', -1) < json_object('k', 2)
|
|
1
|
|
drop table if exists tx;
|
|
create table tx(a double, b int);
|
|
insert into tx values (3.0, 3);
|
|
select json_object('k', a) = json_object('k', b) from tx;
|
|
json_object('k', a) = json_object('k', b)
|
|
1
|
|
drop table if exists t;
|
|
CREATE TABLE t (`id` int NOT NULL AUTO_INCREMENT, `j` json, vc VARCHAR(500) , PRIMARY KEY (`id`));
|
|
INSERT INTO t ( id, j, vc ) VALUES
|
|
( 1, '{"a":1,"b":"qwe","c":[1,2,3,"123",null],"d":{"d1":1,"d2":2}}', '{"a":1,"b":"qwe","c":[1,2,3,"123",null],"d":{"d1":1,"d2":2}}' ),
|
|
( 2, '[1,2,34]', '{' );
|
|
select JSON_PRETTY(t.j), JSON_PRETTY(vc) from t where id = 1;
|
|
JSON_PRETTY(t.j) JSON_PRETTY(vc)
|
|
{
|
|
"a": 1,
|
|
"b": "qwe",
|
|
"c": [
|
|
1,
|
|
2,
|
|
3,
|
|
"123",
|
|
null
|
|
],
|
|
"d": {
|
|
"d1": 1,
|
|
"d2": 2
|
|
}
|
|
} {
|
|
"a": 1,
|
|
"b": "qwe",
|
|
"c": [
|
|
1,
|
|
2,
|
|
3,
|
|
"123",
|
|
null
|
|
],
|
|
"d": {
|
|
"d1": 1,
|
|
"d2": 2
|
|
}
|
|
}
|
|
select JSON_PRETTY(t.j), JSON_PRETTY(vc) from t where id = 2;
|
|
Error 3140 (22032): Invalid JSON text: The document root must not be followed by other values.
|
|
select JSON_PRETTY(t.j), JSON_PRETTY(vc) from t where id in (1,2);
|
|
Error 3140 (22032): Invalid JSON text: The document root must not be followed by other values.
|
|
select JSON_PRETTY("[1,2,3]}");
|
|
Error 3140 (22032): Invalid JSON text: The document root must not be followed by other values.
|
|
drop table if exists t;
|
|
CREATE TABLE t (
|
|
a int(11),
|
|
b varchar(100),
|
|
c decimal(3,2),
|
|
d json,
|
|
e date,
|
|
f time,
|
|
g datetime DEFAULT '2012-01-01',
|
|
h timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
i char(36),
|
|
j text(50));
|
|
insert into t values(1, 'ab', 5.5, '{"id": 1}', '2020-01-10', '11:12:13', '2020-01-11', '2020-10-18 00:00:00', 'first', 'json_arrayagg_test');
|
|
select a, json_arrayagg(b) from t group by a order by a;
|
|
a json_arrayagg(b)
|
|
1 ["ab"]
|
|
select b, json_arrayagg(c) from t group by b order by b;
|
|
b json_arrayagg(c)
|
|
ab [5.5]
|
|
select e, json_arrayagg(f) from t group by e order by e;
|
|
e json_arrayagg(f)
|
|
2020-01-10 ["11:12:13.000000"]
|
|
select f, json_arrayagg(g) from t group by f order by f;
|
|
f json_arrayagg(g)
|
|
11:12:13 ["2020-01-11 00:00:00.000000"]
|
|
select g, json_arrayagg(h) from t group by g order by g;
|
|
g json_arrayagg(h)
|
|
2020-01-11 00:00:00 ["2020-10-18 00:00:00.000000"]
|
|
select h, json_arrayagg(i) from t group by h order by h;
|
|
h json_arrayagg(i)
|
|
2020-10-18 00:00:00 ["first"]
|
|
select i, json_arrayagg(j) from t group by i order by i;
|
|
i json_arrayagg(j)
|
|
first ["json_arrayagg_test"]
|
|
select json_arrayagg(23) from t group by a order by a;
|
|
json_arrayagg(23)
|
|
[23]
|
|
select json_arrayagg(null) from t group by a order by a;
|
|
json_arrayagg(null)
|
|
[null]
|
|
drop table if exists t;
|
|
CREATE TABLE t (
|
|
a int(11),
|
|
b varchar(100),
|
|
c decimal(3,2),
|
|
d json,
|
|
e date,
|
|
f time,
|
|
g datetime DEFAULT '2012-01-01',
|
|
h timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
i char(36),
|
|
j text(50));
|
|
insert into t values(1, 'ab', 5.5, '{"id": 1}', '2020-01-10', '11:12:13', '2020-01-11', '2020-10-18 00:00:00', 'first', 'json_objectagg_test');
|
|
select json_objectagg(a, b) from t group by a order by a;
|
|
json_objectagg(a, b)
|
|
{"1": "ab"}
|
|
select json_objectagg(b, c) from t group by b order by b;
|
|
json_objectagg(b, c)
|
|
{"ab": 5.5}
|
|
select json_objectagg(e, f) from t group by e order by e;
|
|
json_objectagg(e, f)
|
|
{"2020-01-10": "11:12:13.000000"}
|
|
select json_objectagg(f, g) from t group by f order by f;
|
|
json_objectagg(f, g)
|
|
{"11:12:13": "2020-01-11 00:00:00.000000"}
|
|
select json_objectagg(g, h) from t group by g order by g;
|
|
json_objectagg(g, h)
|
|
{"2020-01-11 00:00:00": "2020-10-18 00:00:00.000000"}
|
|
select json_objectagg(h, i) from t group by h order by h;
|
|
json_objectagg(h, i)
|
|
{"2020-10-18 00:00:00": "first"}
|
|
select json_objectagg(i, j) from t group by i order by i;
|
|
json_objectagg(i, j)
|
|
{"first": "json_objectagg_test"}
|
|
select json_objectagg(a, null) from t group by a order by a;
|
|
json_objectagg(a, null)
|
|
{"1": null}
|
|
select a from (
|
|
select JSON_OBJECT('number', number, 'name', name) 'a' from
|
|
(
|
|
select 1 as number, 'name-1' as name union
|
|
(select 2, 'name-2' ) union
|
|
(select 3, 'name-3' ) union
|
|
(select 4, 'name-4' ) union
|
|
(select 5, 'name-5' ) union
|
|
(select 6, 'name-2' )
|
|
) temp1
|
|
) temp where a ->> '$.number' = 1;
|
|
a
|
|
{"name": "name-1", "number": 1}
|
|
DROP TABLE IF EXISTS my_collection;
|
|
CREATE TABLE `my_collection` ( `doc` json DEFAULT NULL, `_id` varchar(32) GENERATED ALWAYS AS (JSON_UNQUOTE(JSON_EXTRACT(doc,'$._id'))) STORED NOT NULL, PRIMARY KEY (`_id`));
|
|
UPDATE `my_collection` SET doc=JSON_SET(doc) WHERE (JSON_EXTRACT(doc,'$.name') = 'clare');
|
|
Error 1582 (42000): Incorrect parameter count in the call to native function 'json_set'
|
|
select json_valid(null);
|
|
json_valid(null)
|
|
NULL
|
|
select json_valid("null");
|
|
json_valid("null")
|
|
1
|
|
select json_valid(0);
|
|
json_valid(0)
|
|
0
|
|
select json_valid("0");
|
|
json_valid("0")
|
|
1
|
|
select json_valid("hello");
|
|
json_valid("hello")
|
|
0
|
|
select json_valid('"hello"');
|
|
json_valid('"hello"')
|
|
1
|
|
select json_valid('{"a":1}');
|
|
json_valid('{"a":1}')
|
|
1
|
|
select json_valid('{}');
|
|
json_valid('{}')
|
|
1
|
|
select json_valid('[]');
|
|
json_valid('[]')
|
|
1
|
|
select json_valid('2019-8-19');
|
|
json_valid('2019-8-19')
|
|
0
|
|
select json_valid('"2019-8-19"');
|
|
json_valid('"2019-8-19"')
|
|
1
|
|
select json_merge(1, 2);
|
|
Error 3146 (22032): Invalid data type for JSON data in argument 1 to function json_merge; a JSON string or JSON type is required.
|
|
select json_merge_preserve(1, 2);
|
|
Error 3146 (22032): Invalid data type for JSON data in argument 1 to function json_merge_preserve; a JSON string or JSON type is required.
|
|
select json_merge_patch(1, 2);
|
|
Error 3146 (22032): Invalid data type for JSON data in argument 1 to function json_merge_patch; a JSON string or JSON type is required.
|
|
select JSON_CONTAINS_PATH(1, 'one', '$.a');
|
|
Error 3146 (22032): Invalid data type for JSON data in argument 1 to function json_contains_path; a JSON string or JSON type is required.
|
|
select json_search(1, 'one', '$.a');
|
|
Error 3146 (22032): Invalid data type for JSON data in argument 1 to function json_search; a JSON string or JSON type is required.
|
|
select json_keys(1, '$.a');
|
|
Error 3146 (22032): Invalid data type for JSON data in argument 1 to function json_keys; a JSON string or JSON type is required.
|
|
select JSON_extract(1, '$.a');
|
|
Error 3146 (22032): Invalid data type for JSON data in argument 1 to function json_extract; a JSON string or JSON type is required.
|
|
DROP TABLE IF EXISTS table_json;
|
|
CREATE TABLE table_json(a json, b VARCHAR(255));
|
|
INSERT INTO table_json values('{"\\"hello\\"": "world", "a": [1, "2", {"aa": "bb"}, 4.0, {"aa": "cc"}], "b": true, "c": ["d"]}', '{"\\"hello\\"": "world", "a": [1, "2", {"aa": "bb"}, 4.0, {"aa": "cc"}], "b": true, "c": ["d"]}');
|
|
INSERT INTO table_json values('[{"a": 1, "b": true}, 3, 3.5, "hello, world", null, true]', '[{"a": 1, "b": true}, 3, 3.5, "hello, world", null, true]');
|
|
select json_type(a), json_type(b) from table_json;
|
|
json_type(a) json_type(b)
|
|
OBJECT OBJECT
|
|
ARRAY ARRAY
|
|
select json_quote();
|
|
Error 1582 (42000): Incorrect parameter count in the call to native function 'json_quote'
|
|
select json_quote('abc', 'def');
|
|
Error 1582 (42000): Incorrect parameter count in the call to native function 'json_quote'
|
|
select json_quote(NULL, 'def');
|
|
Error 1582 (42000): Incorrect parameter count in the call to native function 'json_quote'
|
|
select json_quote('abc', NULL);
|
|
Error 1582 (42000): Incorrect parameter count in the call to native function 'json_quote'
|
|
select json_unquote();
|
|
Error 1582 (42000): Incorrect parameter count in the call to native function 'json_unquote'
|
|
select json_unquote('abc', 'def');
|
|
Error 1582 (42000): Incorrect parameter count in the call to native function 'json_unquote'
|
|
select json_unquote(NULL, 'def');
|
|
Error 1582 (42000): Incorrect parameter count in the call to native function 'json_unquote'
|
|
select json_unquote('abc', NULL);
|
|
Error 1582 (42000): Incorrect parameter count in the call to native function 'json_unquote'
|
|
select json_quote(NULL);
|
|
json_quote(NULL)
|
|
NULL
|
|
select json_unquote(NULL);
|
|
json_unquote(NULL)
|
|
NULL
|
|
select json_quote('abc');
|
|
json_quote('abc')
|
|
"abc"
|
|
select json_quote(convert('"abc"' using ascii));
|
|
json_quote(convert('"abc"' using ascii))
|
|
"\"abc\""
|
|
select json_quote(convert('"abc"' using latin1));
|
|
json_quote(convert('"abc"' using latin1))
|
|
"\"abc\""
|
|
select json_quote(convert('"abc"' using utf8));
|
|
json_quote(convert('"abc"' using utf8))
|
|
"\"abc\""
|
|
select json_quote(convert('"abc"' using utf8mb4));
|
|
json_quote(convert('"abc"' using utf8mb4))
|
|
"\"abc\""
|
|
select json_unquote('abc');
|
|
json_unquote('abc')
|
|
abc
|
|
select json_unquote('"abc"');
|
|
json_unquote('"abc"')
|
|
abc
|
|
select json_unquote(convert('"abc"' using ascii));
|
|
json_unquote(convert('"abc"' using ascii))
|
|
abc
|
|
select json_unquote(convert('"abc"' using latin1));
|
|
json_unquote(convert('"abc"' using latin1))
|
|
abc
|
|
select json_unquote(convert('"abc"' using utf8));
|
|
json_unquote(convert('"abc"' using utf8))
|
|
abc
|
|
select json_unquote(convert('"abc"' using utf8mb4));
|
|
json_unquote(convert('"abc"' using utf8mb4))
|
|
abc
|
|
select json_quote('"');
|
|
json_quote('"')
|
|
"\""
|
|
select json_unquote('"');
|
|
json_unquote('"')
|
|
"
|
|
select json_unquote('""');
|
|
json_unquote('""')
|
|
|
|
select char_length(json_unquote('""'));
|
|
char_length(json_unquote('""'))
|
|
0
|
|
select json_unquote('"" ');
|
|
json_unquote('"" ')
|
|
""
|
|
select json_unquote(cast(json_quote('abc') as json));
|
|
json_unquote(cast(json_quote('abc') as json))
|
|
abc
|
|
select json_unquote(cast('{"abc": "foo"}' as json));
|
|
json_unquote(cast('{"abc": "foo"}' as json))
|
|
{"abc": "foo"}
|
|
select json_unquote(json_extract(cast('{"abc": "foo"}' as json), '$.abc'));
|
|
json_unquote(json_extract(cast('{"abc": "foo"}' as json), '$.abc'))
|
|
foo
|
|
select json_unquote('["a", "b", "c"]');
|
|
json_unquote('["a", "b", "c"]')
|
|
["a", "b", "c"]
|
|
select json_unquote(cast('["a", "b", "c"]' as json));
|
|
json_unquote(cast('["a", "b", "c"]' as json))
|
|
["a", "b", "c"]
|
|
select json_quote(convert(X'e68891' using utf8));
|
|
json_quote(convert(X'e68891' using utf8))
|
|
"我"
|
|
select json_quote(convert(X'e68891' using utf8mb4));
|
|
json_quote(convert(X'e68891' using utf8mb4))
|
|
"我"
|
|
select cast(json_quote(convert(X'e68891' using utf8)) as json);
|
|
cast(json_quote(convert(X'e68891' using utf8)) as json)
|
|
"我"
|
|
select json_unquote(convert(X'e68891' using utf8));
|
|
json_unquote(convert(X'e68891' using utf8))
|
|
我
|
|
select json_quote(json_quote(json_quote('abc')));
|
|
json_quote(json_quote(json_quote('abc')))
|
|
"\"\\\"abc\\\"\""
|
|
select json_unquote(json_unquote(json_unquote(json_quote(json_quote(json_quote('abc'))))));
|
|
json_unquote(json_unquote(json_unquote(json_quote(json_quote(json_quote('abc'))))))
|
|
abc
|
|
select json_quote(123);
|
|
Error 3064 (HY000): Incorrect type for argument 1 in function json_quote.
|
|
select json_quote(-100);
|
|
Error 3064 (HY000): Incorrect type for argument 1 in function json_quote.
|
|
select json_quote(123.123);
|
|
Error 3064 (HY000): Incorrect type for argument 1 in function json_quote.
|
|
select json_quote(-100.000);
|
|
Error 3064 (HY000): Incorrect type for argument 1 in function json_quote.
|
|
select json_quote(true);
|
|
Error 3064 (HY000): Incorrect type for argument 1 in function json_quote.
|
|
select json_quote(false);
|
|
Error 3064 (HY000): Incorrect type for argument 1 in function json_quote.
|
|
select json_quote(cast("{}" as JSON));
|
|
Error 3064 (HY000): Incorrect type for argument 1 in function json_quote.
|
|
select json_quote(cast("[]" as JSON));
|
|
Error 3064 (HY000): Incorrect type for argument 1 in function json_quote.
|
|
select json_quote(cast("2015-07-29" as date));
|
|
Error 3064 (HY000): Incorrect type for argument 1 in function json_quote.
|
|
select json_quote(cast("12:18:29.000000" as time));
|
|
Error 3064 (HY000): Incorrect type for argument 1 in function json_quote.
|
|
select json_quote(cast("2015-07-29 12:18:29.000000" as datetime));
|
|
Error 3064 (HY000): Incorrect type for argument 1 in function json_quote.
|
|
select json_unquote(123);
|
|
Error 3064 (HY000): Incorrect type for argument 1 in function json_unquote.
|
|
select json_unquote(-100);
|
|
Error 3064 (HY000): Incorrect type for argument 1 in function json_unquote.
|
|
select json_unquote(123.123);
|
|
Error 3064 (HY000): Incorrect type for argument 1 in function json_unquote.
|
|
select json_unquote(-100.000);
|
|
Error 3064 (HY000): Incorrect type for argument 1 in function json_unquote.
|
|
select json_unquote(true);
|
|
Error 3064 (HY000): Incorrect type for argument 1 in function json_unquote.
|
|
select json_unquote(false);
|
|
Error 3064 (HY000): Incorrect type for argument 1 in function json_unquote.
|
|
select json_unquote(cast("2015-07-29" as date));
|
|
Error 3064 (HY000): Incorrect type for argument 1 in function json_unquote.
|
|
select json_unquote(cast("12:18:29.000000" as time));
|
|
Error 3064 (HY000): Incorrect type for argument 1 in function json_unquote.
|
|
select json_unquote(cast("2015-07-29 12:18:29.000000" as datetime));
|
|
Error 3064 (HY000): Incorrect type for argument 1 in function json_unquote.
|
|
select json_extract(a, '$.a[1]'), json_extract(b, '$.b') from table_json;
|
|
json_extract(a, '$.a[1]') json_extract(b, '$.b')
|
|
"2" true
|
|
NULL NULL
|
|
select json_extract(json_set(a, '$.a[1]', 3), '$.a[1]'), json_extract(json_set(b, '$.b', false), '$.b') from table_json;
|
|
json_extract(json_set(a, '$.a[1]', 3), '$.a[1]') json_extract(json_set(b, '$.b', false), '$.b')
|
|
3 false
|
|
NULL NULL
|
|
select json_extract(json_insert(a, '$.a[1]', 3), '$.a[1]'), json_extract(json_insert(b, '$.b', false), '$.b') from table_json;
|
|
json_extract(json_insert(a, '$.a[1]', 3), '$.a[1]') json_extract(json_insert(b, '$.b', false), '$.b')
|
|
"2" true
|
|
NULL NULL
|
|
select json_extract(json_replace(a, '$.a[1]', 3), '$.a[1]'), json_extract(json_replace(b, '$.b', false), '$.b') from table_json;
|
|
json_extract(json_replace(a, '$.a[1]', 3), '$.a[1]') json_extract(json_replace(b, '$.b', false), '$.b')
|
|
3 false
|
|
NULL NULL
|
|
select json_extract(json_merge(a, cast(b as JSON)), '$[0].a[0]') from table_json;
|
|
json_extract(json_merge(a, cast(b as JSON)), '$[0].a[0]')
|
|
1
|
|
1
|
|
select json_extract(json_array(1,2,3), '$[1]');
|
|
json_extract(json_array(1,2,3), '$[1]')
|
|
2
|
|
select json_extract(json_object(1,2,3,4), '$."1"');
|
|
json_extract(json_object(1,2,3,4), '$."1"')
|
|
2
|
|
update table_json set a=json_set(a,'$.a',json_object('a',1,'b',2)) where json_extract(a,'$.a[1]') = '2';
|
|
select json_extract(a, '$.a.a'), json_extract(a, '$.a.b') from table_json;
|
|
json_extract(a, '$.a.a') json_extract(a, '$.a.b')
|
|
1 2
|
|
NULL NULL
|
|
select json_contains(NULL, '1'), json_contains('1', NULL), json_contains('1', '1', NULL);
|
|
json_contains(NULL, '1') json_contains('1', NULL) json_contains('1', '1', NULL)
|
|
NULL NULL NULL
|
|
select json_contains('{}','{}'), json_contains('[1]','1'), json_contains('[1]','"1"'), json_contains('[1,2,[1,[5,[3]]]]', '[1,3]', '$[2]'), json_contains('[1,2,[1,[5,{"a":[2,3]}]]]', '[1,{"a":[3]}]', "$[2]"), json_contains('{"a":1}', '{"a":1,"b":2}', "$");
|
|
json_contains('{}','{}') json_contains('[1]','1') json_contains('[1]','"1"') json_contains('[1,2,[1,[5,[3]]]]', '[1,3]', '$[2]') json_contains('[1,2,[1,[5,{"a":[2,3]}]]]', '[1,{"a":[3]}]', "$[2]") json_contains('{"a":1}', '{"a":1,"b":2}', "$")
|
|
1 1 0 1 1 0
|
|
select json_contains('{"a": 1}', '1', "$.c"), json_contains('{"a": [1, 2]}', '1', "$.a[2]"), json_contains('{"a": [1, {"a": 1}]}', '1', "$.a[1].b");
|
|
json_contains('{"a": 1}', '1', "$.c") json_contains('{"a": [1, 2]}', '1', "$.a[2]") json_contains('{"a": [1, {"a": 1}]}', '1', "$.a[1].b")
|
|
NULL NULL NULL
|
|
select json_contains('1','1','$.*');
|
|
Error 3149 (42000): In this situation, path expressions may not contain the * and ** tokens or an array range.
|
|
select
|
|
json_contains_path(NULL, 'one', "$.c"),
|
|
json_contains_path(NULL, 'all', "$.c"),
|
|
json_contains_path('{"a": 1}', NULL, "$.c"),
|
|
json_contains_path('{"a": 1}', 'one', NULL),
|
|
json_contains_path('{"a": 1}', 'all', NULL);
|
|
json_contains_path(NULL, 'one', "$.c") json_contains_path(NULL, 'all', "$.c") json_contains_path('{"a": 1}', NULL, "$.c") json_contains_path('{"a": 1}', 'one', NULL) json_contains_path('{"a": 1}', 'all', NULL)
|
|
NULL NULL NULL NULL NULL
|
|
select
|
|
json_contains_path('{"a": 1, "b": 2, "c": {"d": 4}}', 'one', '$.c.d'),
|
|
json_contains_path('{"a": 1, "b": 2, "c": {"d": 4}}', 'one', '$.a.d'),
|
|
json_contains_path('{"a": 1, "b": 2, "c": {"d": 4}}', 'all', '$.c.d'),
|
|
json_contains_path('{"a": 1, "b": 2, "c": {"d": 4}}', 'all', '$.a.d');
|
|
json_contains_path('{"a": 1, "b": 2, "c": {"d": 4}}', 'one', '$.c.d') json_contains_path('{"a": 1, "b": 2, "c": {"d": 4}}', 'one', '$.a.d') json_contains_path('{"a": 1, "b": 2, "c": {"d": 4}}', 'all', '$.c.d') json_contains_path('{"a": 1, "b": 2, "c": {"d": 4}}', 'all', '$.a.d')
|
|
1 0 1 0
|
|
select
|
|
json_contains_path('{"a": 1, "b": 2, "c": {"d": 4}}', 'one', '$.a', '$.e'),
|
|
json_contains_path('{"a": 1, "b": 2, "c": {"d": 4}}', 'one', '$.a', '$.b'),
|
|
json_contains_path('{"a": 1, "b": 2, "c": {"d": 4}}', 'all', '$.a', '$.e'),
|
|
json_contains_path('{"a": 1, "b": 2, "c": {"d": 4}}', 'all', '$.a', '$.b');
|
|
json_contains_path('{"a": 1, "b": 2, "c": {"d": 4}}', 'one', '$.a', '$.e') json_contains_path('{"a": 1, "b": 2, "c": {"d": 4}}', 'one', '$.a', '$.b') json_contains_path('{"a": 1, "b": 2, "c": {"d": 4}}', 'all', '$.a', '$.e') json_contains_path('{"a": 1, "b": 2, "c": {"d": 4}}', 'all', '$.a', '$.b')
|
|
1 1 0 1
|
|
select
|
|
json_contains_path('{"a": 1, "b": 2, "c": {"d": 4}}', 'one', '$.*'),
|
|
json_contains_path('{"a": 1, "b": 2, "c": {"d": 4}}', 'one', '$[*]'),
|
|
json_contains_path('{"a": 1, "b": 2, "c": {"d": 4}}', 'all', '$.*'),
|
|
json_contains_path('{"a": 1, "b": 2, "c": {"d": 4}}', 'all', '$[*]');
|
|
json_contains_path('{"a": 1, "b": 2, "c": {"d": 4}}', 'one', '$.*') json_contains_path('{"a": 1, "b": 2, "c": {"d": 4}}', 'one', '$[*]') json_contains_path('{"a": 1, "b": 2, "c": {"d": 4}}', 'all', '$.*') json_contains_path('{"a": 1, "b": 2, "c": {"d": 4}}', 'all', '$[*]')
|
|
1 0 1 0
|
|
select
|
|
json_keys('[]'),
|
|
json_keys('{}'),
|
|
json_keys('{"a": 1, "b": 2}'),
|
|
json_keys('{"a": {"c": 3}, "b": 2}'),
|
|
json_keys('{"a": {"c": 3}, "b": 2}', "$.a");
|
|
json_keys('[]') json_keys('{}') json_keys('{"a": 1, "b": 2}') json_keys('{"a": {"c": 3}, "b": 2}') json_keys('{"a": {"c": 3}, "b": 2}', "$.a")
|
|
NULL [] ["a", "b"] ["a", "b"] ["c"]
|
|
SELECT JSON_KEYS('[{"X": 1}, {"Y": 2}]', '$[1]');
|
|
JSON_KEYS('[{"X": 1}, {"Y": 2}]', '$[1]')
|
|
["Y"]
|
|
SELECT JSON_KEYS('[{"A1": 1, "B1": 2, "C1": 3}, {"A2": 10, "B2": 20, "C2": {"D": 4}}, {"A3": 1, "B3": 2, "C3": 6}]', '$[1]');
|
|
JSON_KEYS('[{"A1": 1, "B1": 2, "C1": 3}, {"A2": 10, "B2": 20, "C2": {"D": 4}}, {"A3": 1, "B3": 2, "C3": 6}]', '$[1]')
|
|
["A2", "B2", "C2"]
|
|
SELECT JSON_KEYS('[{"A": 1, "B": 2, "C": {"D": 3}}, {"A": 10, "B": 20, "C": {"D": 4}}, {"A": 1, "B": 2, "C": [{"D": 5}, {"E": 55}]}]', '$[last].C');
|
|
JSON_KEYS('[{"A": 1, "B": 2, "C": {"D": 3}}, {"A": 10, "B": 20, "C": {"D": 4}}, {"A": 1, "B": 2, "C": [{"D": 5}, {"E": 55}]}]', '$[last].C')
|
|
NULL
|
|
SELECT JSON_KEYS('[{"A": 1, "B": 2, "C": {"D": 3}}, {"A": 10, "B": 20, "C": {"D": 4}}, {"A": 1, "B": 2, "C": [{"D": 5}, {"E": 55}]}]', '$[last].C[1]');
|
|
JSON_KEYS('[{"A": 1, "B": 2, "C": {"D": 3}}, {"A": 10, "B": 20, "C": {"D": 4}}, {"A": 1, "B": 2, "C": [{"D": 5}, {"E": 55}]}]', '$[last].C[1]')
|
|
["E"]
|
|
SELECT JSON_KEYS('[{"A": 1, "B": 2}, {"C": 3, "D": [{"F": 5}, {"E": 55}]}]', '$[1].D[1]');
|
|
JSON_KEYS('[{"A": 1, "B": 2}, {"C": 3, "D": [{"F": 5}, {"E": 55}]}]', '$[1].D[1]')
|
|
["E"]
|
|
SELECT JSON_KEYS('[{"X": 1}, {"Y": {"a": 1, "b": 2, "c": 3}}]', '$[1].Y');
|
|
JSON_KEYS('[{"X": 1}, {"Y": {"a": 1, "b": 2, "c": 3}}]', '$[1].Y')
|
|
["a", "b", "c"]
|
|
SELECT JSON_KEYS('[{"X": 1}, {"Y": [a,b,c]}]', '$.Y');
|
|
Error 3140 (22032): Invalid JSON text: The document root must not be followed by other values.
|
|
select
|
|
json_length('1'),
|
|
json_length('{}'),
|
|
json_length('[]'),
|
|
json_length('{"a": 1}'),
|
|
json_length('{"a": 1, "b": 2}'),
|
|
json_length('[1, 2, 3]'),
|
|
json_length('{}', '$'),
|
|
json_length('1', '$'),
|
|
json_length(null, '$'),
|
|
json_length(null, 'fdfd'),
|
|
json_length('{}', null),
|
|
json_length('1', '$.a'),
|
|
json_length('{}', '$.a');
|
|
json_length('1') json_length('{}') json_length('[]') json_length('{"a": 1}') json_length('{"a": 1, "b": 2}') json_length('[1, 2, 3]') json_length('{}', '$') json_length('1', '$') json_length(null, '$') json_length(null, 'fdfd') json_length('{}', null) json_length('1', '$.a') json_length('{}', '$.a')
|
|
1 0 0 1 2 3 0 1 NULL NULL NULL NULL NULL
|
|
select json_length('{}', 'fsdfds');
|
|
Error 3143 (42000): Invalid JSON path expression. The error is around character position 1.
|
|
select json_length('1', 'fsdfds');
|
|
Error 3143 (42000): Invalid JSON path expression. The error is around character position 1.
|
|
select json_array(922337203685477580) = json_array(922337203685477581);
|
|
json_array(922337203685477580) = json_array(922337203685477581)
|
|
0
|
|
select json_overlaps('[[1,2], 3]', '[1, 3]');
|
|
json_overlaps('[[1,2], 3]', '[1, 3]')
|
|
1
|
|
select json_overlaps('[{"a":1}]', '{"a":1}');
|
|
json_overlaps('[{"a":1}]', '{"a":1}')
|
|
1
|
|
select json_overlaps('{"a":1}', '[{"a":1}]');
|
|
json_overlaps('{"a":1}', '[{"a":1}]')
|
|
1
|
|
select json_overlaps('[1,[2,3]]', '[[1,2], 3]');
|
|
json_overlaps('[1,[2,3]]', '[[1,2], 3]')
|
|
0
|
|
select json_overlaps('{"a":[1,2]}', '{"a":[2,1]}');
|
|
json_overlaps('{"a":[1,2]}', '{"a":[2,1]}')
|
|
0
|
|
select json_overlaps('{"a":[1,2]}', '{"a":[2,1]}');
|
|
json_overlaps('{"a":[1,2]}', '{"a":[2,1]}')
|
|
0
|
|
drop table if exists tx1;
|
|
create table tx1(id int key, a double, b double, c double, d double);
|
|
insert into tx1 values (1, 0.1, 0.2, 0.3, 0.0);
|
|
select a+b, c from tx1;
|
|
a+b c
|
|
0.30000000000000004 0.3
|
|
select json_array(a+b) = json_array(c) from tx1;
|
|
json_array(a+b) = json_array(c)
|
|
0
|
|
SELECT '{"a":1}' MEMBER OF('{"a":1}');
|
|
'{"a":1}' MEMBER OF('{"a":1}')
|
|
0
|
|
SELECT '{"a":1}' MEMBER OF('[{"a":1}]');
|
|
'{"a":1}' MEMBER OF('[{"a":1}]')
|
|
0
|
|
SELECT 1 MEMBER OF('1');
|
|
1 MEMBER OF('1')
|
|
1
|
|
SELECT '{"a":1}' MEMBER OF('{"a":1}');
|
|
'{"a":1}' MEMBER OF('{"a":1}')
|
|
0
|
|
SELECT '[4,5]' MEMBER OF('[[3,4],[4,5]]');
|
|
'[4,5]' MEMBER OF('[[3,4],[4,5]]')
|
|
0
|
|
SELECT '[4,5]' MEMBER OF('[[3,4],"[4,5]"]');
|
|
'[4,5]' MEMBER OF('[[3,4],"[4,5]"]')
|
|
1
|
|
drop table if exists t;
|
|
create table t(a enum('a', 'b'), b time, c binary(10));
|
|
insert into t values ('a', '11:00:00', 'a');
|
|
select a member of ('"a"') from t;
|
|
a member of ('"a"')
|
|
1
|
|
select b member of (json_array(cast('11:00:00' as time))) from t;
|
|
b member of (json_array(cast('11:00:00' as time)))
|
|
1
|
|
select b member of ('"11:00:00"') from t;
|
|
b member of ('"11:00:00"')
|
|
0
|
|
select c member of ('"a"') from t;
|
|
c member of ('"a"')
|
|
0
|
|
select 'a' member of ('a');
|
|
Error 3140 (22032): Invalid JSON text: The document root must not be followed by other values.
|
|
drop table if exists t;
|
|
create table t(a char(20), b blob);
|
|
insert into t values ('a string', 'a binary string');
|
|
select json_object(a, b) from t;
|
|
json_object(a, b)
|
|
{"a string": "base64:type252:YSBiaW5hcnkgc3RyaW5n"}
|
|
select json_objectagg(a, b) from t;
|
|
json_objectagg(a, b)
|
|
{"a string": "base64:type252:YSBiaW5hcnkgc3RyaW5n"}
|
|
select json_object(b, a) from t;
|
|
Error 3144 (22032): Cannot create a JSON value from a string with CHARACTER SET 'binary'.
|
|
select json_objectagg(b, a) from t;
|
|
Error 3144 (22032): Cannot create a JSON value from a string with CHARACTER SET 'binary'.
|
|
select cast(cast(b'010101' as json) as signed);
|
|
cast(cast(b'010101' as json) as signed)
|
|
0
|
|
Level Code Message
|
|
Warning 1292 Truncated incorrect INTEGER value: '"base64:type253:FQ=="'
|
|
select cast(json_extract(json_objectagg('a', b'010101'), '$.a') as signed);
|
|
cast(json_extract(json_objectagg('a', b'010101'), '$.a') as signed)
|
|
0
|
|
Level Code Message
|
|
Warning 1292 Truncated incorrect INTEGER value: '"base64:type253:FQ=="'
|
|
select cast(json_extract(json_objectagg('a', b'010101'), '$.a') as double);
|
|
cast(json_extract(json_objectagg('a', b'010101'), '$.a') as double)
|
|
0
|
|
Level Code Message
|
|
Warning 1292 Truncated incorrect FLOAT value: '"base64:type253:FQ=="'
|
|
drop table if exists t;
|
|
create table t(a JSON);
|
|
insert into t values ('{}'), ('true'), ('5');
|
|
select * from t where a = TRUE;
|
|
a
|
|
true
|
|
select * from t where a < 6;
|
|
a
|
|
5
|
|
select * from t where a > 5;
|
|
a
|
|
{}
|
|
true
|
|
drop table if exists t;
|
|
create table t(a JSON);
|
|
insert into t with recursive c1 as (select cast(1 as signed) c, json_array(1) as a
|
|
union
|
|
select c + 1, json_array_insert(a, concat('$', repeat('[0]', c)), json_array(1))
|
|
from c1
|
|
where c < 101)
|
|
select a from c1 where c > 100;
|
|
Error 3157 (22032): The JSON document exceeds the maximum depth.
|
|
insert into t with recursive c1 as (select cast(1 as signed) c, json_array(1) as a
|
|
union
|
|
select c + 1, json_array_insert(a, concat('$', repeat('[0]', c)), json_array(1))
|
|
from c1
|
|
where c < 100)
|
|
select a from c1 where c > 99;
|
|
select json_array(a, 1) from t;
|
|
Error 3157 (22032): The JSON document exceeds the maximum depth.
|
|
select json_object(1, a) from t;
|
|
Error 3157 (22032): The JSON document exceeds the maximum depth.
|
|
select json_set(a, concat('$', repeat('[0]', 100)), json_array(json_array(3))) from t;
|
|
Error 3157 (22032): The JSON document exceeds the maximum depth.
|
|
select json_array_append(a, concat('$', repeat('[0]', 100)), 1) from t;
|
|
Error 3157 (22032): The JSON document exceeds the maximum depth.
|
|
select json_storage_free(NULL);
|
|
json_storage_free(NULL)
|
|
NULL
|
|
select json_storage_free('{}');
|
|
json_storage_free('{}')
|
|
0
|
|
select json_storage_free('1');
|
|
json_storage_free('1')
|
|
0
|
|
select json_storage_free('{"a": "b"}');
|
|
json_storage_free('{"a": "b"}')
|
|
0
|
|
select json_storage_free('{"c":["a","b"]');
|
|
Error 3140 (22032): Invalid JSON text: The document root must not be followed by other values.
|
|
select json_extract('[{"a": [1,2,3,4]}]', '$[0] . a[last]');
|
|
json_extract('[{"a": [1,2,3,4]}]', '$[0] . a[last]')
|
|
4
|
|
select json_extract('[{"a": [1,2,3,4]}]', '$[0] . a [last - 1]');
|
|
json_extract('[{"a": [1,2,3,4]}]', '$[0] . a [last - 1]')
|
|
3
|
|
select json_extract('[{"a": [1,2,3,4]}]', '$[0].a [last - 100]');
|
|
json_extract('[{"a": [1,2,3,4]}]', '$[0].a [last - 100]')
|
|
NULL
|
|
select json_extract('[{"a": [1,2,3,4]}]', '$[0].a[1 to last]');
|
|
json_extract('[{"a": [1,2,3,4]}]', '$[0].a[1 to last]')
|
|
[2, 3, 4]
|
|
select json_extract('[{"a": [1,2,3,4]}]', '$[0].a[1 to last - 1]');
|
|
json_extract('[{"a": [1,2,3,4]}]', '$[0].a[1 to last - 1]')
|
|
[2, 3]
|
|
select json_extract('[{"a": [1,2,3,4]}]', '$[0].a[1 to last - 100]');
|
|
json_extract('[{"a": [1,2,3,4]}]', '$[0].a[1 to last - 100]')
|
|
NULL
|
|
select json_extract('[{"a": [1,2,3,4]}]', '$[0].a[1 to 100]');
|
|
json_extract('[{"a": [1,2,3,4]}]', '$[0].a[1 to 100]')
|
|
[2, 3, 4]
|
|
select json_extract('[{"a": [1,2,3,4]}]', '$[0].a[0 to last]');
|
|
json_extract('[{"a": [1,2,3,4]}]', '$[0].a[0 to last]')
|
|
[1, 2, 3, 4]
|
|
select json_extract('[{"a": [1,2,3,4]}]', '$[0].a[0 to 2]');
|
|
json_extract('[{"a": [1,2,3,4]}]', '$[0].a[0 to 2]')
|
|
[1, 2, 3]
|
|
drop table if exists t;
|
|
create table t (a json);
|
|
insert into t values ('"-1"');
|
|
insert into t values ('"18446744073709551615"');
|
|
insert into t values ('"18446744073709552000"');
|
|
select a, cast(a as unsigned) from t;
|
|
a cast(a as unsigned)
|
|
"-1" 18446744073709551615
|
|
"18446744073709551615" 18446744073709551615
|
|
"18446744073709552000" 18446744073709551615
|
|
select a, cast(a as signed) from t;
|
|
a cast(a as signed)
|
|
"-1" -1
|
|
"18446744073709551615" -1
|
|
"18446744073709552000" -1
|
|
select cast(binary 'aa' as json);
|
|
cast(binary 'aa' as json)
|
|
"base64:type254:YWE="
|
|
drop table if exists t;
|
|
create table t (vb VARBINARY(10), b BINARY(10), vc VARCHAR(10), c CHAR(10));
|
|
insert into t values ('1', '1', '1', '1');
|
|
select cast(vb as json), cast(b as json), cast(vc as json), cast(c as json) from t;
|
|
cast(vb as json) cast(b as json) cast(vc as json) cast(c as json)
|
|
"base64:type15:MQ==" "base64:type254:MQAAAAAAAAAAAA==" 1 1
|
|
select 1 from t where cast(vb as json) = '1';
|
|
1
|
|
select 1 from t where cast(b as json) = '1';
|
|
1
|
|
select 1 from t where cast(vc as json) = '1';
|
|
1
|
|
select 1 from t where cast(c as json) = '1';
|
|
1
|
|
select 1 from t where cast(BINARY vc as json) = '1';
|
|
1
|
|
select 1 from t where cast(BINARY c as json) = '1';
|
|
1
|
|
drop table if exists t;
|
|
create table t (j json);
|
|
insert into t values (cast(cast("2024-10-24 11:11:11.12346" as datetime(6)) as json));
|
|
select cast(j as datetime(6)) from t;
|
|
cast(j as datetime(6))
|
|
2024-10-24 11:11:11.123460
|
|
select cast(j as datetime(3)) from t;
|
|
cast(j as datetime(3))
|
|
2024-10-24 11:11:11.123
|
|
select cast(j as datetime) from t;
|
|
cast(j as datetime)
|
|
2024-10-24 11:11:11
|
|
SELECT JSON_SCHEMA_VALID(NULL, NULL);
|
|
JSON_SCHEMA_VALID(NULL, NULL)
|
|
NULL
|
|
SELECT JSON_SCHEMA_VALID('{}', NULL);
|
|
JSON_SCHEMA_VALID('{}', NULL)
|
|
NULL
|
|
SELECT JSON_SCHEMA_VALID(NULL, '{}');
|
|
JSON_SCHEMA_VALID(NULL, '{}')
|
|
NULL
|
|
SELECT JSON_SCHEMA_VALID(NULL, '');
|
|
JSON_SCHEMA_VALID(NULL, '')
|
|
NULL
|
|
SELECT JSON_SCHEMA_VALID('{"required": ["a","b"]}', '{"a": 5,"b": 6}');
|
|
JSON_SCHEMA_VALID('{"required": ["a","b"]}', '{"a": 5,"b": 6}')
|
|
1
|
|
SELECT JSON_SCHEMA_VALID('{"required": ["a","b"]}', '{"a": 5,"c": 6}');
|
|
JSON_SCHEMA_VALID('{"required": ["a","b"]}', '{"a": 5,"c": 6}')
|
|
0
|
|
SELECT JSON_SCHEMA_VALID('{"type": "object"}', '{}');
|
|
JSON_SCHEMA_VALID('{"type": "object"}', '{}')
|
|
1
|
|
SELECT JSON_SCHEMA_VALID('{"type": "object"}', '"foo"');
|
|
JSON_SCHEMA_VALID('{"type": "object"}', '"foo"')
|
|
0
|
|
SELECT JSON_SCHEMA_VALID('{"properties": {"a": {"type": "number"}}}', '{}');
|
|
JSON_SCHEMA_VALID('{"properties": {"a": {"type": "number"}}}', '{}')
|
|
1
|
|
SELECT JSON_SCHEMA_VALID('{"properties": {"a": {"type": "number"}}}', '{"a": "foo"}');
|
|
JSON_SCHEMA_VALID('{"properties": {"a": {"type": "number"}}}', '{"a": "foo"}')
|
|
0
|
|
SELECT JSON_SCHEMA_VALID('{"properties": {"a": {"type": "number"}}}', '{"a": 5}');
|
|
JSON_SCHEMA_VALID('{"properties": {"a": {"type": "number"}}}', '{"a": 5}')
|
|
1
|
|
SELECT JSON_SCHEMA_VALID('{"properties": {"a": {"type": "number", "minimum": 5}}}', '{"a": 5}');
|
|
JSON_SCHEMA_VALID('{"properties": {"a": {"type": "number", "minimum": 5}}}', '{"a": 5}')
|
|
1
|
|
SELECT JSON_SCHEMA_VALID('{"properties": {"a": {"type": "number", "minimum": 5}}}', '{"a": 6}');
|
|
JSON_SCHEMA_VALID('{"properties": {"a": {"type": "number", "minimum": 5}}}', '{"a": 6}')
|
|
1
|
|
SELECT JSON_SCHEMA_VALID('{"properties": {"a": {"pattern": "^a"}}}', '{"a": "abc"}');
|
|
JSON_SCHEMA_VALID('{"properties": {"a": {"pattern": "^a"}}}', '{"a": "abc"}')
|
|
1
|
|
SELECT JSON_SCHEMA_VALID('{"properties": {"a": {"pattern": "^a"}}}', '{"a": "cba"}');
|
|
JSON_SCHEMA_VALID('{"properties": {"a": {"pattern": "^a"}}}', '{"a": "cba"}')
|
|
0
|
|
SELECT JSON_QUOTE("<html>");
|
|
JSON_QUOTE("<html>")
|
|
"<html>"
|
|
SELECT JSON_QUOTE("&");
|
|
JSON_QUOTE("&")
|
|
"&"
|
|
SELECT JSON_QUOTE(CONVERT(0x10 USING utf8mb4));
|
|
JSON_QUOTE(CONVERT(0x10 USING utf8mb4))
|
|
"\u0010"
|
|
SELECT JSON_QUOTE("O'Neil");
|
|
JSON_QUOTE("O'Neil")
|
|
"O'Neil"
|
|
SELECT JSON_CONTAINS(123, '');
|
|
Error 3146 (22032): Invalid data type for JSON data in argument 1 to function json_contains; a JSON string or JSON type is required.
|
|
SELECT JSON_CONTAINS('{}', 123);
|
|
Error 3146 (22032): Invalid data type for JSON data in argument 2 to function json_contains; a JSON string or JSON type is required.
|
|
SELECT JSON_OVERLAPS(123, '');
|
|
Error 3146 (22032): Invalid data type for JSON data in argument 1 to function json_overlaps; a JSON string or JSON type is required.
|
|
SELECT JSON_OVERLAPS('{}', 123);
|
|
Error 3146 (22032): Invalid data type for JSON data in argument 2 to function json_overlaps; a JSON string or JSON type is required.
|
|
SELECT 'abc' MEMBER OF(123);
|
|
Error 3146 (22032): Invalid data type for JSON data in argument 2 to function member of; a JSON string or JSON type is required.
|
|
SELECT JSON_SEARCH('{}',3,4);
|
|
Error 3154 (42000): The oneOrAll argument to json_search may take these values: 'one' or 'all'.
|
|
SELECT JSON_ARRAY_APPEND('[]','abc','def');
|
|
Error 3143 (42000): Invalid JSON path expression. The error is around character position 1.
|
|
SELECT JSON_ARRAY_INSERT('{}','abc','def');
|
|
Error 3143 (42000): Invalid JSON path expression. The error is around character position 1.
|
|
SELECT JSON_REMOVE('{}','$');
|
|
Error 3153 (42000): The path expression '$' is not allowed in this context.
|
|
SELECT JSON_REMOVE('{}','$.*');
|
|
Error 3149 (42000): In this situation, path expressions may not contain the * and ** tokens or an array range.
|
|
SELECT JSON_SET('{}','$.*','');
|
|
Error 3149 (42000): In this situation, path expressions may not contain the * and ** tokens or an array range.
|
|
SELECT JSON_CONTAINS_PATH('{}', 'on', '$.a');
|
|
Error 3154 (42000): The oneOrAll argument to json_contains_path may take these values: 'one' or 'all'.
|
|
SELECT JSON_SEARCH('{}', 'on', '$.a');
|
|
Error 3154 (42000): The oneOrAll argument to json_search may take these values: 'one' or 'all'.
|
|
SELECT JSON_OBJECT(NULL,'abc');
|
|
Error 3158 (22032): JSON documents may not contain NULL member names.
|
|
SELECT JSON_SCHEMA_VALID(1, '{}');
|
|
Error 3146 (22032): Invalid data type for JSON data in argument 1 to function json_schema_valid; a JSON string or JSON type is required.
|
|
SELECT JSON_SCHEMA_VALID('{}', 1);
|
|
Error 3146 (22032): Invalid data type for JSON data in argument 2 to function json_schema_valid; a JSON string or JSON type is required.
|
|
SELECT JSON_SCHEMA_VALID('','{}');
|
|
Error 3141 (22032): Invalid JSON text in argument 1 to function json_schema_valid: "The document is empty." at position 0.
|
|
SELECT JSON_SCHEMA_VALID('{}','');
|
|
Error 3141 (22032): Invalid JSON text in argument 2 to function json_schema_valid: "The document is empty." at position 0.
|
|
SELECT JSON_SCHEMA_VALID('', NULL);
|
|
Error 3141 (22032): Invalid JSON text in argument 1 to function json_schema_valid: "The document is empty." at position 0.
|
|
SELECT JSON_SCHEMA_VALID('1','{}');
|
|
Error 3853 (22032): Invalid JSON type in argument 1 to function json_schema_valid; an object is required.
|
|
SELECT JSON_SCHEMA_VALID(CONCAT('{"foo": ',repeat('[', 1000),repeat(']', 1000),'}'), json_object());
|
|
Error 3157 (22032): The JSON document exceeds the maximum depth.
|
|
SELECT JSON_SCHEMA_VALID('{"properties": {"a": {"exclusiveMinimum": true}}}', '{}');
|
|
Error 3853 (22032): Invalid JSON type in argument 1 to function json_schema_valid; an error unmarshaling properties from json: error unmarshaling exclusiveMinimum from json: json: cannot unmarshal bool into Go value of type jsonschema.ExclusiveMinimum is required.
|
|
select json_type(cast(cast('2024' as year) as json));
|
|
json_type(cast(cast('2024' as year) as json))
|
|
UNSIGNED INTEGER
|
|
drop table if exists t;
|
|
create table t(j json, str varchar(255), other int);
|
|
insert into t values (NULL, NULL, NULL);
|
|
select json_valid(j), json_valid(str), json_valid(other) from t;
|
|
json_valid(j) json_valid(str) json_valid(other)
|
|
NULL NULL NULL
|
|
DROP TABLE IF EXISTS t1;
|
|
CREATE TABLE t1(id INT PRIMARY KEY, d1 DATE, d2 DATETIME, t1 TIME, t2 TIMESTAMP, b1 BIT, b2 BINARY);
|
|
INSERT INTO t1 VALUES (1, '2024-06-14', '2024-06-14 09:37:00', '09:37:00', '2024-06-14 09:37:00', b'0', 0x41);
|
|
SELECT JSON_TYPE(d1) FROM t1;
|
|
Error 3146 (22032): Invalid data type for JSON data in argument 1 to function json_type; a JSON string or JSON type is required.
|
|
SELECT JSON_TYPE(d2) FROM t1;
|
|
Error 3146 (22032): Invalid data type for JSON data in argument 1 to function json_type; a JSON string or JSON type is required.
|
|
SELECT JSON_TYPE(t1) FROM t1;
|
|
Error 3146 (22032): Invalid data type for JSON data in argument 1 to function json_type; a JSON string or JSON type is required.
|
|
SELECT JSON_TYPE(t2) FROM t1;
|
|
Error 3146 (22032): Invalid data type for JSON data in argument 1 to function json_type; a JSON string or JSON type is required.
|
|
SELECT JSON_TYPE(b1) FROM t1;
|
|
Error 3146 (22032): Invalid data type for JSON data in argument 1 to function json_type; a JSON string or JSON type is required.
|
|
SELECT JSON_TYPE(b2) FROM t1;
|
|
Error 3144 (22032): Cannot create a JSON value from a string with CHARACTER SET 'binary'.
|
|
SELECT JSON_EXTRACT(b2, '$') FROM t1;
|
|
Error 3144 (22032): Cannot create a JSON value from a string with CHARACTER SET 'binary'.
|
|
SELECT JSON_MERGE(b2, '{a:"b"}') FROM t1;
|
|
Error 3144 (22032): Cannot create a JSON value from a string with CHARACTER SET 'binary'.
|
|
SELECT JSON_CONTAINS_PATH(b2, 'one', '$.a') FROM t1;
|
|
Error 3144 (22032): Cannot create a JSON value from a string with CHARACTER SET 'binary'.
|
|
SELECT '1' member of(b2) FROM t1;
|
|
Error 3144 (22032): Cannot create a JSON value from a string with CHARACTER SET 'binary'.
|
|
SELECT JSON_CONTAINS(b2, '{a:"b"}') FROM t1;
|
|
Error 3144 (22032): Cannot create a JSON value from a string with CHARACTER SET 'binary'.
|
|
SELECT JSON_OVERLAPS(b2, '{a:"b"}') FROM t1;
|
|
Error 3144 (22032): Cannot create a JSON value from a string with CHARACTER SET 'binary'.
|
|
SELECT JSON_MERGE_PATCH(b2, '{a:"b"}') FROM t1;
|
|
Error 3144 (22032): Cannot create a JSON value from a string with CHARACTER SET 'binary'.
|
|
SELECT JSON_MERGE_PATCH('{a:"b"}', b2) FROM t1;
|
|
Error 3144 (22032): Cannot create a JSON value from a string with CHARACTER SET 'binary'.
|
|
SELECT JSON_MERGE_PRESERVE(b2, '{a:"b"}') FROM t1;
|
|
Error 3144 (22032): Cannot create a JSON value from a string with CHARACTER SET 'binary'.
|
|
SELECT JSON_MERGE_PRESERVE('{a:"b"}', b2) FROM t1;
|
|
Error 3144 (22032): Cannot create a JSON value from a string with CHARACTER SET 'binary'.
|
|
SELECT JSON_SEARCH(b2, 'one', '1') FROM t1;
|
|
Error 3144 (22032): Cannot create a JSON value from a string with CHARACTER SET 'binary'.
|
|
SELECT JSON_KEYS(b2) FROM t1;
|
|
Error 3144 (22032): Cannot create a JSON value from a string with CHARACTER SET 'binary'.
|
|
SELECT JSON_SCHEMA_VALID(b2, '{}') FROM t1;
|
|
Error 3144 (22032): Cannot create a JSON value from a string with CHARACTER SET 'binary'.
|
|
prepare stmt from 'select json_object(?, ?)';
|
|
set @a=1;
|
|
execute stmt using @a, @a;
|
|
json_object(?, ?)
|
|
{"1": 1}
|
|
select json_extract("0.0", "$");
|
|
json_extract("0.0", "$")
|
|
0.0
|
|
select json_extract("[1E17]", "$");
|
|
json_extract("[1E17]", "$")
|
|
[1e17]
|
|
select json_extract('[1E27]', '$');
|
|
json_extract('[1E27]', '$')
|
|
[1e27]
|
|
select json_extract("{\"\\b\":\"\"}", "$");
|
|
json_extract("{\"\\b\":\"\"}", "$")
|
|
{"\b": ""}
|
|
select json_extract("{\"\\f\":\"\"}", "$");
|
|
json_extract("{\"\\f\":\"\"}", "$")
|
|
{"\f": ""}
|
|
select json_extract('{"a":"b"}', '$[0]');
|
|
json_extract('{"a":"b"}', '$[0]')
|
|
{"a": "b"}
|
|
select json_extract('{"a":"b"}', '$[last]');
|
|
json_extract('{"a":"b"}', '$[last]')
|
|
{"a": "b"}
|
|
select json_set('{"a":"b"}', '$[last]', 1);
|
|
json_set('{"a":"b"}', '$[last]', 1)
|
|
1
|
|
SELECT JSON_ARRAY_APPEND('[1]', '$', JSON_ARRAY(2, 3));
|
|
JSON_ARRAY_APPEND('[1]', '$', JSON_ARRAY(2, 3))
|
|
[1, [2, 3]]
|
|
set tidb_enable_vectorized_expression = 'ON';
|
|
select json_search('{"h": "i"}', 'all', 'i', '\\', NULL);
|
|
json_search('{"h": "i"}', 'all', 'i', '\\', NULL)
|
|
NULL
|
|
set tidb_enable_vectorized_expression = 'OFF';
|
|
select json_search('{"h": "i"}', 'all', 'i', '\\', NULL);
|
|
json_search('{"h": "i"}', 'all', 'i', '\\', NULL)
|
|
NULL
|
|
set tidb_enable_vectorized_expression = default;
|
|
select json_memberof();
|
|
Error 1582 (42000): Incorrect parameter count in the call to native function 'json_memberof'
|
|
drop table if exists unsignedTable;
|
|
CREATE TABLE unsignedTable(i INT PRIMARY KEY, j JSON);
|
|
insert into unsignedTable values(1, "[5, 7]"), (4, "[0, 8]");
|
|
select json_sum_crc32(j AS UNSIGNED ARRAY) as sum_crc32 from unsignedTable;
|
|
sum_crc32
|
|
4017124912
|
|
8302376500
|
|
select json_sum_crc32(j AS SIGNED ARRAY) as sum_crc32 from unsignedTable;
|
|
sum_crc32
|
|
4017124912
|
|
8302376500
|
|
select json_sum_crc32(j AS DOUBLE ARRAY) as sum_crc32 from unsignedTable;
|
|
sum_crc32
|
|
4017124912
|
|
8302376500
|
|
drop table if exists signedTable;
|
|
CREATE TABLE signedTable(i INT PRIMARY KEY, j JSON);
|
|
insert into signedTable values(1, "[-1, -2]"), (4, "[3, 4]");
|
|
select json_sum_crc32(j AS SIGNED ARRAY) as sum_crc32 from signedTable;
|
|
sum_crc32
|
|
3645989306
|
|
5931313619
|
|
select json_sum_crc32(j AS DOUBLE ARRAY) as sum_crc32 from signedTable;
|
|
sum_crc32
|
|
3645989306
|
|
5931313619
|
|
select json_sum_crc32(j AS UNSIGNED ARRAY) as sum_crc32 from signedTable;
|
|
Error 1690 (22003): constant -1 overflows bigint
|
|
drop table if exists doubleTable;
|
|
CREATE TABLE doubleTable(i INT, j JSON);
|
|
insert into doubleTable values (1, null), (2, "[2.1, 3.2]");
|
|
select json_sum_crc32(j AS double ARRAY) as sum_crc32 from doubleTable;
|
|
sum_crc32
|
|
NULL
|
|
2637479025
|
|
select json_sum_crc32(j AS SIGNED ARRAY) as sum_crc32 from doubleTable;
|
|
Error 1105 (HY000): Invalid JSON value for CAST to type bigint
|
|
drop table if exists charTable;
|
|
CREATE TABLE charTable(i INT, j JSON);
|
|
insert into charTable values (2, '["a"]'), (4, null), (3, '["c"]');
|
|
select json_sum_crc32(j AS char(10) ARRAY) from charTable;
|
|
json_sum_crc32(j AS char(10) ARRAY)
|
|
3904355907
|
|
NULL
|
|
112844655
|
|
select json_sum_crc32(j AS double ARRAY) from charTable;
|
|
Error 1105 (HY000): Invalid JSON value for CAST to type double
|