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

Inconsistency between implicit and explicit conversion of 1/3 to char

    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 CHAR(10));
      INSERT INTO t1 VALUES (1/3);
      SHOW WARNINGS;
      SELECT *, CAST(1/3 AS CHAR) FROM t1;
      

      demonstrates some inconsistency between
      implicit and explicit conversion of 1/3 to CHAR:

      +---------+------+----------------------------------------+
      | Level   | Code | Message                                |
      +---------+------+----------------------------------------+
      | Warning | 1265 | Data truncated for column 'a' at row 1 |
      +---------+------+----------------------------------------+
      1 row in set (0.00 sec)
      
      +------------+-------------------+
      | a          | CAST(1/3 AS CHAR) |
      +------------+-------------------+
      | 0.33333333 | 0.3333            |
      +------------+-------------------+
      1 row in set (0.00 sec)
      

      Notice, explicit CAST preserves only 4 fractional digits, while
      implicit CAST preserves all fractional digits.

      The correct behaviour is probably to preserve all digits.

        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: