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

CAST('0e1111111111' AS DECIMAL(38,0)) returns a wrong result

Details

    Description

      This query returns a correct result:

      select cast('0e111111111' AS DECIMAL(38,0)) AS a;
      

      +---+
      | a |
      +---+
      | 0 |
      +---+
      1 row in set (0.000 sec)
      

      Let's add one more digits to the exponent:

      select cast('0e1111111111' AS DECIMAL(38,0)) AS a;
      

      +----------------------------------------+
      | a                                      |
      +----------------------------------------+
      | 99999999999999999999999999999999999999 |
      +----------------------------------------+
      1 row in set, 3 warnings (0.001 sec)
      

      Opps. Looks wrong. 0 multiplied to 10^1111111111 should still be 0.

      show warnings;
      

      +---------+------+-------------------------------------------------------------+
      | Level   | Code | Message                                                     |
      +---------+------+-------------------------------------------------------------+
      | Warning | 1916 | Got overflow when converting '' to DECIMAL. Value truncated |
      | Warning | 1292 | Truncated incorrect DECIMAL value: '0e1111111111'           |
      | Warning | 1264 | Out of range value for column 'a' at row 1                  |
      +---------+------+-------------------------------------------------------------+
      

      Attachments

        Issue Links

          Activity

            bar Alexander Barkov created issue -
            bar Alexander Barkov made changes -
            Field Original Value New Value
            Affects Version/s 10.5.8 [ 25023 ]
            Affects Version/s 5.5 [ 15800 ]
            Affects Version/s 10.3 [ 22126 ]
            Affects Version/s 10.4 [ 22408 ]
            Affects Version/s 10.0 [ 16000 ]
            bar Alexander Barkov added a comment - - edited

            A similar problem happens with a non-zero mantissa:

            select cast('.00000000000000000000000000000000000001e111111111111111111111' AS DECIMAL(38,0)) AS a;
            

            +---+
            | a |
            +---+
            | 0 |
            +---+
            1 row in set, 1 warning (0.000 sec)
            

            Looks wrong. The expected result is 99999999999999999999999999999999999999 - the maximum possible value for the target data type.

            bar Alexander Barkov added a comment - - edited A similar problem happens with a non-zero mantissa: select cast ( '.00000000000000000000000000000000000001e111111111111111111111' AS DECIMAL (38,0)) AS a; +---+ | a | +---+ | 0 | +---+ 1 row in set, 1 warning (0.000 sec) Looks wrong. The expected result is 99999999999999999999999999999999999999 - the maximum possible value for the target data type.

            Note, DOUBLE works fine for the same input:

            select cast('0e1111111111' AS DOUBLE) AS a;
            

            +------+
            | a    |
            +------+
            |    0 |
            +------+
            

            select cast('.00000000000000000000000000000000000001e111111111111111111111' AS DOUBLE) AS a;
            

            +------------------------+
            | a                      |
            +------------------------+
            | 1.7976931348623157e308 |
            +------------------------+
            

            Notice, it returns 0 and the maximum possible DOUBLE value. Looks correct.

            bar Alexander Barkov added a comment - Note, DOUBLE works fine for the same input: select cast ( '0e1111111111' AS DOUBLE ) AS a; +------+ | a | +------+ | 0 | +------+ select cast ( '.00000000000000000000000000000000000001e111111111111111111111' AS DOUBLE ) AS a; +------------------------+ | a | +------------------------+ | 1.7976931348623157e308 | +------------------------+ Notice, it returns 0 and the maximum possible DOUBLE value. Looks correct.
            sanja Oleksandr Byelkin made changes -
            Assignee Oleksandr Byelkin [ sanja ] Alexander Barkov [ bar ]

            OK to push in 10.2

            sanja Oleksandr Byelkin added a comment - OK to push in 10.2
            bar Alexander Barkov made changes -
            Fix Version/s 10.2.37 [ 25112 ]
            Fix Version/s 10.3.28 [ 25111 ]
            Fix Version/s 10.4.18 [ 25110 ]
            Fix Version/s 10.5.9 [ 25109 ]
            Fix Version/s 10.6.0 [ 24431 ]
            Fix Version/s 10.5 [ 23123 ]
            bar Alexander Barkov made changes -
            issue.field.resolutiondate 2021-02-09 08:01:26.0 2021-02-09 08:01:26.327
            bar Alexander Barkov made changes -
            Resolution Fixed [ 1 ]
            Status Open [ 1 ] Closed [ 6 ]
            bar Alexander Barkov made changes -
            dbart Daniel Bartholomew made changes -
            Fix Version/s 10.2.38 [ 25207 ]
            Fix Version/s 10.2.37 [ 25112 ]
            bar Alexander Barkov made changes -
            Fix Version/s 10.2.37 [ 25112 ]
            Fix Version/s 10.2.38 [ 25207 ]
            dbart Daniel Bartholomew made changes -
            Fix Version/s 10.5.10 [ 25204 ]
            Fix Version/s 10.4.19 [ 25205 ]
            Fix Version/s 10.3.29 [ 25206 ]
            Fix Version/s 10.2.38 [ 25207 ]
            Fix Version/s 10.5.9 [ 25109 ]
            Fix Version/s 10.4.18 [ 25110 ]
            Fix Version/s 10.3.28 [ 25111 ]
            Fix Version/s 10.2.37 [ 25112 ]
            serg Sergei Golubchik made changes -
            Workflow MariaDB v3 [ 118852 ] MariaDB v4 [ 158863 ]

            People

              bar Alexander Barkov
              bar Alexander Barkov
              Votes:
              0 Vote for this issue
              Watchers:
              2 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.