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

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

    XMLWordPrintable

Details

    • Bug
    • Status: Open (View Workflow)
    • Minor
    • Resolution: Unresolved
    • 5.5.36, 10.0.9
    • 5.5(EOL)
    • None
    • 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.

      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.