Skip to content

Commit d6c07c4

Browse files
authored
table: Don't cast date default values (same as timestamp/datetime) (#59049)
close #59047
1 parent 49d7761 commit d6c07c4

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

ddl/db_partition_test.go

+9
Original file line numberDiff line numberDiff line change
@@ -4903,3 +4903,12 @@ func TestIssue54829(t *testing.T) {
49034903
}
49044904

49054905
// TODO: check EXCHANGE how it handles null (for all types of partitioning!!!)
4906+
4907+
func TestIssue59047(t *testing.T) {
4908+
store := testkit.CreateMockStore(t)
4909+
tk := testkit.NewTestKit(t, store)
4910+
tk.MustExec("use test")
4911+
tk.MustExec(`create table t (id bigint primary key, name varchar(20))`)
4912+
tk.MustExec(`alter table t add column d date not null`)
4913+
tk.MustExec(`update t set name = 'x'`)
4914+
}

table/column.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,9 @@ func getColDefaultValue(ctx sessionctx.Context, col *model.ColumnInfo, defaultVa
568568
return getColDefaultValueFromNil(ctx, col, args)
569569
}
570570

571-
if col.GetType() != mysql.TypeTimestamp && col.GetType() != mysql.TypeDatetime {
571+
switch col.GetType() {
572+
case mysql.TypeTimestamp, mysql.TypeDate, mysql.TypeDatetime:
573+
default:
572574
value, err := CastValue(ctx, types.NewDatum(defaultVal), col, false, false)
573575
if err != nil {
574576
return types.Datum{}, err

0 commit comments

Comments
 (0)