Skip to content

Commit

Permalink
expression: truncate time part for current_date columns (#54045) (#54575
Browse files Browse the repository at this point in the history
)

close #53746
  • Loading branch information
ti-chi-bot committed Jul 18, 2024
1 parent 4ba6bdd commit d5b1d9b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
14 changes: 11 additions & 3 deletions pkg/expression/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions tests/integrationtest/r/executor/write.result
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 6 additions & 0 deletions tests/integrationtest/t/executor/write.test
Original file line number Diff line number Diff line change
Expand Up @@ -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);

0 comments on commit d5b1d9b

Please sign in to comment.