diff --git a/pkg/expression/helper.go b/pkg/expression/helper.go index 2cb0f161bb13f..a7b8c2b7254da 100644 --- a/pkg/expression/helper.go +++ b/pkg/expression/helper.go @@ -94,14 +94,22 @@ func GetTimeValue(ctx sessionctx.Context, v interface{}, tp byte, fsp int, expli switch x := v.(type) { case string: lowerX := strings.ToLower(x) - if lowerX == ast.CurrentTimestamp || lowerX == ast.CurrentDate { + switch lowerX { + case ast.CurrentTimestamp: if value, err = getTimeCurrentTimeStamp(ctx, tp, fsp); err != nil { return d, err } - } else if lowerX == types.ZeroDatetimeStr { + case ast.CurrentDate: + if value, err = getTimeCurrentTimeStamp(ctx, tp, fsp); err != nil { + return d, err + } + yy, mm, dd := value.Year(), value.Month(), value.Day() + truncated := types.FromDate(yy, mm, dd, 0, 0, 0, 0) + value.SetCoreTime(truncated) + case types.ZeroDatetimeStr: value, err = types.ParseTimeFromNum(sc, 0, tp, fsp) terror.Log(err) - } else { + default: value, err = types.ParseTime(sc, x, tp, fsp, explicitTz) if err != nil { return d, err diff --git a/tests/integrationtest/r/executor/write.result b/tests/integrationtest/r/executor/write.result index 9916eff8e9f64..2d6fada04c409 100644 --- a/tests/integrationtest/r/executor/write.result +++ b/tests/integrationtest/r/executor/write.result @@ -1888,3 +1888,9 @@ update t force index(primary) set b = 10 where a = '2023-06-11 10:00:00'; admin check table t; drop table if exists t; +drop table if exists t; +create table t (a date default current_date); +insert into t values(); +select count(1) from t where a = date(a); +count(1) +1 diff --git a/tests/integrationtest/t/executor/write.test b/tests/integrationtest/t/executor/write.test index 8c3ac8c33bfe5..4e249e2aa18a5 100644 --- a/tests/integrationtest/t/executor/write.test +++ b/tests/integrationtest/t/executor/write.test @@ -1147,3 +1147,9 @@ insert into t values ('2023-06-11 10:00:00', 1); update t force index(primary) set b = 10 where a = '2023-06-11 10:00:00'; admin check table t; drop table if exists t; + +# TestIssue53746 +drop table if exists t; +create table t (a date default current_date); +insert into t values(); +select count(1) from t where a = date(a);