Files
tidb/tests/integrationtest/r/expression/json.result

652 lines
25 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 (HY000): Invalid data type for JSON data in argument 0 to function json_merge; a JSON string or JSON type is required.
select json_merge_preserve(1, 2);
Error 3146 (HY000): Invalid data type for JSON data in argument 0 to function json_merge_preserve; a JSON string or JSON type is required.
select json_merge_patch(1, 2);
Error 3146 (HY000): Invalid data type for JSON data in argument 0 to function json_merge_patch; a JSON string or JSON type is required.
select JSON_CONTAINS_PATH(1, 'one', '$.a');
Error 3146 (HY000): Invalid data type for JSON data in argument 0 to function json_contains_path; a JSON string or JSON type is required.
select json_search(1, 'one', '$.a');
Error 3146 (HY000): Invalid data type for JSON data in argument 0 to function json_search; a JSON string or JSON type is required.
select json_keys(1, '$.a');
Error 3146 (HY000): Invalid data type for JSON data in argument 0 to function json_keys; a JSON string or JSON type is required.
select JSON_extract(1, '$.a');
Error 3146 (HY000): Invalid data type for JSON data in argument 0 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 range selection.
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_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 (HY000): Cannot create a JSON value from a string with CHARACTER SET 'binary'.
select json_objectagg(b, a) from t;
Error 3144 (HY000): 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 (HY000): 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 (HY000): The JSON document exceeds the maximum depth.
select json_object(1, a) from t;
Error 3157 (HY000): The JSON document exceeds the maximum depth.
select json_set(a, concat('$', repeat('[0]', 100)), json_array(json_array(3))) from t;
Error 3157 (HY000): The JSON document exceeds the maximum depth.
select json_array_append(a, concat('$', repeat('[0]', 100)), 1) from t;
Error 3157 (HY000): 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