pingcap / tidb

TiDB is an open-source, cloud-native, distributed, MySQL-Compatible database for elastic scale and real-time analytics. Try AI-powered Chat2Query free at : https://www.pingcap.com/tidb-serverless/
https://pingcap.com
Apache License 2.0
37.05k stars 5.83k forks source link

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

Open dveeden opened 6 days ago

dveeden commented 6 days ago

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)

Related

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

This is related to https://github.com/pingcap/tidb/issues/44786

lawrence1223freenew commented 4 days ago

From databricks https://pingcap-ticket.atlassian.net/jira/servicedesk/projects/NAID/queues/custom/29/NAID-10828