diff --git a/pkg/expression/helper.go b/pkg/expression/helper.go index ae0d5153b92db..154d599142d95 100644 --- a/pkg/expression/helper.go +++ b/pkg/expression/helper.go @@ -92,14 +92,22 @@ func GetTimeValue(ctx BuildContext, v any, tp byte, fsp int, explicitTz *time.Lo 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.GetEvalCtx(), tp, fsp); err != nil { return d, err } - } else if lowerX == types.ZeroDatetimeStr { + case ast.CurrentDate: + if value, err = getTimeCurrentTimeStamp(ctx.GetEvalCtx(), 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(tc, 0, tp, fsp) terror.Log(err) - } else { + default: value, err = types.ParseTime(tc, x, tp, fsp) if err != nil { return d, err diff --git a/tests/integrationtest/r/executor/write.result b/tests/integrationtest/r/executor/write.result index 2d8beea1b32d9..64356a3097d2a 100644 --- a/tests/integrationtest/r/executor/write.result +++ b/tests/integrationtest/r/executor/write.result @@ -2146,3 +2146,9 @@ Error 1364 (HY000): Field 'pk' doesn't have a default value replace t2 set c=default(a); Error 3105 (HY000): The value specified for generated column 'c' in table 't2' is not allowed. drop table t1, t2; +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 abea1af658bc4..3da9c50888acc 100644 --- a/tests/integrationtest/t/executor/write.test +++ b/tests/integrationtest/t/executor/write.test @@ -1350,3 +1350,8 @@ replace t2 set a=default(a), c=default(c); replace t2 set c=default(a); drop table t1, t2; +# 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);