Skip to content

Commit

Permalink
table: Don't cast date default values (same as timestamp/datetime) (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
mjonss authored and YangKeao committed Jan 23, 2025
1 parent e0726e7 commit b181a7b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
9 changes: 9 additions & 0 deletions ddl/db_partition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4903,3 +4903,12 @@ func TestIssue54829(t *testing.T) {
}

// TODO: check EXCHANGE how it handles null (for all types of partitioning!!!)

func TestIssue59047(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec(`create table t (id bigint primary key, name varchar(20))`)
tk.MustExec(`alter table t add column d date not null`)
tk.MustExec(`update t set name = 'x'`)
}
4 changes: 3 additions & 1 deletion table/column.go
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,9 @@ func getColDefaultValue(ctx sessionctx.Context, col *model.ColumnInfo, defaultVa
return getColDefaultValueFromNil(ctx, col, args)
}

if col.GetType() != mysql.TypeTimestamp && col.GetType() != mysql.TypeDatetime {
switch col.GetType() {
case mysql.TypeTimestamp, mysql.TypeDate, mysql.TypeDatetime:
default:
value, err := CastValue(ctx, types.NewDatum(defaultVal), col, false, false)
if err != nil {
return types.Datum{}, err
Expand Down

0 comments on commit b181a7b

Please sign in to comment.