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

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

    XMLWordPrintable

    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

              People

              Assignee:
              bar Alexander Barkov
              Reporter:
              bar Alexander Barkov
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: