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

            Patch modification was discussed on slack.

            holyfoot Alexey Botchkov added a comment - Patch modification was discussed on slack.

            ok to push

            holyfoot Alexey Botchkov added a comment - ok to push

            Testing done

            lstartseva Lena Startseva added a comment - Testing done
            CRC Steven Haigh added a comment - - edited

            I'm trying to track back a regression that MIGHT end up being related to this.

            Given the following query:

            SELECT JSON_EXTRACT('{ "temperatures": { "AO-therm": "value" } }', '$.temperatures.AO-therm');
            

            The results for different versions of MariaDB are as follows:

            • 10.11-rc --> null
            • 10.10.4 --> null
            • 10.9.4 --> null
            • 10.8.6 --> "value"

            As such, this seems like a regression in behaviours from 10.8.6 onwards.

            CRC Steven Haigh added a comment - - edited I'm trying to track back a regression that MIGHT end up being related to this. Given the following query: SELECT JSON_EXTRACT( '{ "temperatures": { "AO-therm": "value" } }' , '$.temperatures.AO-therm' ); The results for different versions of MariaDB are as follows: 10.11-rc --> null 10.10.4 --> null 10.9.4 --> null 10.8.6 --> "value" As such, this seems like a regression in behaviours from 10.8.6 onwards.

            Yes, it is. See "causes" links above.

            serg Sergei Golubchik added a comment - Yes, it is. See "causes" links above.

            People

              rucha174 Rucha Deodhar
              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.