mirror of
https://github.com/MariaDB/server.git
synced 2025-01-15 19:42:28 +01:00
MDEV-28072: JSON_EXTRACT has inconsistent behavior with '0' value in json
path (when range is used) Analysis: When 0 comes after space, then the json path parser changes the state to JE_SYN instead of PS_Z (meaning parse zero). Hence the warning. Fix: Make the state PS_Z instead of JE_SYN.
This commit is contained in:
parent
95a9078efc
commit
c69d72c2e4
3 changed files with 855 additions and 2 deletions
|
@ -1751,6 +1751,53 @@ JSON_OVERLAPS('true','tr')
|
|||
Warnings:
|
||||
Warning 4037 Unexpected end of JSON text in argument 2 to function 'json_overlaps'
|
||||
#
|
||||
<<<<<<< HEAD
|
||||
||||||| parent of 970dba92c3d... MDEV-28072: JSON_EXTRACT has inconsistent behavior with '0' value in json
|
||||
<<<<<<< HEAD
|
||||
<<<<<<< HEAD
|
||||
||||||| constructed merge base
|
||||
# End of 10.9 test
|
||||
#
|
||||
#
|
||||
||||||| constructed merge base
|
||||
# End of 10.9 test
|
||||
#
|
||||
#
|
||||
=======
|
||||
>>>>>>> MDEV-22224: Support JSON Path negative index
|
||||
# Beginning of 10.9 Test
|
||||
#
|
||||
=======
|
||||
# Beginning of 10.9 Test
|
||||
#
|
||||
>>>>>>> MDEV-28071: JSON_EXISTS returns always 1 if it is used range notation for
|
||||
=======
|
||||
<<<<<<< HEAD
|
||||
<<<<<<< HEAD
|
||||
<<<<<<< HEAD
|
||||
||||||| constructed merge base
|
||||
# End of 10.9 test
|
||||
#
|
||||
#
|
||||
||||||| constructed merge base
|
||||
# End of 10.9 test
|
||||
#
|
||||
#
|
||||
=======
|
||||
>>>>>>> MDEV-22224: Support JSON Path negative index
|
||||
||||||| constructed merge base
|
||||
=======
|
||||
# End of 10.9 test
|
||||
#
|
||||
#
|
||||
>>>>>>> MDEV-28072: JSON_EXTRACT has inconsistent behavior with '0' value in json
|
||||
# Beginning of 10.9 Test
|
||||
#
|
||||
=======
|
||||
# Beginning of 10.9 Test
|
||||
#
|
||||
>>>>>>> MDEV-28071: JSON_EXISTS returns always 1 if it is used range notation for
|
||||
>>>>>>> 970dba92c3d... MDEV-28072: JSON_EXTRACT has inconsistent behavior with '0' value in json
|
||||
# MDEV-22224: Support JSON Path negative index
|
||||
#
|
||||
SET @json='{
|
||||
|
@ -2024,6 +2071,7 @@ SELECT JSON_VALUE(@json,'$.x[0]');
|
|||
JSON_VALUE(@json,'$.x[0]')
|
||||
0
|
||||
#
|
||||
<<<<<<< HEAD
|
||||
# MDEV-27911: Implement range notation for json path
|
||||
#
|
||||
SET @json= '[
|
||||
|
@ -3014,7 +3062,21 @@ SELECT JSON_VALUE(@json, '$.A[last-1][last-1].key1');
|
|||
JSON_VALUE(@json, '$.A[last-1][last-1].key1')
|
||||
123
|
||||
#
|
||||
<<<<<<< HEAD
|
||||
# MDEV-28075: JSON_VALUE returns first value from array not from range
|
||||
||||||| parent of 970dba92c3d... MDEV-28072: JSON_EXTRACT has inconsistent behavior with '0' value in json
|
||||
# MDEV-22224: Support JSON Path negative index
|
||||
#
|
||||
# MDEV-27911: Implement range notation for json path
|
||||
=======
|
||||
# MDEV-22224: Support JSON Path negative index
|
||||
#
|
||||
# Beginning of 10.9 Test
|
||||
#
|
||||
# MDEV-22224: Support JSON Path negative index
|
||||
#
|
||||
# MDEV-27911: Implement range notation for json path
|
||||
>>>>>>> 970dba92c3d... MDEV-28072: JSON_EXTRACT has inconsistent behavior with '0' value in json
|
||||
#
|
||||
SET @json1= '[
|
||||
[{"key1": "value1"}, {"key2": "value2"}],
|
||||
|
@ -3038,9 +3100,32 @@ SELECT JSON_VALUE(@json, '$[2 to 3][0]');
|
|||
JSON_VALUE(@json, '$[2 to 3][0]')
|
||||
7
|
||||
#
|
||||
<<<<<<< HEAD
|
||||
# Beginning of 10.9 Test
|
||||
#
|
||||
# MDEV-22224: Support JSON Path negative index
|
||||
||||||| parent of 970dba92c3d... MDEV-28072: JSON_EXTRACT has inconsistent behavior with '0' value in json
|
||||
# MDEV-27911: Implement range notation for json path
|
||||
=======
|
||||
# MDEV-28072: JSON_EXTRACT has inconsistent behavior with '0' value in
|
||||
# json path (when range is used)
|
||||
#
|
||||
SET @json= '[ 11, 22 , 33]';
|
||||
SELECT JSON_EXTRACT(@json, '$[0 to 0]');
|
||||
JSON_EXTRACT(@json, '$[0 to 0]')
|
||||
[11]
|
||||
SELECT JSON_EXTRACT(@json, '$[0 to -0]');
|
||||
JSON_EXTRACT(@json, '$[0 to -0]')
|
||||
[11]
|
||||
SELECT JSON_EXTRACT(@json, '$[-0 to 0]');
|
||||
JSON_EXTRACT(@json, '$[-0 to 0]')
|
||||
[11]
|
||||
SELECT JSON_EXTRACT(@json, '$[-0 to -0]');
|
||||
JSON_EXTRACT(@json, '$[-0 to -0]')
|
||||
[11]
|
||||
#
|
||||
# MDEV-22224: Support JSON Path negative index
|
||||
>>>>>>> 970dba92c3d... MDEV-28072: JSON_EXTRACT has inconsistent behavior with '0' value in json
|
||||
#
|
||||
SET @json='{
|
||||
"A": [0,
|
||||
|
@ -3298,4 +3383,4 @@ JSON_VALUE(@json, '$.A[last-1][last-1].key1')
|
|||
123
|
||||
#
|
||||
# End of 10.9 Test
|
||||
#
|
||||
#
|
||||
|
|
|
@ -1949,5 +1949,773 @@ SELECT JSON_VALUE(@json, '$[*][0]');
|
|||
SELECT JSON_VALUE(@json, '$[2 to 3][0]');
|
||||
|
||||
--echo #
|
||||
<<<<<<< HEAD
|
||||
||||||| parent of 970dba92c3d... MDEV-28072: JSON_EXTRACT has inconsistent behavior with '0' value in json
|
||||
--echo # MDEV-27911: Implement range notation for json path
|
||||
--echo #
|
||||
|
||||
SET @json= '[
|
||||
[1, {"key1": "value1"}, 3],
|
||||
[false, 5, 6],
|
||||
[7, 8, [9, {"key2": 2}, 11]],
|
||||
[15, 1.34, [14], ["string1", [16, {"key1":[1,2,3,[4,5,6]]}, 18]]],
|
||||
[19, 20],
|
||||
21, 22
|
||||
]';
|
||||
SELECT JSON_EXISTS(@json, '$[3][3][-2 to last]');
|
||||
|
||||
SET @json= '[
|
||||
[1, {"key1": "value1"}, 3],
|
||||
[false, 5, 6],
|
||||
[7, 8, [9, {"key2": 2}, 11]],
|
||||
[15, 1.34, [14], ["string1", [16, {"key1":[1,2,3,[4,5,6]]}, 18]]],
|
||||
[19, 20],
|
||||
21, 22
|
||||
]';
|
||||
SELECT JSON_SEARCH(@json, 'one', '12', NULL, '$[3][0 to 3]');
|
||||
|
||||
SET @json= '[
|
||||
[1, {"key1": "value1"}, 3],
|
||||
[false, 5, 6],
|
||||
[7, 8, [9, {"key2": 2}, 11]],
|
||||
[12, 1.34, [14], ["string1", [16, {"key1":[1,2,3,[4,5,6]]}, 18]]],
|
||||
[19, 20]
|
||||
]';
|
||||
SELECT JSON_VALUE(@json, '$[0][1 to 2].key1');
|
||||
|
||||
SET @json='{
|
||||
"A": [0,
|
||||
[1, 2, 3],
|
||||
[4, 5, 6],
|
||||
"seven",
|
||||
0.8,
|
||||
true,
|
||||
false,
|
||||
"eleven",
|
||||
[12, [13, 14], {"key1":"value1"},[15]],
|
||||
true],
|
||||
"B": {"C": 1},
|
||||
"D": 2
|
||||
}';
|
||||
SELECT JSON_QUERY(@json, '$.A[-2][-3 to -1]');
|
||||
|
||||
SET @json= '[
|
||||
[1, {"key1": "value1"}, 3],
|
||||
[false, 5, 6],
|
||||
[7, 8, [9, {"key2": 2}, 11]],
|
||||
[15, 1.34, [14], ["string1", [16, {"key1":[1,2,3,[4,5,6]]}, 18]]],
|
||||
[19, 20],
|
||||
21, 22
|
||||
]';
|
||||
SELECT JSON_EXTRACT(@json, '$[0 to 3][2]');
|
||||
SELECT JSON_EXTRACT(@json, '$[3][3][last-1 to last]');
|
||||
SELECT JSON_EXTRACT(@json, '$[3][3][-2 to -1]');
|
||||
|
||||
--echo # Checking errors
|
||||
|
||||
SET @json= '[
|
||||
[1, {"key1": "value1"}, 3],
|
||||
[false, 5, 6],
|
||||
[7, 8, [9, {"key2": 2}, 11]],
|
||||
[15, 1.34, [14], ["string1", [16, {"key1":[1,2,3,[4,5,6]]}, 18]]],
|
||||
[19, 20],
|
||||
21, 22
|
||||
]';
|
||||
SELECT JSON_CONTAINS_PATH(@json,'one', '$[3][0 to 3]');
|
||||
|
||||
SET @json= '[
|
||||
[1, {"key1": "value1"}, 3],
|
||||
[false, 5, 6],
|
||||
[7, 8, [9, {"key2": 2}, 11]],
|
||||
[15, 1.34, [14], ["string1", [16, {"key1":[1,2,3,[4,5,6]]}, 18]]],
|
||||
[19, 20],
|
||||
21, 22
|
||||
]';
|
||||
SELECT JSON_CONTAINS(@json, '$[3][0 to 3]');
|
||||
|
||||
SET @json='{
|
||||
"A": [0,
|
||||
[1, 2, 3],
|
||||
[4, 5, 6],
|
||||
"seven",
|
||||
0.8,
|
||||
true,
|
||||
false,
|
||||
"eleven",
|
||||
[12, 13, {"key1":"value1"},[15]],
|
||||
true],
|
||||
"B": {"C": 1},
|
||||
"D": 2
|
||||
}';
|
||||
SELECT JSON_ARRAY_INSERT(@json, '$.A[0 to last-1]', 5);
|
||||
|
||||
SET @json='{
|
||||
"A": [0,
|
||||
[1, 2, 3],
|
||||
[4, 5, 6],
|
||||
"seven",
|
||||
0.8,
|
||||
true,
|
||||
false,
|
||||
"eleven",
|
||||
[12, 13, {"key1":"value1"},[15]],
|
||||
true],
|
||||
"B": {"C": 1},
|
||||
"D": 2
|
||||
}';
|
||||
SELECT JSON_ARRAY_APPEND(@json, '$.A[*]', 7);
|
||||
|
||||
SET @json= '[
|
||||
[1, {"key1": "value1"}, 3],
|
||||
[false, 5, 6],
|
||||
[7, 8, [9, {"key2": 2}, 11]],
|
||||
[12, 1.34, [14], ["string1", [16, {"key1":[1,2,3,[4,5,6]]}, 18]]],
|
||||
[19, 20]
|
||||
]';
|
||||
SELECT JSON_SET(@json, '$[0][1 to 2].key1', 1);
|
||||
|
||||
SET @json= '[
|
||||
[1, {"key1": "value1"}, 3],
|
||||
[false, 5, 6],
|
||||
[7, 8, [9, {"key2": 2}, 11]],
|
||||
[15, 1.34, [14], ["string1", [16, {"key1":[1,2,3,[4,5,6]]}, 18]]],
|
||||
[19, 20],
|
||||
21, 22
|
||||
]';
|
||||
SELECT JSON_REPLACE(@json, '$[1][last-2 to last]', 4);
|
||||
|
||||
SET @json= '[
|
||||
[1, {"key1": "value1"}, 3],
|
||||
[false, 5, 6],
|
||||
[7, 8, [9, {"key2": 2}, 11]],
|
||||
[15, 1.34, [14], ["string1", [16, {"key1":[1,2,3,[4,5,6]]}, 18]]],
|
||||
[19, 20],
|
||||
21, 22
|
||||
]';
|
||||
SELECT JSON_REMOVE(@json, '$[1][-6 to last-2]');
|
||||
|
||||
SET @json='{
|
||||
"A": [0,
|
||||
[1, 2, 3],
|
||||
[4, 5, 6],
|
||||
"seven",
|
||||
0.8,
|
||||
true,
|
||||
false,
|
||||
"eleven",
|
||||
[12, [13, 14], {"key1":"value1"},[15]],
|
||||
true],
|
||||
"B": {"C": 1},
|
||||
"D": 2
|
||||
}';
|
||||
SELECT JSON_KEYS(@json, '$.A[8][1 to 3]');
|
||||
|
||||
--echo #
|
||||
--echo # MDEV-22224: Support JSON Path negative index
|
||||
--echo #
|
||||
|
||||
SET @json='{
|
||||
"A": [0,
|
||||
[1, 2, 3],
|
||||
[4, 5, 6],
|
||||
"seven",
|
||||
0.8,
|
||||
true,
|
||||
false,
|
||||
"eleven",
|
||||
[12, 13, {"key1":"value1"},[15]],
|
||||
true],
|
||||
"B": {"C": 1},
|
||||
"D": 2
|
||||
}';
|
||||
SELECT JSON_ARRAY_APPEND(@json, '$.A[-2][-1]', 5);
|
||||
SELECT JSON_ARRAY_APPEND(@json, '$.A[last-1][last]', 5);
|
||||
|
||||
SET @json='{
|
||||
"A": [0,
|
||||
[1, 2, 3],
|
||||
[4, 5, 6],
|
||||
"seven",
|
||||
0.8,
|
||||
true,
|
||||
false,
|
||||
"eleven",
|
||||
[12, 13, {"key1":"value1"},[15]],
|
||||
true],
|
||||
"B": {"C": 1},
|
||||
"D": 2
|
||||
}';
|
||||
SELECT JSON_ARRAY_INSERT(@json, '$.A[-2][-2]', 5);
|
||||
SELECT JSON_ARRAY_INSERT(@json, '$.A[last-1][last-1]', 5);
|
||||
|
||||
SET @json='{
|
||||
"A": [0,
|
||||
[1, 2, 3],
|
||||
[4, 5, 6],
|
||||
"seven",
|
||||
0.8,
|
||||
true,
|
||||
false,
|
||||
"eleven",
|
||||
[12, 13, {"key1":"value1"},[15]],
|
||||
true],
|
||||
"B": {"C": 1},
|
||||
"D": 2
|
||||
}';
|
||||
SELECT JSON_CONTAINS(@json, '15', '$.A[-2][-1]');
|
||||
SELECT JSON_CONTAINS(@json, '15', '$.A[last-1][last]');
|
||||
|
||||
SET @json='{
|
||||
"A": [0,
|
||||
[1, 2, 3],
|
||||
[4, 5, 6],
|
||||
"seven",
|
||||
0.8,
|
||||
true,
|
||||
false,
|
||||
"eleven",
|
||||
[12, 13, {"key1":"value1"},[15]],
|
||||
true],
|
||||
"B": {"C": 1},
|
||||
"D": 2
|
||||
}';
|
||||
SELECT JSON_CONTAINS_PATH(@json, 'one', '$.A[-2]');
|
||||
SELECT JSON_CONTAINS_PATH(@json, 'one', '$.A[last-1]');
|
||||
|
||||
SET @json='{
|
||||
"A": [0,
|
||||
[1, 2, 3],
|
||||
[4, 5, 6],
|
||||
"seven",
|
||||
0.8,
|
||||
true,
|
||||
false,
|
||||
"eleven",
|
||||
[12, 13, {"key1":"value1"},[15]],
|
||||
true],
|
||||
"B": {"C": 1},
|
||||
"D": 2
|
||||
}';
|
||||
SELECT JSON_EXISTS(@json, '$.A[-2][-1]');
|
||||
SELECT JSON_EXISTS(@json, '$.A[last-1][last]');
|
||||
|
||||
SET @json='{
|
||||
"A": [0,
|
||||
[1, 2, 3],
|
||||
[4, 5, 6],
|
||||
"seven",
|
||||
0.8,
|
||||
true,
|
||||
false,
|
||||
"eleven",
|
||||
[12, [13, 14], {"key1":"value1"},[15]],
|
||||
true],
|
||||
"B": {"C": 1},
|
||||
"D": 2
|
||||
}';
|
||||
SELECT JSON_EXTRACT(@json, '$.A[-8][1]');
|
||||
SELECT JSON_EXTRACT(@json, '$.A[last-7][1]');
|
||||
|
||||
SET @json= '[{"A": 1, "B": 2, "C": {"D": 3}},{"A": 1, "B": 2, "C": {"D": 3}}]';
|
||||
SELECT JSON_KEYS(@json, '$[-1].C');
|
||||
SELECT JSON_KEYS(@json, '$[last].C');
|
||||
|
||||
SET @json='{
|
||||
"A": [0,
|
||||
[1, 2, 3],
|
||||
[4, 5, 6],
|
||||
"seven",
|
||||
0.8,
|
||||
true,
|
||||
false,
|
||||
"eleven",
|
||||
[12, [13, 14], {"key1":"value1"},[15]],
|
||||
true],
|
||||
"B": {"C": 1},
|
||||
"D": 2
|
||||
}';
|
||||
SELECT JSON_LENGTH(@json, '$.A[-2][-3]');
|
||||
SELECT JSON_LENGTH(@json, '$.A[last-1][last-2]');
|
||||
|
||||
SET @json='{
|
||||
"A": [0,
|
||||
[1, 2, 3],
|
||||
[4, 5, 6],
|
||||
"seven",
|
||||
0.8,
|
||||
true,
|
||||
false,
|
||||
"eleven",
|
||||
[12, [13, 14], {"key1":"value1"},[15]],
|
||||
true],
|
||||
"B": {"C": 1},
|
||||
"D": 2
|
||||
}';
|
||||
SELECT JSON_QUERY(@json, '$.A[-8]');
|
||||
SELECT JSON_QUERY(@json, '$.A[last-7]');
|
||||
|
||||
SET @json='{
|
||||
"A": [0,
|
||||
[1, 2, 3],
|
||||
[4, 5, 6],
|
||||
"seven",
|
||||
0.8,
|
||||
true,
|
||||
false,
|
||||
"eleven",
|
||||
[12, [13, 14], {"key1":"value1"},[15]],
|
||||
true],
|
||||
"B": {"C": 1},
|
||||
"D": 2
|
||||
}';
|
||||
SELECT JSON_REMOVE(@json, '$.A[-10]');
|
||||
SELECT JSON_REMOVE(@json, '$.A[last-9]');
|
||||
|
||||
SET @json='{
|
||||
"A": [0,
|
||||
[1, 2, 3],
|
||||
[4, 5, 6],
|
||||
"seven",
|
||||
0.8,
|
||||
true,
|
||||
false,
|
||||
"eleven",
|
||||
[12, [13, 14], {"key1":"value1"},[15]],
|
||||
true],
|
||||
"B": {"C": 1},
|
||||
"D": 2
|
||||
}';
|
||||
SELECT JSON_REPLACE(@json, '$.A[-1]', 4);
|
||||
SELECT JSON_REPLACE(@json, '$.A[last]', 4);
|
||||
|
||||
SET @json = '["abc", [{"k": "10"}, "def"], {"x":"abc"}, {"y":"bcd"}]';
|
||||
SELECT JSON_SEARCH(@json, 'all', 'abc', NULL, '$[-2]');
|
||||
SELECT JSON_SEARCH(@json, 'all', 'abc', NULL, '$[last-1]');
|
||||
|
||||
SET @json='{
|
||||
"A": [0,
|
||||
[1, 2, 3],
|
||||
[4, 5, 6],
|
||||
"seven",
|
||||
0.8,
|
||||
true,
|
||||
false,
|
||||
"eleven",
|
||||
[12, [13, 14], {"key1":"value1"},[15]],
|
||||
true],
|
||||
"B": {"C": 1},
|
||||
"D": 2
|
||||
}';
|
||||
SELECT JSON_SET(@json, '$.A[-4]', 100);
|
||||
SELECT JSON_SET(@json, '$.A[last-3]', 100);
|
||||
|
||||
SET @json='{
|
||||
"A": [0,
|
||||
[1, 2, 3],
|
||||
[4, 5, 6],
|
||||
"seven",
|
||||
0.8,
|
||||
true,
|
||||
false,
|
||||
"eleven",
|
||||
[12, [13, 14], {"key1":123},[15]],
|
||||
true],
|
||||
"B": {"C": 1},
|
||||
"D": 2
|
||||
}';
|
||||
SELECT JSON_VALUE(@json, '$.A[-2][-2].key1');
|
||||
SELECT JSON_VALUE(@json, '$.A[last-1][last-1].key1');
|
||||
|
||||
--echo #
|
||||
=======
|
||||
--echo # MDEV-27911: Implement range notation for json path
|
||||
--echo #
|
||||
|
||||
SET @json= '[
|
||||
[1, {"key1": "value1"}, 3],
|
||||
[false, 5, 6],
|
||||
[7, 8, [9, {"key2": 2}, 11]],
|
||||
[15, 1.34, [14], ["string1", [16, {"key1":[1,2,3,[4,5,6]]}, 18]]],
|
||||
[19, 20],
|
||||
21, 22
|
||||
]';
|
||||
SELECT JSON_EXISTS(@json, '$[3][3][-2 to last]');
|
||||
|
||||
SET @json= '[
|
||||
[1, {"key1": "value1"}, 3],
|
||||
[false, 5, 6],
|
||||
[7, 8, [9, {"key2": 2}, 11]],
|
||||
[15, 1.34, [14], ["string1", [16, {"key1":[1,2,3,[4,5,6]]}, 18]]],
|
||||
[19, 20],
|
||||
21, 22
|
||||
]';
|
||||
SELECT JSON_SEARCH(@json, 'one', '12', NULL, '$[3][0 to 3]');
|
||||
|
||||
SET @json= '[
|
||||
[1, {"key1": "value1"}, 3],
|
||||
[false, 5, 6],
|
||||
[7, 8, [9, {"key2": 2}, 11]],
|
||||
[12, 1.34, [14], ["string1", [16, {"key1":[1,2,3,[4,5,6]]}, 18]]],
|
||||
[19, 20]
|
||||
]';
|
||||
SELECT JSON_VALUE(@json, '$[0][1 to 2].key1');
|
||||
|
||||
SET @json='{
|
||||
"A": [0,
|
||||
[1, 2, 3],
|
||||
[4, 5, 6],
|
||||
"seven",
|
||||
0.8,
|
||||
true,
|
||||
false,
|
||||
"eleven",
|
||||
[12, [13, 14], {"key1":"value1"},[15]],
|
||||
true],
|
||||
"B": {"C": 1},
|
||||
"D": 2
|
||||
}';
|
||||
SELECT JSON_QUERY(@json, '$.A[-2][-3 to -1]');
|
||||
|
||||
SET @json= '[
|
||||
[1, {"key1": "value1"}, 3],
|
||||
[false, 5, 6],
|
||||
[7, 8, [9, {"key2": 2}, 11]],
|
||||
[15, 1.34, [14], ["string1", [16, {"key1":[1,2,3,[4,5,6]]}, 18]]],
|
||||
[19, 20],
|
||||
21, 22
|
||||
]';
|
||||
SELECT JSON_EXTRACT(@json, '$[0 to 3][2]');
|
||||
SELECT JSON_EXTRACT(@json, '$[3][3][last-1 to last]');
|
||||
SELECT JSON_EXTRACT(@json, '$[3][3][-2 to -1]');
|
||||
|
||||
--echo # Checking errors
|
||||
|
||||
SET @json= '[
|
||||
[1, {"key1": "value1"}, 3],
|
||||
[false, 5, 6],
|
||||
[7, 8, [9, {"key2": 2}, 11]],
|
||||
[15, 1.34, [14], ["string1", [16, {"key1":[1,2,3,[4,5,6]]}, 18]]],
|
||||
[19, 20],
|
||||
21, 22
|
||||
]';
|
||||
SELECT JSON_CONTAINS_PATH(@json,'one', '$[3][0 to 3]');
|
||||
|
||||
SET @json= '[
|
||||
[1, {"key1": "value1"}, 3],
|
||||
[false, 5, 6],
|
||||
[7, 8, [9, {"key2": 2}, 11]],
|
||||
[15, 1.34, [14], ["string1", [16, {"key1":[1,2,3,[4,5,6]]}, 18]]],
|
||||
[19, 20],
|
||||
21, 22
|
||||
]';
|
||||
SELECT JSON_CONTAINS(@json, '$[3][0 to 3]');
|
||||
|
||||
SET @json='{
|
||||
"A": [0,
|
||||
[1, 2, 3],
|
||||
[4, 5, 6],
|
||||
"seven",
|
||||
0.8,
|
||||
true,
|
||||
false,
|
||||
"eleven",
|
||||
[12, 13, {"key1":"value1"},[15]],
|
||||
true],
|
||||
"B": {"C": 1},
|
||||
"D": 2
|
||||
}';
|
||||
SELECT JSON_ARRAY_INSERT(@json, '$.A[0 to last-1]', 5);
|
||||
|
||||
SET @json='{
|
||||
"A": [0,
|
||||
[1, 2, 3],
|
||||
[4, 5, 6],
|
||||
"seven",
|
||||
0.8,
|
||||
true,
|
||||
false,
|
||||
"eleven",
|
||||
[12, 13, {"key1":"value1"},[15]],
|
||||
true],
|
||||
"B": {"C": 1},
|
||||
"D": 2
|
||||
}';
|
||||
SELECT JSON_ARRAY_APPEND(@json, '$.A[*]', 7);
|
||||
|
||||
SET @json= '[
|
||||
[1, {"key1": "value1"}, 3],
|
||||
[false, 5, 6],
|
||||
[7, 8, [9, {"key2": 2}, 11]],
|
||||
[12, 1.34, [14], ["string1", [16, {"key1":[1,2,3,[4,5,6]]}, 18]]],
|
||||
[19, 20]
|
||||
]';
|
||||
SELECT JSON_SET(@json, '$[0][1 to 2].key1', 1);
|
||||
|
||||
SET @json= '[
|
||||
[1, {"key1": "value1"}, 3],
|
||||
[false, 5, 6],
|
||||
[7, 8, [9, {"key2": 2}, 11]],
|
||||
[15, 1.34, [14], ["string1", [16, {"key1":[1,2,3,[4,5,6]]}, 18]]],
|
||||
[19, 20],
|
||||
21, 22
|
||||
]';
|
||||
SELECT JSON_REPLACE(@json, '$[1][last-2 to last]', 4);
|
||||
|
||||
SET @json= '[
|
||||
[1, {"key1": "value1"}, 3],
|
||||
[false, 5, 6],
|
||||
[7, 8, [9, {"key2": 2}, 11]],
|
||||
[15, 1.34, [14], ["string1", [16, {"key1":[1,2,3,[4,5,6]]}, 18]]],
|
||||
[19, 20],
|
||||
21, 22
|
||||
]';
|
||||
SELECT JSON_REMOVE(@json, '$[1][-6 to last-2]');
|
||||
|
||||
SET @json='{
|
||||
"A": [0,
|
||||
[1, 2, 3],
|
||||
[4, 5, 6],
|
||||
"seven",
|
||||
0.8,
|
||||
true,
|
||||
false,
|
||||
"eleven",
|
||||
[12, [13, 14], {"key1":"value1"},[15]],
|
||||
true],
|
||||
"B": {"C": 1},
|
||||
"D": 2
|
||||
}';
|
||||
SELECT JSON_KEYS(@json, '$.A[8][1 to 3]');
|
||||
|
||||
|
||||
--echo #
|
||||
--echo # MDEV-28072: JSON_EXTRACT has inconsistent behavior with '0' value in
|
||||
--echo # json path (when range is used)
|
||||
--echo #
|
||||
|
||||
SET @json= '[ 11, 22 , 33]';
|
||||
SELECT JSON_EXTRACT(@json, '$[0 to 0]');
|
||||
SELECT JSON_EXTRACT(@json, '$[0 to -0]');
|
||||
SELECT JSON_EXTRACT(@json, '$[-0 to 0]');
|
||||
SELECT JSON_EXTRACT(@json, '$[-0 to -0]');
|
||||
|
||||
--echo #
|
||||
--echo # MDEV-22224: Support JSON Path negative index
|
||||
--echo #
|
||||
|
||||
SET @json='{
|
||||
"A": [0,
|
||||
[1, 2, 3],
|
||||
[4, 5, 6],
|
||||
"seven",
|
||||
0.8,
|
||||
true,
|
||||
false,
|
||||
"eleven",
|
||||
[12, 13, {"key1":"value1"},[15]],
|
||||
true],
|
||||
"B": {"C": 1},
|
||||
"D": 2
|
||||
}';
|
||||
SELECT JSON_ARRAY_APPEND(@json, '$.A[-2][-1]', 5);
|
||||
SELECT JSON_ARRAY_APPEND(@json, '$.A[last-1][last]', 5);
|
||||
|
||||
SET @json='{
|
||||
"A": [0,
|
||||
[1, 2, 3],
|
||||
[4, 5, 6],
|
||||
"seven",
|
||||
0.8,
|
||||
true,
|
||||
false,
|
||||
"eleven",
|
||||
[12, 13, {"key1":"value1"},[15]],
|
||||
true],
|
||||
"B": {"C": 1},
|
||||
"D": 2
|
||||
}';
|
||||
SELECT JSON_ARRAY_INSERT(@json, '$.A[-2][-2]', 5);
|
||||
SELECT JSON_ARRAY_INSERT(@json, '$.A[last-1][last-1]', 5);
|
||||
|
||||
SET @json='{
|
||||
"A": [0,
|
||||
[1, 2, 3],
|
||||
[4, 5, 6],
|
||||
"seven",
|
||||
0.8,
|
||||
true,
|
||||
false,
|
||||
"eleven",
|
||||
[12, 13, {"key1":"value1"},[15]],
|
||||
true],
|
||||
"B": {"C": 1},
|
||||
"D": 2
|
||||
}';
|
||||
SELECT JSON_CONTAINS(@json, '15', '$.A[-2][-1]');
|
||||
SELECT JSON_CONTAINS(@json, '15', '$.A[last-1][last]');
|
||||
|
||||
SET @json='{
|
||||
"A": [0,
|
||||
[1, 2, 3],
|
||||
[4, 5, 6],
|
||||
"seven",
|
||||
0.8,
|
||||
true,
|
||||
false,
|
||||
"eleven",
|
||||
[12, 13, {"key1":"value1"},[15]],
|
||||
true],
|
||||
"B": {"C": 1},
|
||||
"D": 2
|
||||
}';
|
||||
SELECT JSON_CONTAINS_PATH(@json, 'one', '$.A[-2]');
|
||||
SELECT JSON_CONTAINS_PATH(@json, 'one', '$.A[last-1]');
|
||||
|
||||
SET @json='{
|
||||
"A": [0,
|
||||
[1, 2, 3],
|
||||
[4, 5, 6],
|
||||
"seven",
|
||||
0.8,
|
||||
true,
|
||||
false,
|
||||
"eleven",
|
||||
[12, 13, {"key1":"value1"},[15]],
|
||||
true],
|
||||
"B": {"C": 1},
|
||||
"D": 2
|
||||
}';
|
||||
SELECT JSON_EXISTS(@json, '$.A[-2][-1]');
|
||||
SELECT JSON_EXISTS(@json, '$.A[last-1][last]');
|
||||
|
||||
SET @json='{
|
||||
"A": [0,
|
||||
[1, 2, 3],
|
||||
[4, 5, 6],
|
||||
"seven",
|
||||
0.8,
|
||||
true,
|
||||
false,
|
||||
"eleven",
|
||||
[12, [13, 14], {"key1":"value1"},[15]],
|
||||
true],
|
||||
"B": {"C": 1},
|
||||
"D": 2
|
||||
}';
|
||||
SELECT JSON_EXTRACT(@json, '$.A[-8][1]');
|
||||
SELECT JSON_EXTRACT(@json, '$.A[last-7][1]');
|
||||
|
||||
SET @json= '[{"A": 1, "B": 2, "C": {"D": 3}},{"A": 1, "B": 2, "C": {"D": 3}}]';
|
||||
SELECT JSON_KEYS(@json, '$[-1].C');
|
||||
SELECT JSON_KEYS(@json, '$[last].C');
|
||||
|
||||
SET @json='{
|
||||
"A": [0,
|
||||
[1, 2, 3],
|
||||
[4, 5, 6],
|
||||
"seven",
|
||||
0.8,
|
||||
true,
|
||||
false,
|
||||
"eleven",
|
||||
[12, [13, 14], {"key1":"value1"},[15]],
|
||||
true],
|
||||
"B": {"C": 1},
|
||||
"D": 2
|
||||
}';
|
||||
SELECT JSON_LENGTH(@json, '$.A[-2][-3]');
|
||||
SELECT JSON_LENGTH(@json, '$.A[last-1][last-2]');
|
||||
|
||||
SET @json='{
|
||||
"A": [0,
|
||||
[1, 2, 3],
|
||||
[4, 5, 6],
|
||||
"seven",
|
||||
0.8,
|
||||
true,
|
||||
false,
|
||||
"eleven",
|
||||
[12, [13, 14], {"key1":"value1"},[15]],
|
||||
true],
|
||||
"B": {"C": 1},
|
||||
"D": 2
|
||||
}';
|
||||
SELECT JSON_QUERY(@json, '$.A[-8]');
|
||||
SELECT JSON_QUERY(@json, '$.A[last-7]');
|
||||
|
||||
SET @json='{
|
||||
"A": [0,
|
||||
[1, 2, 3],
|
||||
[4, 5, 6],
|
||||
"seven",
|
||||
0.8,
|
||||
true,
|
||||
false,
|
||||
"eleven",
|
||||
[12, [13, 14], {"key1":"value1"},[15]],
|
||||
true],
|
||||
"B": {"C": 1},
|
||||
"D": 2
|
||||
}';
|
||||
SELECT JSON_REMOVE(@json, '$.A[-10]');
|
||||
SELECT JSON_REMOVE(@json, '$.A[last-9]');
|
||||
|
||||
SET @json='{
|
||||
"A": [0,
|
||||
[1, 2, 3],
|
||||
[4, 5, 6],
|
||||
"seven",
|
||||
0.8,
|
||||
true,
|
||||
false,
|
||||
"eleven",
|
||||
[12, [13, 14], {"key1":"value1"},[15]],
|
||||
true],
|
||||
"B": {"C": 1},
|
||||
"D": 2
|
||||
}';
|
||||
SELECT JSON_REPLACE(@json, '$.A[-1]', 4);
|
||||
SELECT JSON_REPLACE(@json, '$.A[last]', 4);
|
||||
|
||||
SET @json = '["abc", [{"k": "10"}, "def"], {"x":"abc"}, {"y":"bcd"}]';
|
||||
SELECT JSON_SEARCH(@json, 'all', 'abc', NULL, '$[-2]');
|
||||
SELECT JSON_SEARCH(@json, 'all', 'abc', NULL, '$[last-1]');
|
||||
|
||||
SET @json='{
|
||||
"A": [0,
|
||||
[1, 2, 3],
|
||||
[4, 5, 6],
|
||||
"seven",
|
||||
0.8,
|
||||
true,
|
||||
false,
|
||||
"eleven",
|
||||
[12, [13, 14], {"key1":"value1"},[15]],
|
||||
true],
|
||||
"B": {"C": 1},
|
||||
"D": 2
|
||||
}';
|
||||
SELECT JSON_SET(@json, '$.A[-4]', 100);
|
||||
SELECT JSON_SET(@json, '$.A[last-3]', 100);
|
||||
|
||||
SET @json='{
|
||||
"A": [0,
|
||||
[1, 2, 3],
|
||||
[4, 5, 6],
|
||||
"seven",
|
||||
0.8,
|
||||
true,
|
||||
false,
|
||||
"eleven",
|
||||
[12, [13, 14], {"key1":123},[15]],
|
||||
true],
|
||||
"B": {"C": 1},
|
||||
"D": 2
|
||||
}';
|
||||
SELECT JSON_VALUE(@json, '$.A[-2][-2].key1');
|
||||
SELECT JSON_VALUE(@json, '$.A[last-1][last-1].key1');
|
||||
|
||||
--echo #
|
||||
>>>>>>> 970dba92c3d... MDEV-28072: JSON_EXTRACT has inconsistent behavior with '0' value in json
|
||||
--echo # End of 10.9 Test
|
||||
--echo #
|
||||
|
|
|
@ -1091,7 +1091,7 @@ static int json_path_transitions[N_PATH_STATES][N_PATH_CLASSES]=
|
|||
PS_INT, PS_INT, JE_SYN, JE_SYN, PS_AS, JE_SYN, JE_SYN, JE_SYN,
|
||||
JE_NOT_JSON_CHR, JE_BAD_CHR},
|
||||
/* AS */ { JE_EOS, JE_SYN, JE_SYN, JE_SYN, PS_T, PS_PT, JE_SYN, PS_NEG,
|
||||
JE_SYN, PS_INT, PS_LAST, PS_AS, JE_SYN, JE_SYN, JE_SYN,
|
||||
PS_Z, PS_INT, PS_LAST, PS_AS, JE_SYN, JE_SYN, JE_SYN,
|
||||
JE_NOT_JSON_CHR, JE_BAD_CHR},
|
||||
/* KEY */ { JE_EOS, PS_KNM, PS_KWD, JE_SYN, PS_KNM, PS_KNM, JE_SYN, JE_SYN,
|
||||
PS_KNM, PS_KNM, PS_KNM, PS_KNM, PS_KNM, JE_SYN, PS_KEYX, PS_KNM,
|
||||
|
|
Loading…
Reference in a new issue