Bug #99238 JSON Path implement negative offset
Submitted: 13 Apr 2020 10:04 Modified: 14 Apr 2020 12:26
Reporter: Federico Razzoli Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: JSON Severity:S4 (Feature request)
Version:8.0 OS:Any
Assigned to: CPU Architecture:Any

[13 Apr 2020 10:04] Federico Razzoli
Description:
JSON Path allows to extract the last element from an array by specifying a negative index:

$[-1]

It would be very handy to have this in MySQL.

How to repeat:
mysql> SELECT JSON_EXTRACT(JSON_ARRAY(1, 2, 3), '$[0]');
+-------------------------------------------+
| JSON_EXTRACT(JSON_ARRAY(1, 2, 3), '$[0]') |
+-------------------------------------------+
| 1                                         |
+-------------------------------------------+
1 row in set (0.00 sec)

mysql> SELECT JSON_EXTRACT(JSON_ARRAY(1, 2, 3), '$[-1]');
ERROR 3143 (42000): Invalid JSON path expression. The error is around character position 2.
[13 Apr 2020 10:05] Federico Razzoli
Setting to "feature request"
[14 Apr 2020 12:26] MySQL Verification Team
Hello Federico,

Thank you for the feature request!

regards,
Umesh