|
|
|
@ -7,21 +7,21 @@
|
|
|
|
|
|
|
|
|
|
# Some extra checks for comparisons between positive and negative zero.
|
|
|
|
|
# All should be equal.
|
|
|
|
|
SELECT CAST(0.0e0 AS JSON) = -0.0e0;
|
|
|
|
|
SELECT CAST(CAST(0 AS DECIMAL) AS JSON) = CAST(-0.0e0 AS DECIMAL);
|
|
|
|
|
SELECT CAST(0.0e0 AS JSON) = CAST(-0.0e0 AS DECIMAL);
|
|
|
|
|
SELECT CAST(CAST(0 AS DECIMAL) AS JSON) = -0.0e0;
|
|
|
|
|
SELECT CAST(CAST(0 AS SIGNED) AS JSON) = -0.0e0;
|
|
|
|
|
SELECT CAST(CAST(0 AS SIGNED) AS JSON) = CAST(-0.0e0 AS DECIMAL);
|
|
|
|
|
SELECT CAST(CAST(0 AS UNSIGNED) AS JSON) = -0.0e0;
|
|
|
|
|
SELECT CAST(CAST(0 AS UNSIGNED) AS JSON) = CAST(-0.0e0 AS DECIMAL);
|
|
|
|
|
SELECT JSON_COMPACT(0.0e0) = -0.0e0;
|
|
|
|
|
SELECT JSON_COMPACT(CAST(0 AS DECIMAL)) = CAST(-0.0e0 AS DECIMAL);
|
|
|
|
|
SELECT JSON_COMPACT(0.0e0) = CAST(-0.0e0 AS DECIMAL);
|
|
|
|
|
SELECT JSON_COMPACT(CAST(0 AS DECIMAL)) = -0.0e0;
|
|
|
|
|
SELECT JSON_COMPACT(CAST(0 AS SIGNED)) = -0.0e0;
|
|
|
|
|
SELECT JSON_COMPACT(CAST(0 AS SIGNED)) = CAST(-0.0e0 AS DECIMAL);
|
|
|
|
|
SELECT JSON_COMPACT(CAST(0 AS UNSIGNED)) = -0.0e0;
|
|
|
|
|
SELECT JSON_COMPACT(CAST(0 AS UNSIGNED)) = CAST(-0.0e0 AS DECIMAL);
|
|
|
|
|
|
|
|
|
|
# Test that CAST string argument isn't treated as ANY_JSON_ATOM
|
|
|
|
|
# in that a MySQL string needs to be parsed to JSON here; it is not
|
|
|
|
|
# auto-converted to a JSON string as in ANY_JSON_ATOM contexts.
|
|
|
|
|
select cast('"abc"' as json);
|
|
|
|
|
select json_compact('"abc"');
|
|
|
|
|
--echo error ER_INVALID_JSON_TEXT_IN_PARAM
|
|
|
|
|
select cast('abc' as json);
|
|
|
|
|
select json_compact('abc');
|
|
|
|
|
|
|
|
|
|
--echo
|
|
|
|
|
--echo # String literal - valid JSON
|
|
|
|
@ -50,11 +50,11 @@ set names 'utf8';
|
|
|
|
|
|
|
|
|
|
--echo
|
|
|
|
|
--echo # Json expression
|
|
|
|
|
select JSON_VALID(cast('[123]' as JSON ));
|
|
|
|
|
select JSON_VALID(json_compact('[123]'));
|
|
|
|
|
|
|
|
|
|
--echo
|
|
|
|
|
--echo # Json expression NULL
|
|
|
|
|
select JSON_VALID(cast(NULL as JSON ));
|
|
|
|
|
select JSON_VALID(json_compact(NULL));
|
|
|
|
|
|
|
|
|
|
--echo
|
|
|
|
|
--echo # Bare NULL
|
|
|
|
@ -80,7 +80,7 @@ select JSON_VALID( CAST('2015-01-15' AS DATE) );
|
|
|
|
|
--echo # The date string doesn't parse as JSON text, so wrong:
|
|
|
|
|
select JSON_VALID( CAST(CAST('2015-01-15' AS DATE) as CHAR CHARACTER SET 'utf8') );
|
|
|
|
|
--echo # OK, though:
|
|
|
|
|
select JSON_VALID( CAST(CURDATE() as JSON) );
|
|
|
|
|
select JSON_VALID( json_compact(CURDATE()) );
|
|
|
|
|
|
|
|
|
|
--echo
|
|
|
|
|
--echo # Function result - NULL
|
|
|
|
@ -299,14 +299,14 @@ SELECT JSON_LENGTH
|
|
|
|
|
--echo # Test of JSON_DEPTH function.
|
|
|
|
|
--echo # ----------------------------------------------------------------------
|
|
|
|
|
select json_depth(null);
|
|
|
|
|
select json_depth(cast(null as json));
|
|
|
|
|
select json_depth(json_compact(null));
|
|
|
|
|
#select i, json_depth(j) from t1;
|
|
|
|
|
select json_depth(cast('[]' as json)),
|
|
|
|
|
json_depth(cast('{}' as json)),
|
|
|
|
|
json_depth(cast('null' as json)),
|
|
|
|
|
select json_depth(json_compact('[]')),
|
|
|
|
|
json_depth(json_compact('{}')),
|
|
|
|
|
json_depth(json_compact('null')),
|
|
|
|
|
json_depth(json_quote('foo'));
|
|
|
|
|
select json_depth(cast('[[2], 3, [[[4]]]]' as json));
|
|
|
|
|
select json_depth(cast('{"a": {"a1": [3]}, "b": {"b1": {"c": {"d": [5]}}}}' as json));
|
|
|
|
|
select json_depth(json_compact('[[2], 3, [[[4]]]]'));
|
|
|
|
|
select json_depth(json_compact('{"a": {"a1": [3]}, "b": {"b1": {"c": {"d": [5]}}}}'));
|
|
|
|
|
|
|
|
|
|
# examples from the wl7909 spec
|
|
|
|
|
# returns 1
|
|
|
|
@ -325,7 +325,7 @@ SELECT JSON_DEPTH
|
|
|
|
|
SELECT JSON_DEPTH( '"abc"' );
|
|
|
|
|
|
|
|
|
|
# returns 1
|
|
|
|
|
SELECT JSON_DEPTH( CAST( '"abc"' AS JSON ) );
|
|
|
|
|
SELECT JSON_DEPTH( json_compact( '"abc"') );
|
|
|
|
|
|
|
|
|
|
--echo error ER_INVALID_TYPE_FOR_JSON
|
|
|
|
|
SELECT JSON_DEPTH( 1 );
|
|
|
|
@ -334,7 +334,7 @@ SELECT JSON_DEPTH( 1 );
|
|
|
|
|
SELECT JSON_DEPTH( 'abc' );
|
|
|
|
|
|
|
|
|
|
# returns 1
|
|
|
|
|
SELECT JSON_DEPTH( CAST( 1 AS JSON ) );
|
|
|
|
|
SELECT JSON_DEPTH( json_compact( 1) );
|
|
|
|
|
|
|
|
|
|
# returns 2
|
|
|
|
|
SELECT JSON_DEPTH
|
|
|
|
@ -608,93 +608,93 @@ select json_type('3.14');
|
|
|
|
|
select json_type(CAST(CAST('2015-01-15' AS DATE) as CHAR CHARACTER SET 'utf8'));
|
|
|
|
|
|
|
|
|
|
--echo # ----------------------------------------------------------------------
|
|
|
|
|
--echo # Test of CAST(literal AS JSON)
|
|
|
|
|
--echo # Test of json_compact(literal)
|
|
|
|
|
--echo # ----------------------------------------------------------------------
|
|
|
|
|
select json_type(cast(cast('2014-11-25 18:00' as datetime) as json));
|
|
|
|
|
select json_type(cast(cast('2014-11-25' as date) as json));
|
|
|
|
|
select json_type(cast(cast('18:00:59' as time) as json));
|
|
|
|
|
# select json_type(cast(cast('2014-11-25 18:00' as timestamp) as json)); -- cast target type not supported
|
|
|
|
|
select json_type(json_compact(cast('2014-11-25 18:00' as datetime)));
|
|
|
|
|
select json_type(json_compact(cast('2014-11-25' as date)));
|
|
|
|
|
select json_type(json_compact(cast('18:00:59' as time)));
|
|
|
|
|
# select json_type(json_compact(cast('2014-11-25 18:00' as timestamp))); -- cast target type not supported
|
|
|
|
|
|
|
|
|
|
# select json_type(cast(cast('1999' as year) as json)); -- cast target type not supported
|
|
|
|
|
select json_type(cast(127 as json));
|
|
|
|
|
select json_type(cast(255 as json));
|
|
|
|
|
select json_type(cast(32767 as json));
|
|
|
|
|
select json_type(cast(65535 as json));
|
|
|
|
|
select json_type(cast(8388607 as json));
|
|
|
|
|
select json_type(cast(16777215 as json));
|
|
|
|
|
select json_type(cast(2147483647 as json));
|
|
|
|
|
select json_type(cast(4294967295 as json));
|
|
|
|
|
select json_type(cast(9223372036854775807 as json));
|
|
|
|
|
select json_type(cast(18446744073709551615 as json));
|
|
|
|
|
select json_type(cast(true as json));
|
|
|
|
|
select json_type(cast(b'10101' as json));
|
|
|
|
|
# select json_type(json_compact(cast('1999' as year))); -- cast target type not supported
|
|
|
|
|
select json_type(json_compact(127));
|
|
|
|
|
select json_type(json_compact(255));
|
|
|
|
|
select json_type(json_compact(32767));
|
|
|
|
|
select json_type(json_compact(65535));
|
|
|
|
|
select json_type(json_compact(8388607));
|
|
|
|
|
select json_type(json_compact(16777215));
|
|
|
|
|
select json_type(json_compact(2147483647));
|
|
|
|
|
select json_type(json_compact(4294967295));
|
|
|
|
|
select json_type(json_compact(9223372036854775807));
|
|
|
|
|
select json_type(json_compact(18446744073709551615));
|
|
|
|
|
select json_type(json_compact(true));
|
|
|
|
|
select json_type(json_compact(b'10101'));
|
|
|
|
|
|
|
|
|
|
select json_type(cast(cast(3.14 as decimal(5,2)) as json));
|
|
|
|
|
select json_type(cast(3.14 as json));
|
|
|
|
|
select json_type(cast(3.14E30 as json));
|
|
|
|
|
# select json_type(cast(cast(3.14 as numeral(5,2)) as json)); -- cast target type not supported
|
|
|
|
|
select json_type(json_compact(cast(3.14 as decimal(5,2))));
|
|
|
|
|
select json_type(json_compact(3.14));
|
|
|
|
|
select json_type(json_compact(3.14E30));
|
|
|
|
|
# select json_type(json_compact(cast(3.14 as numeral(5,2)))); -- cast target type not supported
|
|
|
|
|
|
|
|
|
|
# select json_type(cast(cast(3.14 as double) as json)); -- cast target type not supported
|
|
|
|
|
# select json_type(cast(cast(3.14 as float) as json)); -- cast target type not supported
|
|
|
|
|
# select json_type(json_compact(cast(3.14 as double))); -- cast target type not supported
|
|
|
|
|
# select json_type(json_compact(cast(3.14 as float))); -- cast target type not supported
|
|
|
|
|
|
|
|
|
|
# select json_type(cast(cast(b'10101' as bit(10)) as json)); -- cast target type not supported
|
|
|
|
|
# select json_type(cast(cast('10101abcde' as blob) as json)); -- cast target type not supported
|
|
|
|
|
select json_type(cast(cast('10101abcde' as binary) as json));
|
|
|
|
|
# select json_type(json_compact(cast(b'10101' as bit(10)))); -- cast target type not supported
|
|
|
|
|
# select json_type(json_compact(cast('10101abcde' as blob))); -- cast target type not supported
|
|
|
|
|
select json_type(json_compact(cast('10101abcde' as binary)));
|
|
|
|
|
|
|
|
|
|
# select json_type(cast(cast('a' as enum('a','b','c')) as json)); -- cast target type not supported
|
|
|
|
|
# select json_type(cast(cast('a,c' as set('a','b','c')) as json)); -- cast target type not supported
|
|
|
|
|
# select json_type(json_compact(cast('a' as enum('a','b','c')))); -- cast target type not supported
|
|
|
|
|
# select json_type(json_compact(cast('a,c' as set('a','b','c')))); -- cast target type not supported
|
|
|
|
|
|
|
|
|
|
select json_type(cast(ST_GeomFromText('POINT(1 1)') as json));
|
|
|
|
|
select json_type(cast(ST_GeomFromText('LINESTRING(0 0,1 1,2 2)') as json));
|
|
|
|
|
select json_type(cast(ST_GeomFromText('POLYGON((0 0,10 0,10 10,0 10,0 0),
|
|
|
|
|
(5 5,7 5,7 7,5 7, 5 5))') as json));
|
|
|
|
|
select json_type(cast(null as json));
|
|
|
|
|
select json_type(cast(null as json)) is null; # check that it is an SQL NULL
|
|
|
|
|
select json_type(json_compact(ST_GeomFromText('POINT(1 1)')));
|
|
|
|
|
select json_type(json_compact(ST_GeomFromText('LINESTRING(0 0,1 1,2 2)')));
|
|
|
|
|
select json_type(json_compact(ST_GeomFromText('POLYGON((0 0,10 0,10 10,0 10,0 0),
|
|
|
|
|
(5 5,7 5,7 7,5 7, 5 5))')));
|
|
|
|
|
select json_type(json_compact(null));
|
|
|
|
|
select json_type(json_compact(null)) is null; # check that it is an SQL NULL
|
|
|
|
|
select json_type(null) is null; # is an SQL NULL
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# same, but now show the printable value:
|
|
|
|
|
#
|
|
|
|
|
select cast(cast('2014-11-25 18:00' as datetime) as json);
|
|
|
|
|
select cast(cast('2014-11-25' as date) as json);
|
|
|
|
|
select cast(cast('18:00:59' as time) as json);
|
|
|
|
|
# select cast(cast('2014-11-25 18:00' as timestamp) as json); -- cast target type not supported
|
|
|
|
|
select json_compact(cast('2014-11-25 18:00' as datetime));
|
|
|
|
|
select json_compact(cast('2014-11-25' as date));
|
|
|
|
|
select json_compact(cast('18:00:59' as time));
|
|
|
|
|
# select json_compact(cast('2014-11-25 18:00' as timestamp)); -- cast target type not supported
|
|
|
|
|
|
|
|
|
|
# select cast(cast('1999' as year) as json); -- cast target type not supported
|
|
|
|
|
select cast(127 as json);
|
|
|
|
|
select cast(255 as json);
|
|
|
|
|
select cast(32767 as json);
|
|
|
|
|
select cast(65535 as json);
|
|
|
|
|
select cast(8388607 as json);
|
|
|
|
|
select cast(16777215 as json);
|
|
|
|
|
select cast(2147483647 as json);
|
|
|
|
|
select cast(4294967295 as json);
|
|
|
|
|
select cast(9223372036854775807 as json);
|
|
|
|
|
select cast(18446744073709551615 as json);
|
|
|
|
|
select cast(true as json);
|
|
|
|
|
select cast(b'10101' as json);
|
|
|
|
|
# select json_compact(cast('1999' as year)); -- cast target type not supported
|
|
|
|
|
select json_compact(127);
|
|
|
|
|
select json_compact(255);
|
|
|
|
|
select json_compact(32767);
|
|
|
|
|
select json_compact(65535);
|
|
|
|
|
select json_compact(8388607);
|
|
|
|
|
select json_compact(16777215);
|
|
|
|
|
select json_compact(2147483647);
|
|
|
|
|
select json_compact(4294967295);
|
|
|
|
|
select json_compact(9223372036854775807);
|
|
|
|
|
select json_compact(18446744073709551615);
|
|
|
|
|
select json_compact(true);
|
|
|
|
|
select json_compact(b'10101');
|
|
|
|
|
|
|
|
|
|
select cast(cast(3.14 as decimal(5,2)) as json);
|
|
|
|
|
select cast(3.14 as json);
|
|
|
|
|
select cast(3.14e0 as json);
|
|
|
|
|
# select cast(cast(3.14 as numeral(5,2)) as json); -- cast target type not supported
|
|
|
|
|
select json_compact(cast(3.14 as decimal(5,2)));
|
|
|
|
|
select json_compact(3.14);
|
|
|
|
|
select json_compact(3.14e0);
|
|
|
|
|
# select json_compact(cast(3.14 as numeral(5,2))); -- cast target type not supported
|
|
|
|
|
|
|
|
|
|
# select cast(cast(3.14 as double) as json); -- cast target type not supported
|
|
|
|
|
# select cast(cast(3.14 as float) as json); -- cast target type not supported
|
|
|
|
|
# select json_compact(cast(3.14 as double)); -- cast target type not supported
|
|
|
|
|
# select json_compact(cast(3.14 as float)); -- cast target type not supported
|
|
|
|
|
|
|
|
|
|
# select cast(cast(b'10101' as bit(10) as json); -- cast target type not supported
|
|
|
|
|
# select cast(cast('10101abcde' as blob) as json); -- cast target type not supported
|
|
|
|
|
select cast(cast('10101abcde' as binary) as json);
|
|
|
|
|
# select json_compact(cast(b'10101' as bit(10)); -- cast target type not supported
|
|
|
|
|
# select json_compact(cast('10101abcde' as blob)); -- cast target type not supported
|
|
|
|
|
select json_compact(cast('10101abcde' as binary));
|
|
|
|
|
|
|
|
|
|
# select cast(cast('a' as enum('a','b','c') as json); -- cast target type not supported
|
|
|
|
|
# select cast(cast('a,c' as set('a','b','c') as json); -- cast target type not supported
|
|
|
|
|
# select json_compact(cast('a' as enum('a','b','c')); -- cast target type not supported
|
|
|
|
|
# select json_compact(cast('a,c' as set('a','b','c')); -- cast target type not supported
|
|
|
|
|
|
|
|
|
|
select cast(ST_GeomFromText('POINT(1 1)') as json);
|
|
|
|
|
select cast(ST_GeomFromText('LINESTRING(0 0,1 1,2 2)') as json);
|
|
|
|
|
select cast(ST_GeomFromText('POLYGON((0 0,10 0,10 10,0 10,0 0),
|
|
|
|
|
(5 5,7 5,7 7,5 7, 5 5))') as json);
|
|
|
|
|
select cast(null as json);
|
|
|
|
|
select cast(null as json) is null; # check that it is an SQL NULL
|
|
|
|
|
select json_compact(ST_GeomFromText('POINT(1 1)'));
|
|
|
|
|
select json_compact(ST_GeomFromText('LINESTRING(0 0,1 1,2 2)'));
|
|
|
|
|
select json_compact(ST_GeomFromText('POLYGON((0 0,10 0,10 10,0 10,0 0),
|
|
|
|
|
(5 5,7 5,7 7,5 7, 5 5))'));
|
|
|
|
|
select json_compact(null);
|
|
|
|
|
select json_compact(null) is null; # check that it is an SQL NULL
|
|
|
|
|
|
|
|
|
|
--echo # ----------------------------------------------------------------------
|
|
|
|
|
--echo # Test of JSON_KEYS function.
|
|
|
|
@ -761,7 +761,7 @@ SELECT JSON_KEYS('{}', '$', '$');
|
|
|
|
|
--echo # conversion tests.
|
|
|
|
|
--echo # ----------------------------------------------------------------------
|
|
|
|
|
select cast(json_keys('{"a": 1}') as char);
|
|
|
|
|
select cast(cast(1 as json) as char);
|
|
|
|
|
select cast(json_compact(1) as char);
|
|
|
|
|
select cast(json_keys(NULL) as char);
|
|
|
|
|
#select cast(j as char) from keys1;
|
|
|
|
|
|
|
|
|
@ -996,8 +996,8 @@ select json_extract( '[ { "a": [3,4] }, { "b": 2 } ]', '$[0].a', '$[1].a' ) jdoc
|
|
|
|
|
--echo # ----------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
# NULLs
|
|
|
|
|
select json_array_append(NULL, '$.b', cast(1 as json));
|
|
|
|
|
select json_array_append('[1,2,3]', NULL, cast(1 as json));
|
|
|
|
|
select json_array_append(NULL, '$.b', json_compact(1));
|
|
|
|
|
select json_array_append('[1,2,3]', NULL, json_compact(1));
|
|
|
|
|
select json_array_append('[1,2,3]', '$', NULL);
|
|
|
|
|
|
|
|
|
|
# wrong # args
|
|
|
|
@ -1009,25 +1009,25 @@ select json_array_append(NULL, NULL);
|
|
|
|
|
select json_array_append(NULL, NULL, NULL, NULL);
|
|
|
|
|
|
|
|
|
|
# auto-wrap
|
|
|
|
|
SELECT JSON_ARRAY_APPEND(cast('1' as json), '$', 3);
|
|
|
|
|
SELECT JSON_ARRAY_APPEND(cast('{"a": 3}' as json), '$', 3);
|
|
|
|
|
SELECT JSON_ARRAY_APPEND(json_compact('1'), '$', 3);
|
|
|
|
|
SELECT JSON_ARRAY_APPEND(json_compact('{"a": 3}'), '$', 3);
|
|
|
|
|
|
|
|
|
|
--echo error ER_INVALID_JSON_PATH_WILDCARD
|
|
|
|
|
select json_array_append(cast('{"a": {"b": [3]}}' as json), '$**[0]', 6);
|
|
|
|
|
select json_array_append(json_compact('{"a": {"b": [3]}}'), '$**[0]', 6);
|
|
|
|
|
|
|
|
|
|
# Examples from the specification
|
|
|
|
|
|
|
|
|
|
--echo # Auto-wrapping, since because the paths identify scalars.
|
|
|
|
|
--echo # should return {"a": "foo", "b": ["bar", 4], "c": ["wibble", "grape"]}
|
|
|
|
|
SELECT JSON_ARRAY_APPEND('{"a": "foo", "b": "bar", "c": "wibble"}',
|
|
|
|
|
'$.b', cast(4 as json),
|
|
|
|
|
'$.c', cast('"grape"' as json));
|
|
|
|
|
'$.b', json_compact(4),
|
|
|
|
|
'$.c', json_compact('"grape"'));
|
|
|
|
|
|
|
|
|
|
--echo # should return {"a": "foo", "b": [1, 2, 3, 4],
|
|
|
|
|
--echo # "c": ["apple", "pear", "grape"]}
|
|
|
|
|
SELECT JSON_ARRAY_APPEND('{"a" : "foo","b": [1, 2, 3], "c": ["apple", "pear"]}',
|
|
|
|
|
'$.b', cast(4 as json),
|
|
|
|
|
'$.c', cast('"grape"' as json));
|
|
|
|
|
'$.b', json_compact(4),
|
|
|
|
|
'$.c', json_compact('"grape"'));
|
|
|
|
|
|
|
|
|
|
# without CAST: cf. not required for ANY_JSON_ATOM arguments in specification
|
|
|
|
|
SELECT JSON_ARRAY_APPEND('{"a" : "foo","b": [1, 2, 3], "c": ["apple", "pear"]}',
|
|
|
|
@ -1070,8 +1070,8 @@ select json_array_append('3', '$[0][0][0][0]', 100);
|
|
|
|
|
--echo # ----------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
# NULLs
|
|
|
|
|
select json_insert(NULL, '$.b', cast(1 as json));
|
|
|
|
|
select json_insert('[1,2,3]', NULL, cast(1 as json));
|
|
|
|
|
select json_insert(NULL, '$.b', json_compact(1));
|
|
|
|
|
select json_insert('[1,2,3]', NULL, json_compact(1));
|
|
|
|
|
select json_insert('[1,2,3]', '$[3]', NULL);
|
|
|
|
|
|
|
|
|
|
# wrong # args
|
|
|
|
@ -1104,35 +1104,35 @@ select json_insert('{"a": 3}', '$.a[1]', 4, '$.a[2]', '5');
|
|
|
|
|
|
|
|
|
|
# wild card & auto-wrap (scalars)
|
|
|
|
|
--echo error ER_INVALID_JSON_PATH_WILDCARD
|
|
|
|
|
select json_insert(cast('{"a": [1], "b": 2}' as json), '$.*[1]', 6);
|
|
|
|
|
select json_insert(json_compact('{"a": [1], "b": 2}'), '$.*[1]', 6);
|
|
|
|
|
--echo error ER_INVALID_JSON_PATH_WILDCARD
|
|
|
|
|
select json_insert(cast('{"a": 1, "b": 2}' as json), '$.*[1]', 6);
|
|
|
|
|
select json_insert(json_compact('{"a": 1, "b": 2}'), '$.*[1]', 6);
|
|
|
|
|
|
|
|
|
|
--echo error ER_INVALID_JSON_PATH_WILDCARD
|
|
|
|
|
select json_insert(cast('{"a": {"b": 3}}' as json), '$.a.*[1]', 6);
|
|
|
|
|
select json_insert(json_compact('{"a": {"b": 3}}'), '$.a.*[1]', 6);
|
|
|
|
|
--echo error ER_INVALID_JSON_PATH_WILDCARD
|
|
|
|
|
select json_insert(cast('{"a": {"b": [3]}}' as json), '$.a.*[1]', 6);
|
|
|
|
|
select json_insert(json_compact('{"a": {"b": [3]}}'), '$.a.*[1]', 6);
|
|
|
|
|
--echo error ER_INVALID_JSON_PATH_WILDCARD
|
|
|
|
|
select json_insert(cast('{"a": {"b": 3}}' as json), '$**[1]', 6);
|
|
|
|
|
select json_insert(json_compact('{"a": {"b": 3}}'), '$**[1]', 6);
|
|
|
|
|
--echo error ER_INVALID_JSON_PATH_WILDCARD
|
|
|
|
|
select json_insert(cast('{"a": {"b": [3]}}' as json), '$**[1]', 6);
|
|
|
|
|
select json_insert(json_compact('{"a": {"b": [3]}}'), '$**[1]', 6);
|
|
|
|
|
|
|
|
|
|
--echo error ER_INVALID_JSON_PATH_WILDCARD
|
|
|
|
|
select json_insert(cast('[1]' as json), '$[*][1]', 6);
|
|
|
|
|
select json_insert(json_compact('[1]'), '$[*][1]', 6);
|
|
|
|
|
--echo error ER_INVALID_JSON_PATH_WILDCARD
|
|
|
|
|
select json_insert(cast('[1]' as json), '$**[1]', 6);
|
|
|
|
|
select json_insert(json_compact('[1]'), '$**[1]', 6);
|
|
|
|
|
--echo error ER_INVALID_JSON_PATH_WILDCARD
|
|
|
|
|
select json_insert(cast('[1, [2], 3]' as json), '$[*][1]', 6);
|
|
|
|
|
select json_insert(json_compact('[1, [2], 3]'), '$[*][1]', 6);
|
|
|
|
|
--echo error ER_INVALID_JSON_PATH_WILDCARD
|
|
|
|
|
select json_insert(cast('[1, [2], 3]' as json), '$**[1]', 6);
|
|
|
|
|
select json_insert(json_compact('[1, [2], 3]'), '$**[1]', 6);
|
|
|
|
|
|
|
|
|
|
--echo error ER_INVALID_JSON_PATH_WILDCARD
|
|
|
|
|
select json_insert(cast('[[1]]' as json), '$[*][1]', 6);
|
|
|
|
|
select json_insert(json_compact('[[1]]'), '$[*][1]', 6);
|
|
|
|
|
--echo error ER_INVALID_JSON_PATH_WILDCARD
|
|
|
|
|
select json_insert(cast('[[1]]' as json), '$**[1]', 6);
|
|
|
|
|
select json_insert(json_compact('[[1]]'), '$**[1]', 6);
|
|
|
|
|
|
|
|
|
|
# auto-wrap object
|
|
|
|
|
select json_insert(cast('{"a": 3}' as json), '$[1]', 6);
|
|
|
|
|
select json_insert(json_compact('{"a": 3}'), '$[1]', 6);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Examples from the specification
|
|
|
|
@ -1270,7 +1270,7 @@ select json_insert('[]', '$[*][1]', 6);
|
|
|
|
|
# multiple paths,
|
|
|
|
|
select json_array_insert( '[ 1, 2, 3 ]', '$[1]', true, '$[1]', false );
|
|
|
|
|
select json_array_insert( '[ 1, 2, 3 ]', '$[1]',
|
|
|
|
|
cast( '[ "a", "b", "c", "d" ]' as json ), '$[1][2]', false );
|
|
|
|
|
json_compact( '[ "a", "b", "c", "d" ]'), '$[1][2]', false );
|
|
|
|
|
|
|
|
|
|
# test an error while evaluating the document expression
|
|
|
|
|
--echo error ER_INVALID_JSON_TEXT_IN_PARAM
|
|
|
|
@ -1285,8 +1285,8 @@ select json_array_insert( '[ 1, 2, 3 ]', '$[1]', json_extract( '[', '$' ) );
|
|
|
|
|
--echo # ----------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
# NULLs
|
|
|
|
|
select json_set(NULL, '$.b', cast(1 as json));
|
|
|
|
|
select json_set('[1,2,3]', NULL, cast(1 as json));
|
|
|
|
|
select json_set(NULL, '$.b', json_compact(1));
|
|
|
|
|
select json_set('[1,2,3]', NULL, json_compact(1));
|
|
|
|
|
select json_set('[1,2,3]', '$[3]', NULL);
|
|
|
|
|
|
|
|
|
|
# wrong # args
|
|
|
|
@ -1323,7 +1323,7 @@ select json_set('{"a": 3}', '$.a[1]', 4, '$.a[2]', '5');
|
|
|
|
|
|
|
|
|
|
# auto-wrap plus ellipsis with nested hits should give: {"a": [{"b": [3, 6]}, 6]}
|
|
|
|
|
--echo error ER_INVALID_JSON_PATH_WILDCARD
|
|
|
|
|
select json_set(cast('{"a": {"b": [3]}}' as json), '$**[1]', 6);
|
|
|
|
|
select json_set(json_compact('{"a": {"b": [3]}}'), '$**[1]', 6);
|
|
|
|
|
|
|
|
|
|
# Examples from the specification: Include when missing functions are
|
|
|
|
|
# available.
|
|
|
|
@ -1341,7 +1341,7 @@ select json_set(cast('{"a": {"b": [3]}}' as json), '$**[1]', 6);
|
|
|
|
|
# # returns { "a" : "foo", "b" : [ 1, 2, 3 ], "c" : [ true, false ] }
|
|
|
|
|
# SELECT JSON_SET('{ "a" : "foo", "b" : [ 1, 2, 3 ] }',
|
|
|
|
|
# '$.c',
|
|
|
|
|
# JSON_ARRAY( CAST( 'true' AS JSON ), CAST( 'false' AS JSON ) ));
|
|
|
|
|
# JSON_ARRAY( json_compact( 'true'), json_compact( 'false') ));
|
|
|
|
|
|
|
|
|
|
# # returns [ 1, null, null, 2 ]
|
|
|
|
|
# SELECT JSON_SET('1', '$[3]', 2);
|
|
|
|
@ -1353,19 +1353,19 @@ SELECT JSON_SET('{ "a" : "foo"}', '$.a',
|
|
|
|
|
# returns { "a" : {}, "b" : [ 1, 2, 3 ] }
|
|
|
|
|
select json_set('{ "a" : "foo", "b" : [ 1, 2, 3 ] }',
|
|
|
|
|
'$.a',
|
|
|
|
|
cast('{}' as json));
|
|
|
|
|
json_compact('{}'));
|
|
|
|
|
|
|
|
|
|
# returns { "a" : "foo", "b" : [ 1, 2, 3 ], "c" : [ true, false ] }
|
|
|
|
|
select json_set('{ "a" : "foo", "b" : [ 1, 2, 3 ] }',
|
|
|
|
|
'$.c',
|
|
|
|
|
cast('[true, false]' as json));
|
|
|
|
|
json_compact('[true, false]'));
|
|
|
|
|
|
|
|
|
|
# returns [ 1, null, null, 2 ]
|
|
|
|
|
select json_set('1', '$[3]', 2);
|
|
|
|
|
|
|
|
|
|
# should return { "a": { "b": false, "c": true } }
|
|
|
|
|
select json_set('{ "a" : "foo"}', '$.a',
|
|
|
|
|
cast('{"b": false}' as json), '$.a.c', true);
|
|
|
|
|
json_compact('{"b": false}'), '$.a.c', true);
|
|
|
|
|
|
|
|
|
|
# examples from wl7909 spec
|
|
|
|
|
# returns {"a": {}, "b": [1, 2, 3]}
|
|
|
|
@ -1389,7 +1389,7 @@ SELECT JSON_SET
|
|
|
|
|
(
|
|
|
|
|
'{ "a" : "foo", "b" : [ 1, 2, 3 ] }',
|
|
|
|
|
'$.c',
|
|
|
|
|
JSON_ARRAY( CAST( 'true' AS JSON ), CAST( 'false' AS JSON ) )
|
|
|
|
|
JSON_ARRAY( json_compact( 'true'), json_compact( 'false') )
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
# returns [1, 2]
|
|
|
|
@ -1413,8 +1413,8 @@ SELECT JSON_SET
|
|
|
|
|
--echo # ----------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
# NULLs
|
|
|
|
|
select json_replace(NULL, '$.b', cast(1 as json));
|
|
|
|
|
select json_replace('[1,2,3]', NULL, cast(1 as json));
|
|
|
|
|
select json_replace(NULL, '$.b', json_compact(1));
|
|
|
|
|
select json_replace('[1,2,3]', NULL, json_compact(1));
|
|
|
|
|
select json_replace('[1,2,3]', '$[2]', NULL);
|
|
|
|
|
|
|
|
|
|
# wrong # args
|
|
|
|
@ -1468,8 +1468,8 @@ SELECT JSON_REPLACE('{ "a" : "foo", "b" : [ 1, 2, 3 ] }',
|
|
|
|
|
--echo # ----------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
# NULLs
|
|
|
|
|
select json_array(NULL, '$.b', cast(1 as json));
|
|
|
|
|
select json_array('[1,2,3]', NULL, cast(1 as json));
|
|
|
|
|
select json_array(NULL, '$.b', json_compact(1));
|
|
|
|
|
select json_array('[1,2,3]', NULL, json_compact(1));
|
|
|
|
|
select json_array('[1,2,3]', '$[3]', NULL);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -1477,7 +1477,7 @@ select json_array('[1,2,3]', '$[3]', NULL);
|
|
|
|
|
select json_array();
|
|
|
|
|
select json_array(3.14);
|
|
|
|
|
select json_array('[1,2,3]');
|
|
|
|
|
select json_array(cast('[1,2,3]' as json));
|
|
|
|
|
select json_array(json_compact('[1,2,3]'));
|
|
|
|
|
select json_array(1,2,3);
|
|
|
|
|
select json_array(b'0', b'1', b'10');
|
|
|
|
|
|
|
|
|
@ -1503,8 +1503,8 @@ select json_object();
|
|
|
|
|
select json_object( 'a', null );
|
|
|
|
|
select json_object( 'a', 1 );
|
|
|
|
|
select json_object( 'a', 1, 'b', 'foo' );
|
|
|
|
|
select json_object( 'a', 1, 'b', 'foo', 'c', cast( '{ "d": "wibble" }' as json ) );
|
|
|
|
|
select json_object( 'a', true, 'b', false, 'c', cast( 'null' as json) );
|
|
|
|
|
select json_object( 'a', 1, 'b', 'foo', 'c', json_compact( '{ "d": "wibble" }') );
|
|
|
|
|
select json_object( 'a', true, 'b', false, 'c', json_compact( 'null') );
|
|
|
|
|
select json_valid( json_object( '"a"', 1 ) );
|
|
|
|
|
|
|
|
|
|
# long key
|
|
|
|
@ -1707,29 +1707,29 @@ SELECT JSON_UNQUOTE
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
select json_type(case (null is null) when 1 then
|
|
|
|
|
cast('null' as json) else
|
|
|
|
|
cast('[1,2,3]' as json) end);
|
|
|
|
|
json_compact('null') else
|
|
|
|
|
json_compact('[1,2,3]') end);
|
|
|
|
|
|
|
|
|
|
select json_type(case (null is not null) when 1 then
|
|
|
|
|
cast('null' as json) else
|
|
|
|
|
cast('[1,2,3]' as json) end);
|
|
|
|
|
json_compact('null') else
|
|
|
|
|
json_compact('[1,2,3]') end);
|
|
|
|
|
|
|
|
|
|
select json_type( if(null is null,
|
|
|
|
|
cast('null' as json),
|
|
|
|
|
cast('[1,2,3]' as json)) );
|
|
|
|
|
json_compact('null'),
|
|
|
|
|
json_compact('[1,2,3]')) );
|
|
|
|
|
|
|
|
|
|
select json_type( if(null is not null,
|
|
|
|
|
cast('null' as json),
|
|
|
|
|
cast('[1,2,3]' as json)));
|
|
|
|
|
json_compact('null'),
|
|
|
|
|
json_compact('[1,2,3]')));
|
|
|
|
|
|
|
|
|
|
select cast(json_extract(cast(concat('[', cast('["A",2]' as json), ']') as json),
|
|
|
|
|
select cast(json_extract(json_compact(concat('[', json_compact('["A",2]'), ']')),
|
|
|
|
|
'$[0][1]') as char) = 2;
|
|
|
|
|
|
|
|
|
|
--echo # ----------------------------------------------------------------------
|
|
|
|
|
--echo # Test of aggregate function MAX, MIN.
|
|
|
|
|
--echo # ----------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
select max(cast('[1,2,3]' as json));
|
|
|
|
|
select max(json_compact('[1,2,3]'));
|
|
|
|
|
|
|
|
|
|
--echo # ----------------------------------------------------------------------
|
|
|
|
|
--echo # Test of JSON_QUOTE, JSON_UNQUOTE
|
|
|
|
@ -1781,26 +1781,26 @@ select json_unquote(123); # integer not allowed
|
|
|
|
|
select json_unquote('""'); # empty string
|
|
|
|
|
select char_length(json_unquote('""')); # verify empty string
|
|
|
|
|
select json_unquote('"" '); # unchanged: no final "
|
|
|
|
|
select json_unquote(cast(json_quote('abc') as json)); # round trip
|
|
|
|
|
select json_unquote(json_compact(json_quote('abc'))); # round trip
|
|
|
|
|
|
|
|
|
|
# No change in this JSON string: it is an object
|
|
|
|
|
select cast('{"abc": "foo"}' as json);
|
|
|
|
|
select json_unquote(cast('{"abc": "foo"}' as json));
|
|
|
|
|
select json_compact('{"abc": "foo"}');
|
|
|
|
|
select json_unquote(json_compact('{"abc": "foo"}'));
|
|
|
|
|
|
|
|
|
|
# This is a JSON string, so it is actually unquoted
|
|
|
|
|
select json_extract(cast('{"abc": "foo"}' as json), '$.abc');
|
|
|
|
|
select json_unquote(json_extract(cast('{"abc": "foo"}' as json), '$.abc'));
|
|
|
|
|
select json_extract(json_compact('{"abc": "foo"}'), '$.abc');
|
|
|
|
|
select json_unquote(json_extract(json_compact('{"abc": "foo"}'), '$.abc'));
|
|
|
|
|
|
|
|
|
|
# Bug fix: thse should be the same
|
|
|
|
|
select json_unquote('["a", "b", "c"]');
|
|
|
|
|
select json_unquote(cast('["a", "b", "c"]' as json));
|
|
|
|
|
select json_unquote(json_compact('["a", "b", "c"]'));
|
|
|
|
|
|
|
|
|
|
select charset(json_unquote('"abc"'));
|
|
|
|
|
|
|
|
|
|
select json_quote(convert(X'e68891' using utf8)); # chinese "I" (wo3)
|
|
|
|
|
select json_quote(convert(X'e68891' using utf8mb4)); # chinese "I" (wo3)
|
|
|
|
|
|
|
|
|
|
select cast(json_quote(convert(X'e68891' using utf8)) as json);
|
|
|
|
|
select json_compact(json_quote(convert(X'e68891' using utf8)));
|
|
|
|
|
|
|
|
|
|
select json_unquote(convert(X'e68891' using utf8)); # chinese "I" (wo3)
|
|
|
|
|
|
|
|
|
@ -1809,12 +1809,12 @@ select json_unquote(json_unquote(json_unquote( # long round trip of it
|
|
|
|
|
json_quote(json_quote(json_quote('abc'))))));
|
|
|
|
|
|
|
|
|
|
# DATE/TIME will lose their quotes, too:
|
|
|
|
|
select cast(cast('2015-01-15 23:24:25' as datetime) as json);
|
|
|
|
|
select json_unquote(cast(cast('2015-01-15 23:24:25' as datetime) as json));
|
|
|
|
|
select json_compact(cast('2015-01-15 23:24:25' as datetime));
|
|
|
|
|
select json_unquote(json_compact(cast('2015-01-15 23:24:25' as datetime)));
|
|
|
|
|
|
|
|
|
|
# as well as opaque values:
|
|
|
|
|
select cast(st_geomfromtext('point(1 1)') as json);
|
|
|
|
|
select json_unquote(cast(st_geomfromtext('point(1 1)') as json));
|
|
|
|
|
select json_compact(st_geomfromtext('point(1 1)'));
|
|
|
|
|
select json_unquote(json_compact(st_geomfromtext('point(1 1)')));
|
|
|
|
|
|
|
|
|
|
# examples from the wl7909 spec
|
|
|
|
|
# returns the SQL string literal abc
|
|
|
|
@ -1828,7 +1828,7 @@ SELECT JSON_UNQUOTE( 123 );
|
|
|
|
|
|
|
|
|
|
# returns the SQL string literal abc
|
|
|
|
|
SELECT JSON_UNQUOTE
|
|
|
|
|
( CAST( CAST( '"abc"' AS JSON ) AS CHAR ) );
|
|
|
|
|
( CAST( json_compact( '"abc"') AS CHAR ) );
|
|
|
|
|
|
|
|
|
|
# returns 1
|
|
|
|
|
SELECT JSON_UNQUOTE
|
|
|
|
@ -1853,7 +1853,7 @@ SELECT JSON_QUOTE( 'abc' );
|
|
|
|
|
SELECT JSON_QUOTE( 123 );
|
|
|
|
|
|
|
|
|
|
# returns the JSON document consisting of the string scalar "123"
|
|
|
|
|
SELECT CAST( JSON_QUOTE( '123' ) AS JSON );
|
|
|
|
|
SELECT json_compact( JSON_QUOTE( '123' ));
|
|
|
|
|
|
|
|
|
|
--echo # ----------------------------------------------------------------------
|
|
|
|
|
--echo # Test of JSON_CONTAINS
|
|
|
|
@ -1861,47 +1861,47 @@ SELECT CAST( JSON_QUOTE( '123' ) AS JSON );
|
|
|
|
|
|
|
|
|
|
--echo # should give NULL
|
|
|
|
|
select json_contains(NULL, NULL);
|
|
|
|
|
select json_contains(cast('{"a": 1, "b": 2}' as json), NULL);
|
|
|
|
|
select json_contains(NULL, cast('null' as json));
|
|
|
|
|
select json_contains(cast('[1]' as json), cast('[1]' as json), NULL);
|
|
|
|
|
select json_contains(json_compact('{"a": 1, "b": 2}'), NULL);
|
|
|
|
|
select json_contains(NULL, json_compact('null'));
|
|
|
|
|
select json_contains(json_compact('[1]'), json_compact('[1]'), NULL);
|
|
|
|
|
|
|
|
|
|
--echo # should give 0:
|
|
|
|
|
select json_contains(cast(3.14 as json), cast(3 as json));
|
|
|
|
|
select json_contains(json_compact(3.14), json_compact(3));
|
|
|
|
|
|
|
|
|
|
--echo # should give 0: not at top level
|
|
|
|
|
select json_contains(cast('{"a": {"b": 7}}' as json), cast('{"b": 7}' as json));
|
|
|
|
|
select json_contains(json_compact('{"a": {"b": 7}}'), json_compact('{"b": 7}'));
|
|
|
|
|
|
|
|
|
|
--echo # but path argument will fix it:
|
|
|
|
|
select json_contains(cast('{"a": {"b": 7}}' as json), cast('{"b": 7}' as json), '$.a');
|
|
|
|
|
select json_contains(json_compact('{"a": {"b": 7}}'), json_compact('{"b": 7}'), '$.a');
|
|
|
|
|
|
|
|
|
|
--echo # but arrays "introspect"
|
|
|
|
|
select json_contains(cast('[1,[2.0, 3.0]]' as json), cast('[2.0]' as json));
|
|
|
|
|
select json_contains(cast('[1, 2, [3, [4, 5]], 6, 7]' as json), cast('5' as json));
|
|
|
|
|
select json_contains(json_compact('[1,[2.0, 3.0]]'), json_compact('[2.0]'));
|
|
|
|
|
select json_contains(json_compact('[1, 2, [3, [4, 5]], 6, 7]'), json_compact('5'));
|
|
|
|
|
|
|
|
|
|
--echo # should give 0: just a key
|
|
|
|
|
select json_contains(cast('{"a": 1, "b": 2}' as json), cast('"a"' as json));
|
|
|
|
|
select json_contains(json_compact('{"a": 1, "b": 2}'), json_compact('"a"'));
|
|
|
|
|
|
|
|
|
|
--echo # should give 0: one candidate element doesn't match
|
|
|
|
|
select json_contains(cast('[1]' as json), cast('[1,2]' as json));
|
|
|
|
|
select json_contains(json_compact('[1]'), json_compact('[1,2]'));
|
|
|
|
|
|
|
|
|
|
--echo # should all give 1
|
|
|
|
|
select json_contains(cast('null' as json), cast('null' as json));
|
|
|
|
|
select json_contains(json_compact('null'), json_compact('null'));
|
|
|
|
|
--echo # simple object subset
|
|
|
|
|
select json_contains(cast('{"a": 1, "b": 2}' as json), cast( '{"a": 1}' as json));
|
|
|
|
|
select json_contains(json_compact('{"a": 1, "b": 2}'), json_compact( '{"a": 1}'));
|
|
|
|
|
--echo # simple vector subset
|
|
|
|
|
select json_contains(cast('[1, 2, 3]' as json), cast('[1, 3]' as json));
|
|
|
|
|
select json_contains(json_compact('[1, 2, 3]'), json_compact('[1, 3]'));
|
|
|
|
|
--echo # auto-wrap, should give 1
|
|
|
|
|
select json_contains(cast('[1, 2, 3]' as json), cast(3 as json));
|
|
|
|
|
select json_contains(json_compact('[1, 2, 3]'), json_compact(3));
|
|
|
|
|
--echo # ok even with nested cast off elements
|
|
|
|
|
select json_contains(cast('{"person": {"id": 1, "country": "norway"}}' as json),
|
|
|
|
|
cast('{"person": {"country": "norway"}}' as json));
|
|
|
|
|
select json_contains(json_compact('{"person": {"id": 1, "country": "norway"}}'),
|
|
|
|
|
json_compact('{"person": {"country": "norway"}}'));
|
|
|
|
|
--echo # vector reordering and duplicates is ok
|
|
|
|
|
select json_contains(cast('[1,3,5]' as json), cast('[5,3,1,5]' as json));
|
|
|
|
|
select json_contains(json_compact('[1,3,5]'), json_compact('[5,3,1,5]'));
|
|
|
|
|
--echo # ok even with more elts in candidate than in doc
|
|
|
|
|
select json_contains(cast('[{"b": 4, "a":7}]' as json), cast('[{"a":7},{"b":4}]' as json));
|
|
|
|
|
select json_contains(cast('[{"b": 4, "a":7}, 5]' as json), cast('[5, {"a":7, "b":4}]' as json));
|
|
|
|
|
select json_contains(json_compact('[{"b": 4, "a":7}]'), json_compact('[{"a":7},{"b":4}]'));
|
|
|
|
|
select json_contains(json_compact('[{"b": 4, "a":7}, 5]'), json_compact('[5, {"a":7, "b":4}]'));
|
|
|
|
|
--echo # ok even with mixed number types that compare equal
|
|
|
|
|
select json_contains(cast('[{"b": 4, "a":7}, 5.0]' as json), cast('[5, {"a":7.0E0, "b":4}]' as json));
|
|
|
|
|
select json_contains(json_compact('[{"b": 4, "a":7}, 5.0]'), json_compact('[5, {"a":7.0E0, "b":4}]'));
|
|
|
|
|
|
|
|
|
|
# Bug discovered by Rick: used to give 1 (true).
|
|
|
|
|
select json_contains( '{"customer": "cust3"}', '{"customer": "cust1"}' );
|
|
|
|
@ -1919,36 +1919,36 @@ SELECT JSON_CONTAINS('{"a":1}', '{"a":1,"b":2}');
|
|
|
|
|
# returns 1
|
|
|
|
|
SELECT JSON_CONTAINS
|
|
|
|
|
(
|
|
|
|
|
CAST('[1, 4, 6]' AS JSON),
|
|
|
|
|
CAST('[1, 6]' AS JSON)
|
|
|
|
|
json_compact('[1, 4, 6]'),
|
|
|
|
|
json_compact('[1, 6]')
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
# returns 1; even with nested cast off elements
|
|
|
|
|
SELECT JSON_CONTAINS
|
|
|
|
|
(
|
|
|
|
|
CAST('{"person": {"id": 1, "country": "norway"}}' AS JSON),
|
|
|
|
|
CAST('{"person": {"country": "norway"}}' AS JSON)
|
|
|
|
|
json_compact('{"person": {"id": 1, "country": "norway"}}'),
|
|
|
|
|
json_compact('{"person": {"country": "norway"}}')
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
# returns 1; reordering and duplicates are ok
|
|
|
|
|
SELECT JSON_CONTAINS
|
|
|
|
|
(
|
|
|
|
|
CAST('[1,3,5]' AS JSON),
|
|
|
|
|
CAST('[5,3,1,5]' AS JSON)
|
|
|
|
|
json_compact('[1,3,5]'),
|
|
|
|
|
json_compact('[5,3,1,5]')
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
# return 0; no type conversion is performed
|
|
|
|
|
SELECT JSON_CONTAINS
|
|
|
|
|
(
|
|
|
|
|
CAST('[3.14]' AS JSON),
|
|
|
|
|
CAST('[3]' AS JSON)
|
|
|
|
|
json_compact('[3.14]'),
|
|
|
|
|
json_compact('[3]')
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
# returns 1, due to auto-wrapping
|
|
|
|
|
SELECT JSON_CONTAINS
|
|
|
|
|
(
|
|
|
|
|
CAST('[1, 2, 3]' AS JSON),
|
|
|
|
|
CAST(3 AS JSON)
|
|
|
|
|
json_compact('[1, 2, 3]'),
|
|
|
|
|
json_compact(3)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
--error ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT
|
|
|
|
@ -1963,20 +1963,20 @@ SELECT JSON_CONTAINS('[1]', '[1]', '$', '$[0]');
|
|
|
|
|
--echo # Item_func_json_quote::fix_length_and_dec. Bug found by Knut.
|
|
|
|
|
--echo # Similar issue for JSON_UNQUOTE and JSON_TYPE.
|
|
|
|
|
--echo # ----------------------------------------------------------------------
|
|
|
|
|
select json_object("a", ifnull(json_quote('test'), cast('null' as json)));
|
|
|
|
|
select cast(concat('[', json_quote('ab'), ']') as json);
|
|
|
|
|
select cast(concat('[', json_unquote('"12"'), ']') as json);
|
|
|
|
|
select cast(concat('["', json_type(cast(1 as json)), '"]') as json);
|
|
|
|
|
select json_object("a", ifnull(json_quote('test'), json_compact('null')));
|
|
|
|
|
select json_compact(concat('[', json_quote('ab'), ']'));
|
|
|
|
|
select json_compact(concat('[', json_unquote('"12"'), ']'));
|
|
|
|
|
select json_compact(concat('["', json_type( json_compact(1)), '"]'));
|
|
|
|
|
|
|
|
|
|
--echo #
|
|
|
|
|
--echo # Bug#20912438: ITEM_TYPE_HOLDER::DISPLAY_LENGTH(ITEM*): ASSERTION `0' FAILED
|
|
|
|
|
--echo #
|
|
|
|
|
(SELECT JSON_KEYS('{ "key80": "2015-04-20 11:53:55"}')) UNION ALL
|
|
|
|
|
(SELECT JSON_KEYS('{ "key80": "2015-04-20 11:53:55" }') LIMIT 0);
|
|
|
|
|
SELECT CAST(1 AS JSON) UNION ALL SELECT CAST(1 AS JSON);
|
|
|
|
|
SELECT json_compact(1) UNION ALL SELECT json_compact(1);
|
|
|
|
|
|
|
|
|
|
# Exercise NULL handling and error handling in Item_copy_json::copy().
|
|
|
|
|
SELECT COUNT(*), CAST(NULL AS JSON);
|
|
|
|
|
SELECT COUNT(*), json_compact(NULL);
|
|
|
|
|
--echo error ER_INVALID_JSON_TEXT_IN_PARAM
|
|
|
|
|
SELECT COUNT(*), JSON_EXTRACT('not valid json!', '$');
|
|
|
|
|
|
|
|
|
@ -2118,7 +2118,7 @@ execute json_stmt12 USING @mypath;
|
|
|
|
|
--echo #
|
|
|
|
|
|
|
|
|
|
select json_quote( json_type( json_object() ) );
|
|
|
|
|
select json_quote( json_type( cast('{}' as json) ) );
|
|
|
|
|
select json_quote( json_type( json_compact('{}') ) );
|
|
|
|
|
|
|
|
|
|
--echo #
|
|
|
|
|
--echo # Bug#21148020 OUTPUT FROM JSON_TYPE() IS TRUNCATED
|
|
|
|
@ -2130,9 +2130,9 @@ CREATE VIEW v1 AS SELECT JSON_TYPE(JSON_OBJECT());
|
|
|
|
|
SELECT * FROM v1;
|
|
|
|
|
drop view v1;
|
|
|
|
|
|
|
|
|
|
# SELECT JSON_TYPE(CAST(CAST('2015-05-25 11:23:55' AS DATETIME) AS JSON));
|
|
|
|
|
# CREATE VIEW v2 AS SELECT JSON_TYPE(CAST(CAST('2015-05-25 11:23:55' AS
|
|
|
|
|
# DATETIME) AS JSON));
|
|
|
|
|
# SELECT JSON_TYPE(json_compact(CAST('2015-05-25 11:23:55' AS DATETIME)));
|
|
|
|
|
# CREATE VIEW v2 AS SELECT JSON_TYPE(json_compact(CAST('2015-05-25 11:23:55' AS
|
|
|
|
|
# DATETIME)));
|
|
|
|
|
# SELECT * FROM v2;
|
|
|
|
|
# drop view v2;
|
|
|
|
|
|
|
|
|
@ -2284,5 +2284,5 @@ SELECT JSON_REPLACE('[[[1]]]', '$[0][0][0]', 100);
|
|
|
|
|
# a mix of NULLs and JSON values.
|
|
|
|
|
SELECT JSON_ARRAY(LEAST(NULL, NULL), GREATEST(NULL, NULL), LEAST(j1, NULL),
|
|
|
|
|
GREATEST(NULL, j2), LEAST(j1, j2), GREATEST(j1, j2)) AS j
|
|
|
|
|
FROM (SELECT CAST('1' AS JSON) AS j1, CAST('2' AS JSON) AS j2) t;
|
|
|
|
|
FROM (SELECT json_compact('1') AS j1, json_compact('2') AS j2) t;
|
|
|
|
|
|
|
|
|
|