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

Truncation is not always reported when storing data into numeric fields

    XMLWordPrintable

Details

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

    Description

      This SQL script inserts two out-of-range numbers:

      DROP TABLE IF EXISTS t1;
      CREATE TABLE t1 (a TINYINT);
      INSERT INTO t1 VALUES (127.1),(128);
      SHOW WARNINGS;
      SELECT * FROM t1;

      However, only one warning is reported:

      +---------+------+--------------------------------------------+
      | Level   | Code | Message                                    |
      +---------+------+--------------------------------------------+
      | Warning | 1264 | Out of range value for column 'a' at row 2 |
      +---------+------+--------------------------------------------+

      A prove that both numbers were truncated:

      mysql> SELECT * FROM t1;
      +------+
      | a    |
      +------+
      |  127 |
      |  127 |
      +------+
      2 rows in set (0.00 sec)

      It should be fixed to report truncation in both cases.

      The problem happens because the valid range is checked after conversion to integer.
      It should be checked before conversion.

      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.