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

Truncation is not always reported when storing data into numeric fields

    Details

    • Type: Bug
    • Status: Open
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: 5.3.12, 5.5.36, 10.0.9
    • Fix Version/s: 10.0, 5.5
    • Component/s: None
    • Labels:
      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.

        Gliffy Diagrams

          Attachments

            Activity

            There are no comments yet on this issue.

              People

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

                Dates

                • Created:
                  Updated: