Skip to content

Incompatible behaviors on display width #45338

@sayJason

Description

@sayJason

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

I try to store the same value in a TINYINT column but with different display widths, TiDB returns different values.

DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (c1 TINYINT(1) NOT NULL);
INSERT INTO t1 VALUES (-127);
SELECT c1 FROM t1 WHERE CAST(IFNULL(c1, '-') AS CHAR); -- {}, wrong

DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (c1 TINYINT(2) NOT NULL);
INSERT INTO t1 VALUES (-127);
SELECT c1 FROM t1 WHERE CAST(IFNULL(c1, '-') AS CHAR); -- {-127}, right

DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (c1 TINYINT(3) NOT NULL);
INSERT INTO t1 VALUES (-127);
SELECT c1 FROM t1 WHERE CAST(IFNULL(c1, '-') AS CHAR); -- {-127}, right

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

These three SELECTs return the same value -127.
I try the above example in MySQL, they all return -127.

3. What did you see instead (Required)

The first returns empty, while the other two return -127.

4. What is your TiDB version? (Required)

Release Version: v7.2.0
Edition: Community
Git Commit Hash: 9fd5f4a
Git Branch: heads/refs/tags/v7.2.0
UTC Build Time: 2023-06-27 15:04:42
GoVersion: go1.20.5
Race Enabled: false
Check Table Before Drop: false
Store: tikv

Metadata

Metadata

Assignees

No one assigned

    Labels

    affects-5.2This bug affects 5.2.x versions.affects-5.3This bug affects 5.3.x versions.affects-5.4This bug affects the 5.4.x(LTS) versions.affects-6.1This bug affects the 6.1.x(LTS) versions.affects-6.5This bug affects the 6.5.x(LTS) versions.affects-7.1This bug affects the 7.1.x(LTS) versions.affects-7.5This bug affects the 7.5.x(LTS) versions.affects-8.1This bug affects the 8.1.x(LTS) versions.severity/majorsig/executionSIG executiontype/bugThe issue is confirmed as a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions