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

Behaviour of IF() with boolean JSON_EXTRACT as expression is wrong

    XMLWordPrintable

Details

    • Bug
    • Status: In Testing (View Workflow)
    • Major
    • Resolution: Unresolved
    • 11.8.5
    • 11.8
    • Data types, JSON
    • None

    Description

      When using the output of JSON_EXTRACT as an expression in IF(expr, ...), the result has changed between 11.4 and 11.8. I'm wondering if this is an undocumented change (I can update the upgrade guide) or a bug.

      SELECT
          VERSION() AS version,
          JSON_TYPE(JSON_EXTRACT(x.val, '$.booleanValue')) AS json_type,
          JSON_EXTRACT(x.val, '$.booleanValue') AS value,
          IF(JSON_EXTRACT(x.val, '$.booleanValue'), 1, 0) AS value_if,
          (JSON_EXTRACT(x.val, '$.booleanValue') = true) AS value_eq
      FROM (
           SELECT '{"booleanValue": true}' AS val
           UNION ALL
           SELECT '{"booleanValue": false}' AS val
       ) AS x;
      

      Results in these values on version 11.4 vs 11.8:

      Version type value if eq
      11.4.9-MariaDB-ubu2404 BOOLEAN true 1 1
      11.4.9-MariaDB-ubu2404 BOOLEAN false 0 0
      11.8.5-MariaDB-ubu2404 BOOLEAN true 0 1
      11.8.5-MariaDB-ubu2404 BOOLEAN false 0 0

      NB: The query can be changed to use

      JSON_EXTRACT() = true
      

      instead as noted in the reproduction.

      Attachments

        Activity

          People

            serg Sergei Golubchik
            PrinsFrank Frank Prins
            Votes:
            0 Vote for this issue
            Watchers:
            4 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.