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

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

    XMLWordPrintable

Details

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

      Attachments

        Activity

          People

            bar Alexander Barkov
            bar Alexander Barkov
            Votes:
            0 Vote for this issue
            Watchers:
            1 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.