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

Field of type FLOAT does not cast well to integer

    XMLWordPrintable

Details

    • Bug
    • Status: Open (View Workflow)
    • Minor
    • Resolution: Unresolved
    • 5.3.12, 5.5.36, 10.0.9
    • 5.5
    • None
    • None

    Description

      This SQL script:

      DROP TABLE IF EXISTS t1;
      CREATE TABLE t1 (a DOUBLE, b FLOAT);
      INSERT INTO t1 VALUES (1.1e30,1.2e30);
      SELECT CAST(a AS SIGNED),CAST(b as SIGNED) FROM t1;
      SHOW WARNINGS;

      returns a wrong result for the FLOAT field:

      +---------------------+----------------------+
      | CAST(a AS SIGNED)   | CAST(b as SIGNED)    |
      +---------------------+----------------------+
      | 9223372036854775807 | -9223372036854775808 |
      +---------------------+----------------------+
      1 row in set, 1 warning (0.00 sec)

      The expected result should be 9223372036854775807,
      the same with the DOUBLE field.

      Also, a warning is not generated for the FLOAT field.
      It is generated for the DOUBLE field only:

      +---------+------+---------------------------------------------+
      | Level   | Code | Message                                     |
      +---------+------+---------------------------------------------+
      | Warning | 1292 | Truncated incorrect INTEGER value: '1.1e30' |
      +---------+------+---------------------------------------------+
      1 row in set (0.00 sec)

      FLOAT should be fixed to generate warnings, like DOUBLE does.

      Attachments

        Activity

          People

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