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

Incorrect result of $[last] of JSON

    XMLWordPrintable

Details

    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.

      Attachments

        Activity

          People

            rucha174 Rucha Deodhar
            ChiZhang Chi Zhang
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Git Integration

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