Skip to content

Commit

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

close #53746
  • Loading branch information
ti-chi-bot authored Aug 5, 2024
1 parent 5863a6f commit 787fe24
Show file tree
Hide file tree
Showing 3 changed files with 22 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 @@ -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, 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(tc, 0, tp, fsp)
terror.Log(err)
} else {
default:
value, err = types.ParseTime(tc, x, tp, fsp)
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 @@ -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
5 changes: 5 additions & 0 deletions tests/integrationtest/t/executor/write.test
Original file line number Diff line number Diff line change
Expand Up @@ -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);

0 comments on commit 787fe24

Please sign in to comment.