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

Implicit CAST to INT works differently for a field vs a literal

    Details

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

      Description

      I use a string value in any context that assumes an integer input, for example LEFT(..., <string-value>), which causes implicit type cast.

      It works very differently when <string-value> is a literal vs a table column:

      DROP TABLE IF EXISTS t1;
      CREATE TABLE t1 (a VARCHAR(30));
      INSERT INTO t1 VALUES ('18446744073709551615');
      SELECT a, LEFT('test','18446744073709551615'), LEFT('test',a) FROM t1;
      SHOW WARNINGS;
      

      returns

      +----------------------+-------------------------------------+----------------+
      | a                    | LEFT('test','18446744073709551615') | LEFT('test',a) |
      +----------------------+-------------------------------------+----------------+
      | 18446744073709551615 |                                     | test           |
      +----------------------+-------------------------------------+----------------+
      1 row in set, 1 warning (0.00 sec)
      
      +---------+------+-----------------------------------------------------------+
      | Level   | Code | Message                                                   |
      +---------+------+-----------------------------------------------------------+
      | Warning | 1292 | Truncated incorrect INTEGER value: '18446744073709551615' |
      +---------+------+-----------------------------------------------------------+
      1 row in set (0.00 sec)
      

      Notice, LEFT() with a string literal in the second argument returned an empty string, while LEFT() with a string column with the same value returned 'test'.

      Also, only one warning was generated (the literal did not generate a warning, while the table column did).

      The expected behavior would be to return the same result and the same set of warnings for the two LEFT() calls.

        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:
                1 Start watching this issue

                Dates

                • Created:
                  Updated: