Skip to content

Casting integer with display width to string results in truncation #56462

@dveeden

Description

@dveeden

Bug Report

1. Minimal reproduce step (Required)

DROP TABLE IF EXISTS test.t;
CREATE TABLE test.t (id bigint(11) UNSIGNED PRIMARY KEY);
INSERT INTO test.t VALUES (1234567890123456);
SELECT IFNULL(id, 'abcdef') FROM test.t;

2. What did you expect to see? (Required)

MySQL:

mysql-9.0.1> DROP TABLE IF EXISTS test.t;
Query OK, 0 rows affected (0.02 sec)

mysql-9.0.1> CREATE TABLE test.t (id bigint(11) UNSIGNED PRIMARY KEY);
Query OK, 0 rows affected, 1 warning (0.02 sec)

mysql-9.0.1> INSERT INTO test.t VALUES (1234567890123456);
Query OK, 1 row affected (0.00 sec)

mysql-9.0.1> SELECT IFNULL(id, 'abcdef') FROM test.t;
+----------------------+
| IFNULL(id, 'abcdef') |
+----------------------+
| 1234567890123456     |
+----------------------+
1 row in set (0.00 sec)

3. What did you see instead (Required)

TiDB:

mysql-8.0.11-TiDB-v8.3.0> DROP TABLE IF EXISTS test.t;
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql-8.0.11-TiDB-v8.3.0> CREATE TABLE test.t (id bigint(11) UNSIGNED PRIMARY KEY);
Query OK, 0 rows affected (0.05 sec)

mysql-8.0.11-TiDB-v8.3.0> INSERT INTO test.t VALUES (1234567890123456);
Query OK, 1 row affected (0.00 sec)

mysql-8.0.11-TiDB-v8.3.0> SELECT IFNULL(id, 'abcdef') FROM test.t;
+----------------------+
| IFNULL(id, 'abcdef') |
+----------------------+
| 12345678901          |
+----------------------+
1 row in set, 1 warning (0.00 sec)

mysql-8.0.11-TiDB-v8.3.0> SHOW WARNINGS;
+---------+------+------------------------------------------+
| Level   | Code | Message                                  |
+---------+------+------------------------------------------+
| Warning | 1406 | Data Too Long, field len 11, data len 16 |
+---------+------+------------------------------------------+
1 row in set (0.00 sec)

4. What is your TiDB version? (Required)

  • v8.3.0
  • v7.5.1

Related

This is similar to #44213 but for a different set of types.

This is related to #44786

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions