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

Conversion from string to number is inconsistent

    Details

    • Type: Bug
    • Status: Open
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: 5.5.36, 10.0.9
    • Fix Version/s: 10.0, 5.5
    • Component/s: None
    • Labels:
      None

      Description

      This SQL script:

      DROP TABLE IF EXISTS t1;
      CREATE TABLE t1 (a INT);
      INSERT INTO t1 VALUES ('10.6');
      SELECT a, CAST('10.6' AS SIGNED) FROM t1;
      SHOW WARNINGS;
      

      returns:

      +------+------------------------+
      | a    | CAST('10.6' AS SIGNED) |
      +------+------------------------+
      |   11 |                     10 |
      +------+------------------------+
      1 row in set, 1 warning (0.00 sec)
      +---------+------+-------------------------------------------+
      | Level   | Code | Message                                   |
      +---------+------+-------------------------------------------+
      | Warning | 1292 | Truncated incorrect INTEGER value: '10.6' |
      +---------+------+-------------------------------------------+
      1 row in set (0.00 sec)
      

      Notice, when converting to a field, it rounds silently.
      When converting in CAST, it truncates with a warning.

      It should be fixed to expose similar behaviour in both cases.

      The questions is: which of them is correct?

        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: