Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expression: truncate time part for current_date columns #54045

Merged
merged 2 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.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
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(now());
tangenta marked this conversation as resolved.
Show resolved Hide resolved
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(now());
tangenta marked this conversation as resolved.
Show resolved Hide resolved