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

On a non-array document, '$[last]' makes JSON_EXTRACT return NULL but JSON_SET replace the whole document

    XMLWordPrintable

Details

    Description

      For a non-array document, the same server treats '$[0]' and '$[last]' inconsistently.

      Reproduced on 10.11.19 (debug build):

      -- '$[0]': the document is auto-wrapped, consistently
      SELECT JSON_EXISTS('{"a":1}', '$[0]'),       -- 1
             JSON_SET('{"a":1}', '$[0]', 9),       -- 9
             JSON_INSERT('{"a":1}', '$[0]', 9);    -- {"a": 1}  (path exists: no-op)
       
      -- '$[last]' on the same document
      SELECT JSON_EXISTS('{"a":1}', '$[last]'),       -- 0
             JSON_SET('{"a":1}', '$[last]', 9),       -- 9   (whole document replaced)
             JSON_INSERT('{"a":1}', '$[last]', 9),    -- [{"a": 1}, 9]
             JSON_REPLACE('{"a":1}', '$[last]', 9),   -- {"a": 1}
             JSON_EXTRACT('{"a":1}', '$[last]');      -- NULL ('$[0]' returns the document)

      JSON_EXISTS = 0 means the path does not exist, so by the documented relation between the edit functions JSON_SET should behave like JSON_INSERT ([

      {"a": 1}

      , 9]). Instead it silently replaces the whole document with the value — data loss. On the read side the two index spellings also disagree with each other.

      Attachments

        Issue Links

          Activity

            People

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