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

CAST(string_expr AS SIGNED) does not understand scientific notation

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open (View Workflow)
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: 10.0, 10.1, 10.2
    • Fix Version/s: 10.2
    • Component/s: OTHER
    • Labels:
      None

      Description

      Explicit cast from string to DOUBLE and DECIMAL understands scientific number notation.
      Explicit cast from string to SIGNED and UNSIGNED does not understand.

      SELECT CAST('1.9e19' AS DOUBLE) AS c1,
             CAST('1.9e19' AS DECIMAL(30,1)) AS c2,
             CAST('1.9e19' AS SIGNED) AS c3,
             CAST('1.9e19' AS UNSIGNED) AS c4;
      

      +--------+------------------------+----+----+
      | c1     | c2                     | c3 | c4 |
      +--------+------------------------+----+----+
      | 1.9e19 | 19000000000000000000.0 |  1 |  1 |
      +--------+------------------------+----+----+
      

      SELECT COLUMN_GET(COLUMN_CREATE(0, '1.9e19'), 0 AS DOUBLE) AS c1,
             COLUMN_GET(COLUMN_CREATE(0, '1.9e19'), 0 AS DECIMAL(30,1)) AS c2,
             COLUMN_GET(COLUMN_CREATE(0, '1.9e19'), 0 AS SIGNED) AS c3,
             COLUMN_GET(COLUMN_CREATE(0, '1.9e19'), 0 AS UNSIGNED) AS c4;
      

      +--------+------------------------+------+------+
      | c1     | c2                     | c3   | c4   |
      +--------+------------------------+------+------+
      | 1.9e19 | 19000000000000000000.0 |    1 |    1 |
      +--------+------------------------+------+------+
      

      Note, implicit cast in INSERT understands scientific notation:

      CREATE OR REPLACE TABLE t1 (a BIGINT);
      INSERT INTO t1 VALUES ('1.9e19');
      SELECT * FROM t1;
      

      +---------------------+
      | a                   |
      +---------------------+
      | 9223372036854775807 |
      +---------------------+
      

      Explicit CAST to SIGNED/UNSIGNED should be fixed to understand scientific notation.

        Attachments

          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:

                Git Integration