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

When the default value is an expression, changing it to a constant by "set default" can be problematic #51554

Closed
Tracked by #50936
zimulala opened this issue Mar 6, 2024 · 0 comments · Fixed by #51571
Assignees
Labels
affects-7.1 affects-7.5 component/ddl This issue is related to DDL of TiDB. severity/major type/bug This issue is a bug.

Comments

@zimulala
Copy link
Contributor

zimulala commented Mar 6, 2024

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

drop table t;
create table t (c int(10), c1 varchar(256)  default rand());
alter table t alter column c1 set default 'xx';
show create table t;
insert into t values (1, default);

drop table t;
create table t (c int(10), c1 varchar(256)  default (REPLACE(UPPER(UUID()), '-', '')));
alter table t alter column c1 set default 'xx';
show create table t;
insert into t values (1, default);

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

mysql> insert into t values (5, default);
Query OK, 1 row affected (0.00 sec)

mysql> insert into t values (5, default);
Query OK, 1 row affected (0.00 sec)

3. What did you see instead (Required)

tidb> show create table t;
+-------+-------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table                                                                                                                              |
+-------+-------------------------------------------------------------------------------------------------------------------------------------------+
| t     | CREATE TABLE `t` (
  `c` int(10) DEFAULT NULL,
  `c1` varchar(256) DEFAULT xx
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin |
+-------+-------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

tidb> insert into t values (1, default);
ERROR 1054 (42S22): Unknown column 'xx' in 'expression'

4. What is your TiDB version? (Required)

master

@zimulala zimulala added type/bug This issue is a bug. severity/major component/ddl This issue is related to DDL of TiDB. labels Mar 6, 2024
@zimulala zimulala self-assigned this Mar 6, 2024
ti-chi-bot bot pushed a commit that referenced this issue Mar 11, 2024
ti-chi-bot bot pushed a commit that referenced this issue Apr 16, 2024
ti-chi-bot bot pushed a commit that referenced this issue May 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects-7.1 affects-7.5 component/ddl This issue is related to DDL of TiDB. severity/major type/bug This issue is a bug.
Projects
None yet
1 participant