[MDEV-22224] Support JSON Path negative index Created: 2020-04-12 Updated: 2023-08-07 Resolved: 2022-04-13 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | JSON |
| Fix Version/s: | 10.9.1 |
| Type: | Task | Priority: | Critical |
| Reporter: | Federico Razzoli | Assignee: | Rucha Deodhar |
| Resolution: | Fixed | Votes: | 1 |
| Labels: | Preview_10.9, json_path | ||
| Issue Links: |
|
||||||||||||||||||||||||||||||||||||
| Description |
|
JSON Path allows to specify a negative array index, eg $[-1] returns the last element. This is not supported in MariaDB. Because of this, I believe there is no way to retrieve the last element without knowing the array length, nor to insert (JSON_ARRAY_INSERT()) an element at the end of the array. If I'm correct, this is a major missing feature for those who use JSON functions.
UPDATE: The task includes adding the negative index and the new keyword "last" |
| Comments |
| Comment by Rucha Deodhar [ 2021-12-04 ] | |
|
Patch: | |
| Comment by Alexey Botchkov [ 2022-01-27 ] | |
|
ok to push. | |
| Comment by Rucha Deodhar [ 2022-02-15 ] | |
|
Pushed to preview branch: https://github.com/MariaDB/server/tree/preview-10.9-MDEV-22224 | |
| Comment by Sergei Petrunia [ 2022-02-18 ] | |
|
MySQL also supports last as a way to indicate the last array element. See
AFAIU, [last] is also in the SQL standard (grep for <JSON last subscript> in the standard text. holyfoot, rucha174 - what do you think of implementing [last] ? It's probably out of scope of this MDEV, but it should be fairly easy to do now? | |
| Comment by Rucha Deodhar [ 2022-02-18 ] | |
|
psergei Yes, I agree. Implementing [last] should be fairly easy to do. Thanks for bringing it to notice. I'll assign the task to myself. | |
| Comment by Rucha Deodhar [ 2022-02-19 ] | |
|
holyfoot : Patch for implementing [last-n] : https://github.com/MariaDB/server/commit/97d3657710086ada1264fdf4d8cca58db6991be4 | |
| Comment by Alexey Botchkov [ 2022-02-28 ] | |
|
Patch modification was discussed on slack. | |
| Comment by Alexey Botchkov [ 2022-02-28 ] | |
|
ok to push | |
| Comment by Lena Startseva [ 2022-03-02 ] | |
|
Testing done | |
| Comment by Steven Haigh [ 2022-11-30 ] | |
|
I'm trying to track back a regression that MIGHT end up being related to this. Given the following query:
The results for different versions of MariaDB are as follows:
As such, this seems like a regression in behaviours from 10.8.6 onwards. | |
| Comment by Sergei Golubchik [ 2022-12-01 ] | |
|
Yes, it is. See "causes" links above. |