Details
-
Bug
-
Status: Confirmed (View Workflow)
-
Major
-
Resolution: Unresolved
-
10.11, 11.4, 11.8, 12.3, 13.1
Description
Hi,
I found that $[last] might generate an incorrect index for JSON data. This is an example:
CREATE TABLE t( |
id INT PRIMARY KEY, |
j JSON
|
);
|
|
|
INSERT INTO t VALUES |
(1, '["x","target"]'), |
(2, '["x","y","target"]'); |
|
|
SELECT id, |
JSON_EXTRACT(j, '$[last]') AS extracted_last, |
JSON_SEARCH(j, 'one', 'target', NULL, '$[last]') AS searched_last |
FROM t |
ORDER BY id; |
-- 1 "target" "$[1]"
|
-- 2 "y" NULL |
For the first row, the $[last] index is correct, but for the second row, the $[last] index is 1, which is incorrect.