Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong default value for integer type #34881

Closed
Lloyd-Pottiger opened this issue May 23, 2022 · 5 comments · Fixed by #34947
Closed

Wrong default value for integer type #34881

Lloyd-Pottiger opened this issue May 23, 2022 · 5 comments · Fixed by #34947
Assignees
Labels
affects-6.1 This bug affects the 6.1.x(LTS) versions. component/parser report/customer Customers have encountered this bug. severity/moderate type/bug The issue is confirmed as a bug.

Comments

@Lloyd-Pottiger
Copy link
Contributor

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

Wrong default value for integer type cause error in tiflash: pingcap/tiflash#3157

mysql test> create table t (a int);
-- The type of column i is int, but the default value is set to "0.00"
mysql test> alter table t add column i int not null default 0.00; 
mysql test> show create table t;

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

+-------+-------------------------------------------------------------+
| Table | Create Table                                                |
+-------+-------------------------------------------------------------+
| t     | CREATE TABLE `t` (                                          |
|       |   `a` int(11) DEFAULT NULL,                                 |
|       |   `i` int(11) NOT NULL DEFAULT '0'                       |
|       | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin |
+-------+-------------------------------------------------------------+

3. What did you see instead (Required)

+-------+-------------------------------------------------------------+
| Table | Create Table                                                |
+-------+-------------------------------------------------------------+
| t     | CREATE TABLE `t` (                                          |
|       |   `a` int(11) DEFAULT NULL,                                 |
|       |   `i` int(11) NOT NULL DEFAULT '0.00'                       |
|       | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin |
+-------+-------------------------------------------------------------+

4. What is your TiDB version? (Required)

master

@Lloyd-Pottiger Lloyd-Pottiger added the type/bug The issue is confirmed as a bug. label May 23, 2022
@Lloyd-Pottiger
Copy link
Contributor Author

/component parser

@jebter jebter added the affects-6.1 This bug affects the 6.1.x(LTS) versions. label May 23, 2022
@Lloyd-Pottiger
Copy link
Contributor Author

mainly due to https://github.com/pingcap/tidb/blob/master/parser/model/model.go#L242, we set the c.DefaultValue = value directly in which value is in type of string. But when we check default value https://github.com/pingcap/tidb/blob/master/ddl/ddl_api.go#L1307-L1332
we will convert it into int

@Lloyd-Pottiger
Copy link
Contributor Author

/assign

@Lloyd-Pottiger
Copy link
Contributor Author

add another case:

test> create table td ( a int default 1.9, b int);
Query OK, 0 rows affected
Time: 0.079s
test> show create table td;
+-------+--------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table                                                                                                                               |
+-------+--------------------------------------------------------------------------------------------------------------------------------------------+
| td    | CREATE TABLE `td` (\n  `a` int(11) DEFAULT '2',\n  `b` int(11) DEFAULT NULL\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin |
+-------+--------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set
Time: 0.018s

@seiya-annie
Copy link

/found customer

@ti-chi-bot ti-chi-bot bot added the report/customer Customers have encountered this bug. label Jun 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects-6.1 This bug affects the 6.1.x(LTS) versions. component/parser report/customer Customers have encountered this bug. severity/moderate type/bug The issue is confirmed as a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants