Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-22224

Support JSON Path negative index

    XMLWordPrintable

    Details

      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.

      MariaDB [test]> SELECT JSON_EXTRACT(JSON_ARRAY(1, 2, 3), '$[-1]');
      +--------------------------------------------+
      | JSON_EXTRACT(JSON_ARRAY(1, 2, 3), '$[-1]') |
      +--------------------------------------------+
      | NULL                                       |
      +--------------------------------------------+
      1 row in set, 1 warning (0.000 sec)
       
      Warning (Code 4042): Syntax error in JSON path in argument 2 to function 'json_extract' at position 3
      

      UPDATE: The task includes adding the negative index and the new keyword "last"

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              rucha174 Rucha Deodhar
              Reporter:
              f_razzoli Federico Razzoli
              Votes:
              1 Vote for this issue
              Watchers:
              11 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:

                  Git Integration

                  Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.