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

json_extract returns null is any (even nested) data contains 0 written in scientific notation (0E-10)

Details

    • Bug
    • Status: Confirmed (View Workflow)
    • Major
    • Resolution: Unresolved
    • 10.3.11, 10.2(EOL), 10.3(EOL)
    • 10.4(EOL)
    • JSON
    • None

    Description

      Hi, the scientific notation handling was partially fixed in MDEV-15561

      But this still fails

      MariaDB [(none)]> select json_extract('{"test":0e-10}','$.test') from dual;
      +-----------------------------------------+
      | json_extract('{"test":0e-10}','$.test') |
      +-----------------------------------------+
      | NULL                                    |
      +-----------------------------------------+
      1 row in set, 1 warning (0.000 sec)
       
      MariaDB [(none)]> select json_extract('{"test":0E-10}','$.test') from dual;
      +-----------------------------------------+
      | json_extract('{"test":0E-10}','$.test') |
      +-----------------------------------------+
      | NULL                                    |
      +-----------------------------------------+
      1 row in set, 1 warning (0.000 sec)
       
      MariaDB [(none)]> show warnings;
      +---------+------+-----------------------------------------------------------------------------------+
      | Level   | Code | Message                                                                           |
      +---------+------+-----------------------------------------------------------------------------------+
      | Warning | 4038 | Syntax error in JSON text in argument 1 to function 'json_extract' at position 10 |
      +---------+------+-----------------------------------------------------------------------------------+
      1 row in set (0.000 sec)
      

      although this works

       
      MariaDB [(none)]> select json_extract('{"test":1E-10}','$.test') from dual;
      +-----------------------------------------+
      | json_extract('{"test":1E-10}','$.test') |
      +-----------------------------------------+
      | 1E-10                                   |
      +-----------------------------------------+
      1 row in set (0.000 sec)
      

      Attachments

        Activity

          tlamr Tomas Lamr added a comment -

          I know that the zero encoded in scientific notation seems to be strange, but it is just how one of the most used json library works by default.
          When you use https://github.com/FasterXML/jackson and serialize java's BigDecimal that have set scale but it's value will be 0, it will by default serialize it this way.

          This is what Oracle 18c returns

          Oracle Database 18c Enterprise Edition Release 18.0.0.0.0 - Production
          Version 18.3.0.0.0
           
          SQL> select json_value('{"test":0E-10}','$.test') from dual;
           
          JSON_VALUE('{"TEST":0E-10}','$.TEST')
          --------------------------------------------------------------------------------
          0
          

          tlamr Tomas Lamr added a comment - I know that the zero encoded in scientific notation seems to be strange, but it is just how one of the most used json library works by default. When you use https://github.com/FasterXML/jackson and serialize java's BigDecimal that have set scale but it's value will be 0, it will by default serialize it this way. This is what Oracle 18c returns Oracle Database 18c Enterprise Edition Release 18.0.0.0.0 - Production Version 18.3.0.0.0   SQL> select json_value('{"test":0E-10}','$.test') from dual;   JSON_VALUE('{"TEST":0E-10}','$.TEST') -------------------------------------------------------------------------------- 0
          tlamr Tomas Lamr added a comment -

          ah, it just seems to be json_extract specific, json_value work also on mariadb

          MariaDB [(none)]> select JSON_VALUE('{"TEST":0E-10}','$.TEST') from dual;
          +---------------------------------------+
          | JSON_VALUE('{"TEST":0E-10}','$.TEST') |
          +---------------------------------------+
          | 0                                     |
          +---------------------------------------+
          1 row in set (0.004 sec)
           
          MariaDB [(none)]> select JSON_EXTRACT('{"TEST":0E-10}','$.TEST') from dual;
          +-----------------------------------------+
          | JSON_EXTRACT('{"TEST":0E-10}','$.TEST') |
          +-----------------------------------------+
          | NULL                                    |
          +-----------------------------------------+
          1 row in set, 1 warning (0.000 sec)
          

          tlamr Tomas Lamr added a comment - ah, it just seems to be json_extract specific, json_value work also on mariadb MariaDB [(none)]> select JSON_VALUE('{"TEST":0E-10}','$.TEST') from dual; +---------------------------------------+ | JSON_VALUE('{"TEST":0E-10}','$.TEST') | +---------------------------------------+ | 0 | +---------------------------------------+ 1 row in set (0.004 sec)   MariaDB [(none)]> select JSON_EXTRACT('{"TEST":0E-10}','$.TEST') from dual; +-----------------------------------------+ | JSON_EXTRACT('{"TEST":0E-10}','$.TEST') | +-----------------------------------------+ | NULL | +-----------------------------------------+ 1 row in set, 1 warning (0.000 sec)
          alice Alice Sherepa added a comment -

          repeatable on 10.2,10.3

          MariaDB [test]> select json_value('{"test":0e-10}','$.test') from dual;
          +---------------------------------------+
          | json_value('{"test":0e-10}','$.test') |
          +---------------------------------------+
          | 0                                     |
          +---------------------------------------+
          1 row in set (0.000 sec)
           
          MariaDB [test]> select json_extract('{"test":0e-10}','$.test') from dual;
          +-----------------------------------------+
          | json_extract('{"test":0e-10}','$.test') |
          +-----------------------------------------+
          | NULL                                    |
          +-----------------------------------------+
          1 row in set, 1 warning (0.000 sec)
           
          Warning (Code 4038): Syntax error in JSON text in argument 1 to function 'json_extract' at position 10
          

          MySQL 8.0.12

          mysql> select json_extract('{"test":0e-10}','$.test') from dual;
          +-----------------------------------------+
          | json_extract('{"test":0e-10}','$.test') |
          +-----------------------------------------+
          | 0.0                                     |
          +-----------------------------------------+
          1 row in set (0.00 sec)
          

          alice Alice Sherepa added a comment - repeatable on 10.2,10.3 MariaDB [test]> select json_value('{"test":0e-10}','$.test') from dual; +---------------------------------------+ | json_value('{"test":0e-10}','$.test') | +---------------------------------------+ | 0 | +---------------------------------------+ 1 row in set (0.000 sec)   MariaDB [test]> select json_extract('{"test":0e-10}','$.test') from dual; +-----------------------------------------+ | json_extract('{"test":0e-10}','$.test') | +-----------------------------------------+ | NULL | +-----------------------------------------+ 1 row in set, 1 warning (0.000 sec)   Warning (Code 4038): Syntax error in JSON text in argument 1 to function 'json_extract' at position 10 MySQL 8.0.12 mysql> select json_extract('{"test":0e-10}','$.test') from dual; +-----------------------------------------+ | json_extract('{"test":0e-10}','$.test') | +-----------------------------------------+ | 0.0 | +-----------------------------------------+ 1 row in set (0.00 sec)
          tlamr Tomas Lamr added a comment -

          Thanks a lot for such quick feedback!

          tlamr Tomas Lamr added a comment - Thanks a lot for such quick feedback!

          People

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