mirror of
https://github.com/MariaDB/server.git
synced 2025-01-27 01:04:19 +01:00
35760c0000
more fixes.
3634 lines
180 KiB
Text
3634 lines
180 KiB
Text
SELECT CAST(0.0e0 AS JSON) = -0.0e0;
|
||
CAST(0.0e0 AS JSON) = -0.0e0
|
||
1
|
||
SELECT CAST(CAST(0 AS DECIMAL) AS JSON) = CAST(-0.0e0 AS DECIMAL);
|
||
CAST(CAST(0 AS DECIMAL) AS JSON) = CAST(-0.0e0 AS DECIMAL)
|
||
1
|
||
SELECT CAST(0.0e0 AS JSON) = CAST(-0.0e0 AS DECIMAL);
|
||
CAST(0.0e0 AS JSON) = CAST(-0.0e0 AS DECIMAL)
|
||
1
|
||
SELECT CAST(CAST(0 AS DECIMAL) AS JSON) = -0.0e0;
|
||
CAST(CAST(0 AS DECIMAL) AS JSON) = -0.0e0
|
||
1
|
||
SELECT CAST(CAST(0 AS SIGNED) AS JSON) = -0.0e0;
|
||
CAST(CAST(0 AS SIGNED) AS JSON) = -0.0e0
|
||
1
|
||
SELECT CAST(CAST(0 AS SIGNED) AS JSON) = CAST(-0.0e0 AS DECIMAL);
|
||
CAST(CAST(0 AS SIGNED) AS JSON) = CAST(-0.0e0 AS DECIMAL)
|
||
1
|
||
SELECT CAST(CAST(0 AS UNSIGNED) AS JSON) = -0.0e0;
|
||
CAST(CAST(0 AS UNSIGNED) AS JSON) = -0.0e0
|
||
1
|
||
SELECT CAST(CAST(0 AS UNSIGNED) AS JSON) = CAST(-0.0e0 AS DECIMAL);
|
||
CAST(CAST(0 AS UNSIGNED) AS JSON) = CAST(-0.0e0 AS DECIMAL)
|
||
1
|
||
select cast('"abc"' as json);
|
||
cast('"abc"' as json)
|
||
"abc"
|
||
error ER_INVALID_JSON_TEXT_IN_PARAM
|
||
select cast('abc' as json);
|
||
cast('abc' as json)
|
||
abc
|
||
|
||
# String literal - valid JSON
|
||
select JSON_VALID('123');
|
||
JSON_VALID('123')
|
||
1
|
||
select JSON_VALID('-123');
|
||
JSON_VALID('-123')
|
||
1
|
||
select JSON_VALID('5000000000');
|
||
JSON_VALID('5000000000')
|
||
1
|
||
select JSON_VALID('-5000000000');
|
||
JSON_VALID('-5000000000')
|
||
1
|
||
select JSON_VALID('1.23');
|
||
JSON_VALID('1.23')
|
||
1
|
||
select JSON_VALID('"123"');
|
||
JSON_VALID('"123"')
|
||
1
|
||
select JSON_VALID('true');
|
||
JSON_VALID('true')
|
||
1
|
||
select JSON_VALID('false');
|
||
JSON_VALID('false')
|
||
1
|
||
select JSON_VALID('null');
|
||
JSON_VALID('null')
|
||
1
|
||
select JSON_VALID('{"address": "Trondheim"}');
|
||
JSON_VALID('{"address": "Trondheim"}')
|
||
1
|
||
|
||
# String literal - not valid JSON
|
||
select JSON_VALID('12 3');
|
||
JSON_VALID('12 3')
|
||
0
|
||
|
||
# String literal not in UTF-8
|
||
set names 'ascii';
|
||
select JSON_VALID('123');
|
||
JSON_VALID('123')
|
||
1
|
||
set names 'utf8';
|
||
|
||
# Json expression
|
||
select JSON_VALID(cast('[123]' as JSON ));
|
||
JSON_VALID(cast('[123]' as JSON ))
|
||
1
|
||
|
||
# Json expression NULL
|
||
select JSON_VALID(cast(NULL as JSON ));
|
||
JSON_VALID(cast(NULL as JSON ))
|
||
NULL
|
||
|
||
# Bare NULL
|
||
select JSON_VALID( NULL );
|
||
JSON_VALID( NULL )
|
||
NULL
|
||
|
||
# Function result - string
|
||
select JSON_VALID( UPPER('"abc"') );
|
||
JSON_VALID( UPPER('"abc"') )
|
||
1
|
||
set names 'latin1';
|
||
|
||
# Function result - string
|
||
select JSON_VALID( UPPER('"abc"') );
|
||
JSON_VALID( UPPER('"abc"') )
|
||
1
|
||
set names 'utf8';
|
||
|
||
# Function result - date, not valid as JSON without CAST
|
||
select JSON_VALID( CAST('2015-01-15' AS DATE) );
|
||
JSON_VALID( CAST('2015-01-15' AS DATE) )
|
||
0
|
||
|
||
# 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') );
|
||
JSON_VALID( CAST(CAST('2015-01-15' AS DATE) as CHAR CHARACTER SET 'utf8') )
|
||
0
|
||
# OK, though:
|
||
select JSON_VALID( CAST(CURDATE() as JSON) );
|
||
JSON_VALID( CAST(CURDATE() as JSON) )
|
||
0
|
||
|
||
# Function result - NULL
|
||
select JSON_VALID( UPPER(NULL) );
|
||
JSON_VALID( UPPER(NULL) )
|
||
NULL
|
||
select JSON_VALID( UPPER(CAST(NULL as CHAR)) );
|
||
JSON_VALID( UPPER(CAST(NULL as CHAR)) )
|
||
NULL
|
||
SELECT JSON_VALID( '{ "firstName" : "Fred", "lastName" : "Flintstone" }' );
|
||
JSON_VALID( '{ "firstName" : "Fred", "lastName" : "Flintstone" }' )
|
||
1
|
||
SELECT JSON_VALID( '3' );
|
||
JSON_VALID( '3' )
|
||
1
|
||
SELECT JSON_VALID( null );
|
||
JSON_VALID( null )
|
||
NULL
|
||
# ----------------------------------------------------------------------
|
||
# Test of JSON_CONTAINS_PATH function.
|
||
# ----------------------------------------------------------------------
|
||
select json_contains_path();
|
||
ERROR 42000: Incorrect parameter count in the call to native function 'json_contains_path'
|
||
select json_contains_path('{ "a": true }' );
|
||
ERROR 42000: Incorrect parameter count in the call to native function 'json_contains_path'
|
||
select json_contains_path('{ "a": true }', 'all' );
|
||
ERROR 42000: Incorrect parameter count in the call to native function 'json_contains_path'
|
||
error ER_INVALID_JSON_TEXT_IN_PARAM
|
||
select json_contains_path('{ "a": tru }', 'all', '$' );
|
||
json_contains_path('{ "a": tru }', 'all', '$' )
|
||
NULL
|
||
Warnings:
|
||
Warning 4038 Syntax error in JSON text in argument 1 to function 'json_contains_path' at position 10
|
||
error ER_INVALID_JSON_PATH
|
||
select json_contains_path('{ "a": true }', 'all', '$[' );
|
||
json_contains_path('{ "a": true }', 'all', '$[' )
|
||
NULL
|
||
Warnings:
|
||
Warning 4041 Unexpected end of JSON path in argument 3 to function 'json_contains_path'
|
||
error ER_INVALID_JSON_PATH
|
||
select json_contains_path('{ "a": true }', 'all', '$a.***[3]' );
|
||
json_contains_path('{ "a": true }', 'all', '$a.***[3]' )
|
||
NULL
|
||
Warnings:
|
||
Warning 4042 Syntax error in JSON path in argument 3 to function 'json_contains_path' at position 2
|
||
error ER_JSON_BAD_ONE_OR_ALL_ARG
|
||
select json_contains_path('{ "a": true }', 'foo', '$.a' );
|
||
json_contains_path('{ "a": true }', 'foo', '$.a' )
|
||
NULL
|
||
Warnings:
|
||
Warning 4046 Argument 2 to function 'json_contains_path' must be "one" or "all".
|
||
error ER_INVALID_JSON_CHARSET
|
||
select json_contains_path('{}', 'all', cast('$' as binary));
|
||
json_contains_path('{}', 'all', cast('$' as binary))
|
||
1
|
||
select json_contains_path(null, 'all', '$.a' );
|
||
json_contains_path(null, 'all', '$.a' )
|
||
NULL
|
||
select json_contains_path('{ "a": true }', null, '$.a' );
|
||
json_contains_path('{ "a": true }', null, '$.a' )
|
||
NULL
|
||
select json_contains_path('{ "a": true }', 'all', null );
|
||
json_contains_path('{ "a": true }', 'all', null )
|
||
NULL
|
||
select json_contains_path('{ "a": true }', 'all', '$' );
|
||
json_contains_path('{ "a": true }', 'all', '$' )
|
||
1
|
||
select json_contains_path('{ "a": true }', 'all', '$.a' );
|
||
json_contains_path('{ "a": true }', 'all', '$.a' )
|
||
1
|
||
select json_contains_path('{ "a": true }', 'one', '$.a' );
|
||
json_contains_path('{ "a": true }', 'one', '$.a' )
|
||
1
|
||
select json_contains_path('{ "a": true }', 'all', '$.b' );
|
||
json_contains_path('{ "a": true }', 'all', '$.b' )
|
||
0
|
||
select json_contains_path('{ "a": true }', 'one', '$.b' );
|
||
json_contains_path('{ "a": true }', 'one', '$.b' )
|
||
0
|
||
select json_contains_path('{ "a": true }', 'all', '$.a', '$.b' );
|
||
json_contains_path('{ "a": true }', 'all', '$.a', '$.b' )
|
||
0
|
||
select json_contains_path('{ "a": true }', 'all', '$.b', '$.a' );
|
||
json_contains_path('{ "a": true }', 'all', '$.b', '$.a' )
|
||
0
|
||
select json_contains_path('{ "a": true }', 'ALL', '$.a', '$.b' );
|
||
json_contains_path('{ "a": true }', 'ALL', '$.a', '$.b' )
|
||
0
|
||
select json_contains_path('{ "a": true }', 'aLl', '$.a', '$.b' );
|
||
json_contains_path('{ "a": true }', 'aLl', '$.a', '$.b' )
|
||
0
|
||
select json_contains_path('{ "a": true }', 'one', '$.a', '$.b' );
|
||
json_contains_path('{ "a": true }', 'one', '$.a', '$.b' )
|
||
1
|
||
select json_contains_path('{ "a": true }', 'one', '$.b', '$.a' );
|
||
json_contains_path('{ "a": true }', 'one', '$.b', '$.a' )
|
||
1
|
||
select json_contains_path('{ "a": true }', 'ONE', '$.a', '$.b' );
|
||
json_contains_path('{ "a": true }', 'ONE', '$.a', '$.b' )
|
||
1
|
||
select json_contains_path('{ "a": true }', 'oNe', '$.a', '$.b' );
|
||
json_contains_path('{ "a": true }', 'oNe', '$.a', '$.b' )
|
||
1
|
||
select json_contains_path('{ "a": true, "b": [ 1, 2, { "c": [ 4, 5, { "d": [ 6, 7, 8, 9, 10 ]} ] } ] }', 'all', '$**[4]' );
|
||
json_contains_path('{ "a": true, "b": [ 1, 2, { "c": [ 4, 5, { "d": [ 6, 7, 8, 9, 10 ]} ] } ] }', 'all', '$**[4]' )
|
||
1
|
||
select json_contains_path('{ "a": true, "b": [ 1, 2, { "c": [ 4, 5, { "d": [ 6, 7, 8, 9, 10 ]} ] } ] }', 'all', '$**[4]', '$**[5]' );
|
||
json_contains_path('{ "a": true, "b": [ 1, 2, { "c": [ 4, 5, { "d": [ 6, 7, 8, 9, 10 ]} ] } ] }', 'all', '$**[4]', '$**[5]' )
|
||
0
|
||
select json_contains_path('{ "a": true, "b": [ 1, 2, { "c": [ 4, 5, { "d": [ 6, 7, 8, 9, 10 ]} ] } ] }', 'all', '$**.c[2]' );
|
||
json_contains_path('{ "a": true, "b": [ 1, 2, { "c": [ 4, 5, { "d": [ 6, 7, 8, 9, 10 ]} ] } ] }', 'all', '$**.c[2]' )
|
||
1
|
||
select json_contains_path('{ "a": true, "b": [ 1, 2, { "c": [ 4, 5, { "d": [ 6, 7, 8, 9, 10 ]} ] } ] }', 'all', '$**.c[3]' );
|
||
json_contains_path('{ "a": true, "b": [ 1, 2, { "c": [ 4, 5, { "d": [ 6, 7, 8, 9, 10 ]} ] } ] }', 'all', '$**.c[3]' )
|
||
0
|
||
select json_contains_path('{"a":1, "b":2}', 'one', '$.*');
|
||
json_contains_path('{"a":1, "b":2}', 'one', '$.*')
|
||
1
|
||
select json_contains_path('[1,2,3]', 'one', '$.*');
|
||
json_contains_path('[1,2,3]', 'one', '$.*')
|
||
0
|
||
select json_contains_path('{}', 'one', '$[*]');
|
||
json_contains_path('{}', 'one', '$[*]')
|
||
0
|
||
SELECT JSON_CONTAINS_PATH('[1, [[{"x": [{"a":{"b":{"c":42}}}]}]]]',
|
||
'one', '$**.a.*');
|
||
JSON_CONTAINS_PATH('[1, [[{"x": [{"a":{"b":{"c":42}}}]}]]]',
|
||
'one', '$**.a.*')
|
||
1
|
||
SELECT JSON_CONTAINS_PATH('[1, [[{"x": [{"a":{"b":{"c":42}}}]}]]]',
|
||
'all', '$**.a.*');
|
||
JSON_CONTAINS_PATH('[1, [[{"x": [{"a":{"b":{"c":42}}}]}]]]',
|
||
'all', '$**.a.*')
|
||
1
|
||
SELECT JSON_CONTAINS_PATH('[1,2,3]', 'one', '$**[*]');
|
||
JSON_CONTAINS_PATH('[1,2,3]', 'one', '$**[*]')
|
||
1
|
||
SELECT JSON_CONTAINS_PATH('[1,2,3]', 'all', '$**[*]');
|
||
JSON_CONTAINS_PATH('[1,2,3]', 'all', '$**[*]')
|
||
1
|
||
select json_contains_path('{ "a": true, "b": [ 1, 2 ] }', 'all', '$**[1]', '$.b[0]', '$.c' );
|
||
json_contains_path('{ "a": true, "b": [ 1, 2 ] }', 'all', '$**[1]', '$.b[0]', '$.c' )
|
||
0
|
||
select json_contains_path('{ "a": true, "b": [ 1, 2 ] }', 'all', '$.c', '$**[1]', '$.b[0]' );
|
||
json_contains_path('{ "a": true, "b": [ 1, 2 ] }', 'all', '$.c', '$**[1]', '$.b[0]' )
|
||
0
|
||
select json_contains_path('{ "a": true, "b": [ 1, 2 ] }', 'all', '$.b[0]', '$.c', '$**[1]' );
|
||
json_contains_path('{ "a": true, "b": [ 1, 2 ] }', 'all', '$.b[0]', '$.c', '$**[1]' )
|
||
0
|
||
select json_contains_path('{ "a": true, "b": [ 1, 2 ] }', 'one', '$**[1]', '$.b[0]', '$.c' );
|
||
json_contains_path('{ "a": true, "b": [ 1, 2 ] }', 'one', '$**[1]', '$.b[0]', '$.c' )
|
||
1
|
||
select json_contains_path('{ "a": true, "b": [ 1, 2 ] }', 'one', '$.c', '$**[1]', '$.b[0]' );
|
||
json_contains_path('{ "a": true, "b": [ 1, 2 ] }', 'one', '$.c', '$**[1]', '$.b[0]' )
|
||
1
|
||
select json_contains_path('{ "a": true, "b": [ 1, 2 ] }', 'one', '$.b[0]', '$.c', '$**[1]' );
|
||
json_contains_path('{ "a": true, "b": [ 1, 2 ] }', 'one', '$.b[0]', '$.c', '$**[1]' )
|
||
1
|
||
SELECT JSON_CONTAINS_PATH
|
||
(
|
||
'{ "a" : 123, "b" : [ 123, 456 ] }',
|
||
'all',
|
||
'$.a.c',
|
||
'$.b[1]'
|
||
);
|
||
JSON_CONTAINS_PATH
|
||
(
|
||
'{ "a" : 123, "b" : [ 123, 456 ] }',
|
||
'all',
|
||
'$.a.c',
|
||
'$.b[1]'
|
||
)
|
||
0
|
||
SELECT JSON_CONTAINS_PATH
|
||
(
|
||
'{ "a" : 123, "b" : [ 123, 456 ] }',
|
||
'one',
|
||
'$.a.c',
|
||
'$.b[1]'
|
||
);
|
||
JSON_CONTAINS_PATH
|
||
(
|
||
'{ "a" : 123, "b" : [ 123, 456 ] }',
|
||
'one',
|
||
'$.a.c',
|
||
'$.b[1]'
|
||
)
|
||
1
|
||
SELECT JSON_CONTAINS_PATH
|
||
(
|
||
'{ "a" : 123, "b" : [ 123, 456 ] }',
|
||
'all',
|
||
'$.c'
|
||
);
|
||
JSON_CONTAINS_PATH
|
||
(
|
||
'{ "a" : 123, "b" : [ 123, 456 ] }',
|
||
'all',
|
||
'$.c'
|
||
)
|
||
0
|
||
SELECT JSON_CONTAINS_PATH
|
||
(
|
||
'{ "a" : 123, "b" : [ 123, { "c" : { "d" : true } } ] }',
|
||
'all',
|
||
'$.b[1].c.d'
|
||
);
|
||
JSON_CONTAINS_PATH
|
||
(
|
||
'{ "a" : 123, "b" : [ 123, { "c" : { "d" : true } } ] }',
|
||
'all',
|
||
'$.b[1].c.d'
|
||
)
|
||
1
|
||
select json_length( null );
|
||
json_length( null )
|
||
NULL
|
||
select json_length( '1' );
|
||
json_length( '1' )
|
||
1
|
||
|
||
# invalid json text
|
||
error ER_INVALID_JSON_TEXT_IN_PARAM
|
||
select json_length( 'abc' );
|
||
json_length( 'abc' )
|
||
NULL
|
||
Warnings:
|
||
Warning 4038 Syntax error in JSON text in argument 1 to function 'json_length' at position 1
|
||
select json_length( '"abc"' );
|
||
json_length( '"abc"' )
|
||
1
|
||
select json_length( 'true' );
|
||
json_length( 'true' )
|
||
1
|
||
select json_length( 'false' );
|
||
json_length( 'false' )
|
||
1
|
||
select json_length( 'null' );
|
||
json_length( 'null' )
|
||
1
|
||
select json_length( '{}' );
|
||
json_length( '{}' )
|
||
0
|
||
select json_length( '{ "a" : 100, "b" : 200 }' );
|
||
json_length( '{ "a" : 100, "b" : 200 }' )
|
||
2
|
||
select json_length( '{ "a" : 100, "b" : [ 300, 400, 500 ] }' );
|
||
json_length( '{ "a" : 100, "b" : [ 300, 400, 500 ] }' )
|
||
2
|
||
select json_length( '[]' );
|
||
json_length( '[]' )
|
||
0
|
||
select json_length( '[ null, "foo", true, 1.1 ]' );
|
||
json_length( '[ null, "foo", true, 1.1 ]' )
|
||
4
|
||
select json_length( '[ null, "foo", true, { "a" : "b", "c" : "d" } ]' );
|
||
json_length( '[ null, "foo", true, { "a" : "b", "c" : "d" } ]' )
|
||
4
|
||
select json_length( '"foo"' );
|
||
json_length( '"foo"' )
|
||
1
|
||
select json_length( '1.2' );
|
||
json_length( '1.2' )
|
||
1
|
||
|
||
# invalid json path
|
||
error ER_INVALID_JSON_PATH
|
||
select json_length( 'true', 'c$' );
|
||
json_length( 'true', 'c$' )
|
||
NULL
|
||
Warnings:
|
||
Warning 4042 Syntax error in JSON path in argument 2 to function 'json_length' at position 1
|
||
|
||
# invalid json path
|
||
error ER_INVALID_JSON_PATH
|
||
select json_length( '{ "foo" : [ true, false ] }', '$.foo[bar]' );
|
||
json_length( '{ "foo" : [ true, false ] }', '$.foo[bar]' )
|
||
NULL
|
||
Warnings:
|
||
Warning 4042 Syntax error in JSON path in argument 2 to function 'json_length' at position 7
|
||
|
||
# wildcards not allowed in path expressions for this function
|
||
error ER_INVALID_JSON_PATH_WILDCARD
|
||
select json_length( 'true', '$.*' );
|
||
json_length( 'true', '$.*' )
|
||
NULL
|
||
Warnings:
|
||
Warning 4044 Wildcards in JSON path not allowed in argument 2 to function 'json_length'
|
||
|
||
# wildcards not allowed in path expressions for this function
|
||
error ER_INVALID_JSON_PATH_WILDCARD
|
||
select json_length( 'true', '$.foo**.bar' );
|
||
json_length( 'true', '$.foo**.bar' )
|
||
NULL
|
||
Warnings:
|
||
Warning 4044 Wildcards in JSON path not allowed in argument 2 to function 'json_length'
|
||
select json_length( '[ 1, [ 2, 3, 4 ], 5 ]', '$[0]' );
|
||
json_length( '[ 1, [ 2, 3, 4 ], 5 ]', '$[0]' )
|
||
1
|
||
select json_length( '[ 1, [ 2, 3, 4 ], 5 ]', '$[1]' );
|
||
json_length( '[ 1, [ 2, 3, 4 ], 5 ]', '$[1]' )
|
||
3
|
||
select json_length( '[ 1, [ 2, 3, 4 ], 5 ]', '$[2]' );
|
||
json_length( '[ 1, [ 2, 3, 4 ], 5 ]', '$[2]' )
|
||
1
|
||
select json_length( '[ 1, [ 2, 3, 4 ], 5 ]', '$[2][0]' );
|
||
json_length( '[ 1, [ 2, 3, 4 ], 5 ]', '$[2][0]' )
|
||
NULL
|
||
select json_length( '[ 1, [ 2, 3, 4 ], {"a": 1} ]', '$[2][0]' );
|
||
json_length( '[ 1, [ 2, 3, 4 ], {"a": 1} ]', '$[2][0]' )
|
||
NULL
|
||
select json_length( '[ 1, [ 2, 3, 4 ], 5 ]', '$[2][1]' );
|
||
json_length( '[ 1, [ 2, 3, 4 ], 5 ]', '$[2][1]' )
|
||
NULL
|
||
select json_length( '[ 1, { "a": true, "b": false, "c": null }, 5 ]', '$[1]' );
|
||
json_length( '[ 1, { "a": true, "b": false, "c": null }, 5 ]', '$[1]' )
|
||
3
|
||
SELECT JSON_LENGTH
|
||
(
|
||
'{}'
|
||
);
|
||
JSON_LENGTH
|
||
(
|
||
'{}'
|
||
)
|
||
0
|
||
SELECT JSON_LENGTH
|
||
(
|
||
'3'
|
||
);
|
||
JSON_LENGTH
|
||
(
|
||
'3'
|
||
)
|
||
1
|
||
SELECT JSON_LENGTH
|
||
(
|
||
'{ "a" : 123, "b" : [ 123, 456, 789 ] }'
|
||
);
|
||
JSON_LENGTH
|
||
(
|
||
'{ "a" : 123, "b" : [ 123, 456, 789 ] }'
|
||
)
|
||
2
|
||
SELECT JSON_LENGTH
|
||
(
|
||
'{ "a" : 123, "b" : [ 123, 456, 789 ] }',
|
||
'$.b'
|
||
);
|
||
JSON_LENGTH
|
||
(
|
||
'{ "a" : 123, "b" : [ 123, 456, 789 ] }',
|
||
'$.b'
|
||
)
|
||
3
|
||
SELECT JSON_LENGTH
|
||
(
|
||
'{ "a" : 123, "b" : [ 123, 456, 789 ] }',
|
||
'$.c'
|
||
);
|
||
JSON_LENGTH
|
||
(
|
||
'{ "a" : 123, "b" : [ 123, 456, 789 ] }',
|
||
'$.c'
|
||
)
|
||
NULL
|
||
# ----------------------------------------------------------------------
|
||
# Test of JSON_DEPTH function.
|
||
# ----------------------------------------------------------------------
|
||
select json_depth(null);
|
||
json_depth(null)
|
||
NULL
|
||
select json_depth(cast(null as json));
|
||
json_depth(cast(null as json))
|
||
NULL
|
||
select json_depth(cast('[]' as json)),
|
||
json_depth(cast('{}' as json)),
|
||
json_depth(cast('null' as json)),
|
||
json_depth(json_quote('foo'));
|
||
json_depth(cast('[]' as json)) json_depth(cast('{}' as json)) json_depth(cast('null' as json)) json_depth(json_quote('foo'))
|
||
1 1 1 1
|
||
select json_depth(cast('[[2], 3, [[[4]]]]' as json));
|
||
json_depth(cast('[[2], 3, [[[4]]]]' as json))
|
||
5
|
||
select json_depth(cast('{"a": {"a1": [3]}, "b": {"b1": {"c": {"d": [5]}}}}' as json));
|
||
json_depth(cast('{"a": {"a1": [3]}, "b": {"b1": {"c": {"d": [5]}}}}' as json))
|
||
6
|
||
SELECT JSON_DEPTH
|
||
(
|
||
'{}'
|
||
);
|
||
JSON_DEPTH
|
||
(
|
||
'{}'
|
||
)
|
||
1
|
||
SELECT JSON_DEPTH
|
||
(
|
||
'[]'
|
||
);
|
||
JSON_DEPTH
|
||
(
|
||
'[]'
|
||
)
|
||
1
|
||
SELECT JSON_DEPTH( '"abc"' );
|
||
JSON_DEPTH( '"abc"' )
|
||
1
|
||
SELECT JSON_DEPTH( CAST( '"abc"' AS JSON ) );
|
||
JSON_DEPTH( CAST( '"abc"' AS JSON ) )
|
||
1
|
||
error ER_INVALID_TYPE_FOR_JSON
|
||
SELECT JSON_DEPTH( 1 );
|
||
JSON_DEPTH( 1 )
|
||
1
|
||
error ER_INVALID_JSON_TEXT_IN_PARAM
|
||
SELECT JSON_DEPTH( 'abc' );
|
||
JSON_DEPTH( 'abc' )
|
||
NULL
|
||
Warnings:
|
||
Warning 4038 Syntax error in JSON text in argument 1 to function 'json_depth' at position 1
|
||
SELECT JSON_DEPTH( CAST( 1 AS JSON ) );
|
||
JSON_DEPTH( CAST( 1 AS JSON ) )
|
||
1
|
||
SELECT JSON_DEPTH
|
||
(
|
||
'{ "a" : true, "b" : false, "c" : null }'
|
||
);
|
||
JSON_DEPTH
|
||
(
|
||
'{ "a" : true, "b" : false, "c" : null }'
|
||
)
|
||
2
|
||
SELECT JSON_DEPTH
|
||
(
|
||
'[ "a", true, "b" , false, "c" , null ]'
|
||
);
|
||
JSON_DEPTH
|
||
(
|
||
'[ "a", true, "b" , false, "c" , null ]'
|
||
)
|
||
2
|
||
SELECT JSON_DEPTH
|
||
(
|
||
'{ "a" : true, "b" : {}, "c" : null }'
|
||
);
|
||
JSON_DEPTH
|
||
(
|
||
'{ "a" : true, "b" : {}, "c" : null }'
|
||
)
|
||
2
|
||
SELECT JSON_DEPTH
|
||
(
|
||
'[ "a", true, "b" , {}, "c" , null ]'
|
||
);
|
||
JSON_DEPTH
|
||
(
|
||
'[ "a", true, "b" , {}, "c" , null ]'
|
||
)
|
||
2
|
||
SELECT JSON_DEPTH
|
||
(
|
||
'{ "a" : true, "b" : { "e" : false }, "c" : null }'
|
||
);
|
||
JSON_DEPTH
|
||
(
|
||
'{ "a" : true, "b" : { "e" : false }, "c" : null }'
|
||
)
|
||
3
|
||
SELECT JSON_DEPTH
|
||
(
|
||
'[ "a", true, "b" , { "e" : false }, "c" , null ]'
|
||
);
|
||
JSON_DEPTH
|
||
(
|
||
'[ "a", true, "b" , { "e" : false }, "c" , null ]'
|
||
)
|
||
3
|
||
error ER_INVALID_JSON_TEXT_IN_PARAM
|
||
SELECT JSON_DEPTH
|
||
(
|
||
'[ "a", true, "b" , { "e" : false }, "c" , null'
|
||
);
|
||
JSON_DEPTH
|
||
(
|
||
'[ "a", true, "b" , { "e" : false }, "c" , null'
|
||
)
|
||
NULL
|
||
Warnings:
|
||
Warning 4037 Unexpected end of JSON text in argument 1 to function 'json_depth'
|
||
# ----------------------------------------------------------------------
|
||
# Test of JSON_REMOVE function.
|
||
# ----------------------------------------------------------------------
|
||
select json_remove( null, '$[1]' );
|
||
json_remove( null, '$[1]' )
|
||
NULL
|
||
select json_remove( null, '$[1]' ) is null;
|
||
json_remove( null, '$[1]' ) is null
|
||
1
|
||
select json_remove( '[ 1, { "a": true, "b": false, "c": null }, 5 ]', null );
|
||
json_remove( '[ 1, { "a": true, "b": false, "c": null }, 5 ]', null )
|
||
NULL
|
||
select json_remove( '[ 1, { "a": true, "b": false, "c": null }, 5 ]', null ) is null;
|
||
json_remove( '[ 1, { "a": true, "b": false, "c": null }, 5 ]', null ) is null
|
||
1
|
||
select json_remove( '[ 1, { "a": true, "b": false, "c": null }, 5 ]', '$[1]', null );
|
||
json_remove( '[ 1, { "a": true, "b": false, "c": null }, 5 ]', '$[1]', null )
|
||
NULL
|
||
select json_remove( '[ 1, { "a": true, "b": false, "c": null }, 5 ]', '$[1]', null ) is null;
|
||
json_remove( '[ 1, { "a": true, "b": false, "c": null }, 5 ]', '$[1]', null ) is null
|
||
1
|
||
|
||
# not enough args
|
||
select json_remove();
|
||
ERROR 42000: Incorrect parameter count in the call to native function 'json_remove'
|
||
|
||
# not enough args
|
||
select json_remove( '[ 1, { "a": true, "b": false, "c": null }, 5 ]' );
|
||
ERROR 42000: Incorrect parameter count in the call to native function 'json_remove'
|
||
|
||
# not enough args
|
||
select json_remove( '$[1]' );
|
||
ERROR 42000: Incorrect parameter count in the call to native function 'json_remove'
|
||
|
||
# invalid json text
|
||
error ER_INVALID_JSON_TEXT_IN_PARAM
|
||
select json_remove( '[ 1, { "a": true, "b": false, "c": null }, 5 ', '$[1]', '$[2]' );
|
||
json_remove( '[ 1, { "a": true, "b": false, "c": null }, 5 ', '$[1]', '$[2]' )
|
||
NULL
|
||
Warnings:
|
||
Warning 4037 Unexpected end of JSON text in argument 1 to function 'json_remove'
|
||
|
||
# invalid json path
|
||
error ER_INVALID_JSON_PATH
|
||
select json_remove( '[ 1, { "a": true, "b": false, "c": null }, 5 ]', '$[1', '$[2]' );
|
||
json_remove( '[ 1, { "a": true, "b": false, "c": null }, 5 ]', '$[1', '$[2]' )
|
||
NULL
|
||
Warnings:
|
||
Warning 4041 Unexpected end of JSON path in argument 2 to function 'json_remove'
|
||
|
||
# invalid json path
|
||
error ER_INVALID_JSON_PATH
|
||
select json_remove( '[ 1, { "a": true, "b": false, "c": null }, 5 ]', '$[1]', '$[2' );
|
||
json_remove( '[ 1, { "a": true, "b": false, "c": null }, 5 ]', '$[1]', '$[2' )
|
||
NULL
|
||
Warnings:
|
||
Warning 4041 Unexpected end of JSON path in argument 3 to function 'json_remove'
|
||
|
||
# Vacuous path expression
|
||
error ER_JSON_VACUOUS_PATH
|
||
select json_remove( '[ 1, 2, 3 ]', '$' );
|
||
json_remove( '[ 1, 2, 3 ]', '$' )
|
||
NULL
|
||
Warnings:
|
||
Warning 4051 Path expression '$' is not allowed in argument 2 to function 'json_remove'.
|
||
|
||
# Vacuous path expression
|
||
error ER_JSON_VACUOUS_PATH
|
||
select json_remove( '[ 1, 2, 3 ]', '$', '$[2]' );
|
||
json_remove( '[ 1, 2, 3 ]', '$', '$[2]' )
|
||
NULL
|
||
Warnings:
|
||
Warning 4051 Path expression '$' is not allowed in argument 2 to function 'json_remove'.
|
||
|
||
# Vacuous path expression
|
||
error ER_JSON_VACUOUS_PATH
|
||
select json_remove( '[ 1, 2, 3 ]', '$[1]', '$' );
|
||
json_remove( '[ 1, 2, 3 ]', '$[1]', '$' )
|
||
NULL
|
||
Warnings:
|
||
Warning 4051 Path expression '$' is not allowed in argument 3 to function 'json_remove'.
|
||
error ER_INVALID_JSON_PATH_WILDCARD
|
||
select json_remove( '[ 1, 2, 3 ]', '$[*]' );
|
||
json_remove( '[ 1, 2, 3 ]', '$[*]' )
|
||
NULL
|
||
Warnings:
|
||
Warning 4044 Wildcards in JSON path not allowed in argument 2 to function 'json_remove'
|
||
error ER_INVALID_JSON_PATH_WILDCARD
|
||
select json_remove( '[ 1, 2, 3 ]', '$**[2]' );
|
||
json_remove( '[ 1, 2, 3 ]', '$**[2]' )
|
||
NULL
|
||
Warnings:
|
||
Warning 4044 Wildcards in JSON path not allowed in argument 2 to function 'json_remove'
|
||
error ER_INVALID_JSON_PATH_WILDCARD
|
||
select json_remove( '[ 1, 2, 3 ]', '$[2]', '$[*]' );
|
||
json_remove( '[ 1, 2, 3 ]', '$[2]', '$[*]' )
|
||
NULL
|
||
Warnings:
|
||
Warning 4044 Wildcards in JSON path not allowed in argument 3 to function 'json_remove'
|
||
error ER_INVALID_JSON_PATH_WILDCARD
|
||
select json_remove( '[ 1, 2, 3 ]', '$[2]', '$**[2]' );
|
||
json_remove( '[ 1, 2, 3 ]', '$[2]', '$**[2]' )
|
||
NULL
|
||
Warnings:
|
||
Warning 4044 Wildcards in JSON path not allowed in argument 3 to function 'json_remove'
|
||
select json_remove( '[ 1, 2, 3 ]', '$[0]' );
|
||
json_remove( '[ 1, 2, 3 ]', '$[0]' )
|
||
[ 2, 3 ]
|
||
select json_remove( '[ 1, 2, 3 ]', '$[1]' );
|
||
json_remove( '[ 1, 2, 3 ]', '$[1]' )
|
||
[ 1, 3 ]
|
||
select json_remove( '[ 1, 2, 3 ]', '$[2]' );
|
||
json_remove( '[ 1, 2, 3 ]', '$[2]' )
|
||
[ 1, 2]
|
||
select json_remove( '[ 1, 2, 3 ]', '$[3]' );
|
||
json_remove( '[ 1, 2, 3 ]', '$[3]' )
|
||
[ 1, 2, 3 ]
|
||
select json_remove( '[ 1, { "a": true, "b": false, "c": null }, 5 ]', '$[1]' );
|
||
json_remove( '[ 1, { "a": true, "b": false, "c": null }, 5 ]', '$[1]' )
|
||
[ 1, 5 ]
|
||
error ER_INVALID_JSON_PATH_WILDCARD
|
||
select json_remove( '[ { "a": { "a": true } } ]', '$**.a' );
|
||
json_remove( '[ { "a": { "a": true } } ]', '$**.a' )
|
||
NULL
|
||
Warnings:
|
||
Warning 4044 Wildcards in JSON path not allowed in argument 2 to function 'json_remove'
|
||
select json_remove( '[ { "a": true }, { "b": false }, { "c": null }, { "a": null } ]', '$[0].a', '$[2].c' );
|
||
json_remove( '[ { "a": true }, { "b": false }, { "c": null }, { "a": null } ]', '$[0].a', '$[2].c' )
|
||
[ { }, { "b": false }, { }, { "a": null } ]
|
||
error ER_INVALID_JSON_PATH_WILDCARD
|
||
select json_remove( '[ { "a": true }, { "b": [ { "c": { "a": true } } ] }, { "c": null }, { "a": null } ]', '$**.a' );
|
||
json_remove( '[ { "a": true }, { "b": [ { "c": { "a": true } } ] }, { "c": null }, { "a": null } ]', '$**.a' )
|
||
NULL
|
||
Warnings:
|
||
Warning 4044 Wildcards in JSON path not allowed in argument 2 to function 'json_remove'
|
||
select json_remove( '{"id": 123, "name": "systemQA", "array": [1, 2, 3]}', '$[0]' );
|
||
json_remove( '{"id": 123, "name": "systemQA", "array": [1, 2, 3]}', '$[0]' )
|
||
{"id": 123, "name": "systemQA", "array": [1, 2, 3]}
|
||
SELECT JSON_REMOVE
|
||
(
|
||
'{"a" : "foo", "b" : [true, {"c" : 123}]}',
|
||
'$.b[ 1 ]'
|
||
);
|
||
JSON_REMOVE
|
||
(
|
||
'{"a" : "foo", "b" : [true, {"c" : 123}]}',
|
||
'$.b[ 1 ]'
|
||
)
|
||
{"a" : "foo", "b" : [true, {"c" : 123}]}
|
||
SELECT JSON_REMOVE
|
||
(
|
||
'{ "a" : "foo", "b" : [ true, { "c" : 123, "c" : 456 } ] }',
|
||
'$.b[ 1 ].c'
|
||
);
|
||
JSON_REMOVE
|
||
(
|
||
'{ "a" : "foo", "b" : [ true, { "c" : 123, "c" : 456 } ] }',
|
||
'$.b[ 1 ].c'
|
||
)
|
||
NULL
|
||
Warnings:
|
||
Warning 4037 Unexpected end of JSON text in argument 1 to function 'json_remove'
|
||
SELECT JSON_REMOVE
|
||
(
|
||
'{ "a" : "foo", "b" : [ true, { "c" : 123 } ] }',
|
||
'$.b[ 1 ].c'
|
||
);
|
||
JSON_REMOVE
|
||
(
|
||
'{ "a" : "foo", "b" : [ true, { "c" : 123 } ] }',
|
||
'$.b[ 1 ].c'
|
||
)
|
||
NULL
|
||
Warnings:
|
||
Warning 4037 Unexpected end of JSON text in argument 1 to function 'json_remove'
|
||
SELECT JSON_REMOVE
|
||
(
|
||
'{ "a" : "foo", "b" : [ true, { "c" : 123, "d" : 456 } ] }',
|
||
'$.b[ 1 ].e'
|
||
);
|
||
JSON_REMOVE
|
||
(
|
||
'{ "a" : "foo", "b" : [ true, { "c" : 123, "d" : 456 } ] }',
|
||
'$.b[ 1 ].e'
|
||
)
|
||
NULL
|
||
Warnings:
|
||
Warning 4037 Unexpected end of JSON text in argument 1 to function 'json_remove'
|
||
# ----------------------------------------------------------------------
|
||
# Test of JSON_MERGE function.
|
||
# ----------------------------------------------------------------------
|
||
|
||
# not enough args
|
||
select json_merge();
|
||
ERROR 42000: Incorrect parameter count in the call to native function 'json_merge'
|
||
|
||
# not enough args
|
||
select json_merge( '[ 1, 2, 3 ]' );
|
||
ERROR 42000: Incorrect parameter count in the call to native function 'json_merge'
|
||
select json_merge( null, null );
|
||
json_merge( null, null )
|
||
NULL
|
||
select json_merge( null, '[ 1, 2, 3 ]' );
|
||
json_merge( null, '[ 1, 2, 3 ]' )
|
||
NULL
|
||
select json_merge( '[ 1, 2, 3 ]', null );
|
||
json_merge( '[ 1, 2, 3 ]', null )
|
||
NULL
|
||
select json_merge( null, '[ 1, 2, 3 ]', '[ 4, 5, 6 ]' );
|
||
json_merge( null, '[ 1, 2, 3 ]', '[ 4, 5, 6 ]' )
|
||
NULL
|
||
select json_merge( '[ 1, 2, 3 ]', null, '[ 4, 5, 6 ]' );
|
||
json_merge( '[ 1, 2, 3 ]', null, '[ 4, 5, 6 ]' )
|
||
NULL
|
||
select json_merge( '[ 1, 2, 3 ]', '[ 4, 5, 6 ]', null );
|
||
json_merge( '[ 1, 2, 3 ]', '[ 4, 5, 6 ]', null )
|
||
NULL
|
||
error ER_INVALID_JSON_TEXT_IN_PARAM
|
||
select json_merge( '[1, 2]', '[3, 4' );
|
||
json_merge( '[1, 2]', '[3, 4' )
|
||
[1, 2, 3, 4
|
||
error ER_INVALID_JSON_TEXT_IN_PARAM
|
||
select json_merge( '[1, 2', '[3, 4]' );
|
||
json_merge( '[1, 2', '[3, 4]' )
|
||
NULL
|
||
Warnings:
|
||
Warning 4037 Unexpected end of JSON text in argument 1 to function 'json_merge'
|
||
select json_merge( '1', '2' );
|
||
json_merge( '1', '2' )
|
||
[1, 2]
|
||
select json_merge( '1', '[2, 3]' );
|
||
json_merge( '1', '[2, 3]' )
|
||
[1, 2, 3]
|
||
select json_merge( '[1, 2]', '3' );
|
||
json_merge( '[1, 2]', '3' )
|
||
[1, 2, 3]
|
||
select json_merge( '1', '{ "a": 2 }' );
|
||
json_merge( '1', '{ "a": 2 }' )
|
||
[1, { "a": 2 }]
|
||
select json_merge( '{ "a": 2 }', '1' );
|
||
json_merge( '{ "a": 2 }', '1' )
|
||
[{ "a": 2 }, 1]
|
||
select json_merge( '[1, 2]', '[3, 4]' );
|
||
json_merge( '[1, 2]', '[3, 4]' )
|
||
[1, 2, 3, 4]
|
||
select json_merge( '{ "a": 2 }', '{ "b": 3}' );
|
||
json_merge( '{ "a": 2 }', '{ "b": 3}' )
|
||
{ "a": 2 , "b": 3}
|
||
select json_merge( '[1, 2]', '{ "a": 2 }' );
|
||
json_merge( '[1, 2]', '{ "a": 2 }' )
|
||
[1, 2, { "a": 2 }]
|
||
select json_merge( '{ "a": 2 }', '[1, 2]' );
|
||
json_merge( '{ "a": 2 }', '[1, 2]' )
|
||
[{ "a": 2 }, 1, 2]
|
||
select json_merge( '{"a": 1, "b": 2 }', '{"b": 3, "d": 4 }' );
|
||
json_merge( '{"a": 1, "b": 2 }', '{"b": 3, "d": 4 }' )
|
||
{"a": 1, "b": 2 , "b": 3, "d": 4 }
|
||
select json_merge( '{"a": 1, "b": 2 }', '{"b": [3, 4], "d": 4 }' );
|
||
json_merge( '{"a": 1, "b": 2 }', '{"b": [3, 4], "d": 4 }' )
|
||
{"a": 1, "b": 2 , "b": [3, 4], "d": 4 }
|
||
select json_merge( '{"a": 1, "b": [2, 3] }', '{"b": 4, "d": 4 }' );
|
||
json_merge( '{"a": 1, "b": [2, 3] }', '{"b": 4, "d": 4 }' )
|
||
{"a": 1, "b": [2, 3] , "b": 4, "d": 4 }
|
||
select json_merge( '{"a": 1, "b": 2 }', '{"b": {"e": 7, "f": 8}, "d": 4 }' );
|
||
json_merge( '{"a": 1, "b": 2 }', '{"b": {"e": 7, "f": 8}, "d": 4 }' )
|
||
{"a": 1, "b": 2 , "b": {"e": 7, "f": 8}, "d": 4 }
|
||
select json_merge( '{"b": {"e": 7, "f": 8}, "d": 4 }', '{"a": 1, "b": 2 }' );
|
||
json_merge( '{"b": {"e": 7, "f": 8}, "d": 4 }', '{"a": 1, "b": 2 }' )
|
||
{"b": {"e": 7, "f": 8}, "d": 4 , "a": 1, "b": 2 }
|
||
select json_merge( '{"a": 1, "b": [2, 9] }', '{"b": [10, 11], "d": 4 }' );
|
||
json_merge( '{"a": 1, "b": [2, 9] }', '{"b": [10, 11], "d": 4 }' )
|
||
{"a": 1, "b": [2, 9] , "b": [10, 11], "d": 4 }
|
||
select json_merge( '{"a": 1, "b": [2, 9] }', '{"b": {"e": 7, "f": 8}, "d": 4 }' );
|
||
json_merge( '{"a": 1, "b": [2, 9] }', '{"b": {"e": 7, "f": 8}, "d": 4 }' )
|
||
{"a": 1, "b": [2, 9] , "b": {"e": 7, "f": 8}, "d": 4 }
|
||
select json_merge( '{"b": {"e": 7, "f": 8}, "d": 4 }', '{"a": 1, "b": [2, 9] }' );
|
||
json_merge( '{"b": {"e": 7, "f": 8}, "d": 4 }', '{"a": 1, "b": [2, 9] }' )
|
||
{"b": {"e": 7, "f": 8}, "d": 4 , "a": 1, "b": [2, 9] }
|
||
select json_merge( '{"b": {"e": 7, "f": 8}, "d": 4 }', '{ "a": 1, "b": {"e": 20, "g": 21 } }' );
|
||
json_merge( '{"b": {"e": 7, "f": 8}, "d": 4 }', '{ "a": 1, "b": {"e": 20, "g": 21 } }' )
|
||
{"b": {"e": 7, "f": 8}, "d": 4 , "a": 1, "b": {"e": 20, "g": 21 } }
|
||
select json_merge( '1', '2', '3' );
|
||
json_merge( '1', '2', '3' )
|
||
[1, 2, 3]
|
||
select json_merge( '[1, 2 ]', '3', '[4, 5]' );
|
||
json_merge( '[1, 2 ]', '3', '[4, 5]' )
|
||
[1, 2 , 3, 4, 5]
|
||
select json_merge
|
||
(
|
||
'{ "a": true, "b": { "c": 3, "d": 4 }, "e": [ 1, 2 ] }',
|
||
'{ "d": false, "b": { "g": 3, "d": 5 }, "f": [ 1, 2 ] }',
|
||
'{ "m": true, "b": { "h": 8, "d": 4 }, "e": [ 3, 4 ] }'
|
||
);
|
||
json_merge
|
||
(
|
||
'{ "a": true, "b": { "c": 3, "d": 4 }, "e": [ 1, 2 ] }',
|
||
'{ "d": false, "b": { "g": 3, "d": 5 }, "f": [ 1, 2 ] }',
|
||
'{ "m": true, "b": { "h": 8, "d": 4 }, "e": [ 3, 4 ] }'
|
||
)
|
||
{ "a": true, "b": { "c": 3, "d": 4 }, "e": [ 1, 2 ] , "d": false, "b": { "g": 3, "d": 5 }, "f": [ 1, 2 ] , "m": true, "b": { "h": 8, "d": 4 }, "e": [ 3, 4 ] }
|
||
SELECT JSON_MERGE
|
||
(
|
||
'{ "a" : "foo", "b" : [ true, { "c" : 123 } ] }',
|
||
'[ 5, 6]'
|
||
);
|
||
JSON_MERGE
|
||
(
|
||
'{ "a" : "foo", "b" : [ true, { "c" : 123 } ] }',
|
||
'[ 5, 6]'
|
||
)
|
||
[{ "a" : "foo", "b" : [ true, { "c" : 123 } ] }, 5, 6]
|
||
SELECT JSON_MERGE
|
||
(
|
||
'{ "a" : "foo", "b" : [ true, { "c" : 123 } ] }',
|
||
'{ "b": [ false, 34 ] }'
|
||
);
|
||
JSON_MERGE
|
||
(
|
||
'{ "a" : "foo", "b" : [ true, { "c" : 123 } ] }',
|
||
'{ "b": [ false, 34 ] }'
|
||
)
|
||
{ "a" : "foo", "b" : [ true, { "c" : 123 } ] , "b": [ false, 34 ] }
|
||
SELECT JSON_MERGE
|
||
(
|
||
'{ "a" : "foo", "b" : [ true, { "c" : 123 } ] }',
|
||
'{ "b": "bar" }'
|
||
);
|
||
JSON_MERGE
|
||
(
|
||
'{ "a" : "foo", "b" : [ true, { "c" : 123 } ] }',
|
||
'{ "b": "bar" }'
|
||
)
|
||
{ "a" : "foo", "b" : [ true, { "c" : 123 } ] , "b": "bar" }
|
||
SELECT JSON_MERGE
|
||
(
|
||
'{ "a" : { "b" : 1 } }',
|
||
'{ "a" : { "c" : 1 } }'
|
||
);
|
||
JSON_MERGE
|
||
(
|
||
'{ "a" : { "b" : 1 } }',
|
||
'{ "a" : { "c" : 1 } }'
|
||
)
|
||
{ "a" : { "b" : 1 } , "a" : { "c" : 1 } }
|
||
# ----------------------------------------------------------------------
|
||
# Test of JSON_TYPE function.
|
||
# ----------------------------------------------------------------------
|
||
error ER_INVALID_JSON_TEXT_IN_PARAM
|
||
select json_type('abc');
|
||
json_type('abc')
|
||
NULL
|
||
Warnings:
|
||
Warning 4038 Syntax error in JSON text in argument 1 to function 'json_type' at position 1
|
||
select json_type('{"a": 2}');
|
||
json_type('{"a": 2}')
|
||
OBJECT
|
||
select json_type('[1,2]');
|
||
json_type('[1,2]')
|
||
ARRAY
|
||
select json_type('"scalar string"');
|
||
json_type('"scalar string"')
|
||
STRING
|
||
select json_type('true');
|
||
json_type('true')
|
||
BOOLEAN
|
||
select json_type('false');
|
||
json_type('false')
|
||
BOOLEAN
|
||
select json_type('null');
|
||
json_type('null')
|
||
NULL
|
||
select json_type('1');
|
||
json_type('1')
|
||
INTEGER
|
||
select json_type('-0');
|
||
json_type('-0')
|
||
INTEGER
|
||
select json_type('-0.0');
|
||
json_type('-0.0')
|
||
DOUBLE
|
||
error ER_INVALID_TYPE_FOR_JSON
|
||
select json_type(-1);
|
||
json_type(-1)
|
||
INTEGER
|
||
error ER_INVALID_TYPE_FOR_JSON
|
||
select json_type(CAST(1 AS UNSIGNED));
|
||
json_type(CAST(1 AS UNSIGNED))
|
||
INTEGER
|
||
select json_type('32767');
|
||
json_type('32767')
|
||
INTEGER
|
||
error ER_INVALID_TYPE_FOR_JSON
|
||
select json_type(PI());
|
||
json_type(PI())
|
||
DOUBLE
|
||
select json_type('3.14');
|
||
json_type('3.14')
|
||
DOUBLE
|
||
error ER_INVALID_JSON_TEXT_IN_PARAM
|
||
select json_type(CAST(CAST('2015-01-15' AS DATE) as CHAR CHARACTER SET 'utf8'));
|
||
json_type(CAST(CAST('2015-01-15' AS DATE) as CHAR CHARACTER SET 'utf8'))
|
||
INTEGER
|
||
# ----------------------------------------------------------------------
|
||
# Test of CAST(literal AS JSON)
|
||
# ----------------------------------------------------------------------
|
||
select json_type(cast(cast('2014-11-25 18:00' as datetime) as json));
|
||
json_type(cast(cast('2014-11-25 18:00' as datetime) as json))
|
||
INTEGER
|
||
select json_type(cast(cast('2014-11-25' as date) as json));
|
||
json_type(cast(cast('2014-11-25' as date) as json))
|
||
INTEGER
|
||
select json_type(cast(cast('18:00:59' as time) as json));
|
||
json_type(cast(cast('18:00:59' as time) as json))
|
||
INTEGER
|
||
select json_type(cast(127 as json));
|
||
json_type(cast(127 as json))
|
||
INTEGER
|
||
select json_type(cast(255 as json));
|
||
json_type(cast(255 as json))
|
||
INTEGER
|
||
select json_type(cast(32767 as json));
|
||
json_type(cast(32767 as json))
|
||
INTEGER
|
||
select json_type(cast(65535 as json));
|
||
json_type(cast(65535 as json))
|
||
INTEGER
|
||
select json_type(cast(8388607 as json));
|
||
json_type(cast(8388607 as json))
|
||
INTEGER
|
||
select json_type(cast(16777215 as json));
|
||
json_type(cast(16777215 as json))
|
||
INTEGER
|
||
select json_type(cast(2147483647 as json));
|
||
json_type(cast(2147483647 as json))
|
||
INTEGER
|
||
select json_type(cast(4294967295 as json));
|
||
json_type(cast(4294967295 as json))
|
||
INTEGER
|
||
select json_type(cast(9223372036854775807 as json));
|
||
json_type(cast(9223372036854775807 as json))
|
||
INTEGER
|
||
select json_type(cast(18446744073709551615 as json));
|
||
json_type(cast(18446744073709551615 as json))
|
||
INTEGER
|
||
select json_type(cast(true as json));
|
||
json_type(cast(true as json))
|
||
INTEGER
|
||
select json_type(cast(b'10101' as json));
|
||
json_type(cast(b'10101' as json))
|
||
NULL
|
||
Warnings:
|
||
Warning 4036 Character disallowd in JSON in argument 1 to function 'json_type' at position 1
|
||
select json_type(cast(cast(3.14 as decimal(5,2)) as json));
|
||
json_type(cast(cast(3.14 as decimal(5,2)) as json))
|
||
DOUBLE
|
||
select json_type(cast(3.14 as json));
|
||
json_type(cast(3.14 as json))
|
||
DOUBLE
|
||
select json_type(cast(3.14E30 as json));
|
||
json_type(cast(3.14E30 as json))
|
||
NULL
|
||
Warnings:
|
||
Warning 4038 Syntax error in JSON text in argument 1 to function 'json_type' at position 7
|
||
select json_type(cast(cast('10101abcde' as binary) as json));
|
||
json_type(cast(cast('10101abcde' as binary) as json))
|
||
INTEGER
|
||
select json_type(cast(ST_GeomFromText('POINT(1 1)') as json));
|
||
json_type(cast(ST_GeomFromText('POINT(1 1)') as json))
|
||
NULL
|
||
Warnings:
|
||
Warning 4036 Character disallowd in JSON in argument 1 to function 'json_type' at position 1
|
||
select json_type(cast(ST_GeomFromText('LINESTRING(0 0,1 1,2 2)') as json));
|
||
json_type(cast(ST_GeomFromText('LINESTRING(0 0,1 1,2 2)') as json))
|
||
NULL
|
||
Warnings:
|
||
Warning 4036 Character disallowd in JSON in argument 1 to function 'json_type' at position 1
|
||
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));
|
||
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))
|
||
NULL
|
||
Warnings:
|
||
Warning 4036 Character disallowd in JSON in argument 1 to function 'json_type' at position 1
|
||
select json_type(cast(null as json));
|
||
json_type(cast(null as json))
|
||
NULL
|
||
select json_type(cast(null as json)) is null;
|
||
json_type(cast(null as json)) is null
|
||
1
|
||
select json_type(null) is null;
|
||
json_type(null) is null
|
||
1
|
||
select cast(cast('2014-11-25 18:00' as datetime) as json);
|
||
cast(cast('2014-11-25 18:00' as datetime) as json)
|
||
2014-11-25 18:00:00
|
||
select cast(cast('2014-11-25' as date) as json);
|
||
cast(cast('2014-11-25' as date) as json)
|
||
2014-11-25
|
||
select cast(cast('18:00:59' as time) as json);
|
||
cast(cast('18:00:59' as time) as json)
|
||
18:00:59
|
||
select cast(127 as json);
|
||
cast(127 as json)
|
||
127
|
||
select cast(255 as json);
|
||
cast(255 as json)
|
||
255
|
||
select cast(32767 as json);
|
||
cast(32767 as json)
|
||
32767
|
||
select cast(65535 as json);
|
||
cast(65535 as json)
|
||
65535
|
||
select cast(8388607 as json);
|
||
cast(8388607 as json)
|
||
8388607
|
||
select cast(16777215 as json);
|
||
cast(16777215 as json)
|
||
16777215
|
||
select cast(2147483647 as json);
|
||
cast(2147483647 as json)
|
||
2147483647
|
||
select cast(4294967295 as json);
|
||
cast(4294967295 as json)
|
||
4294967295
|
||
select cast(9223372036854775807 as json);
|
||
cast(9223372036854775807 as json)
|
||
9223372036854775807
|
||
select cast(18446744073709551615 as json);
|
||
cast(18446744073709551615 as json)
|
||
18446744073709551615
|
||
select cast(true as json);
|
||
cast(true as json)
|
||
1
|
||
select cast(b'10101' as json);
|
||
cast(b'10101' as json)
|
||
|
||
select cast(cast(3.14 as decimal(5,2)) as json);
|
||
cast(cast(3.14 as decimal(5,2)) as json)
|
||
3.14
|
||
select cast(3.14 as json);
|
||
cast(3.14 as json)
|
||
3.14
|
||
select cast(3.14e0 as json);
|
||
cast(3.14e0 as json)
|
||
3.14
|
||
select cast(cast('10101abcde' as binary) as json);
|
||
cast(cast('10101abcde' as binary) as json)
|
||
10101abcde
|
||
select cast(ST_GeomFromText('POINT(1 1)') as json);
|
||
cast(ST_GeomFromText('POINT(1 1)') as json)
|
||
|