-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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, executor: castStringAsTime returns null when sql_mode is not strict #8516
Conversation
/run-all-tests |
PTAL @tiancaiamao @zz-jason |
PTAL @tiancaiamao @winoros |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@@ -1175,13 +1175,13 @@ func (b *builtinCastStringAsTimeSig) evalTime(row chunk.Row) (res types.Time, is | |||
sc := b.ctx.GetSessionVars().StmtCtx | |||
res, err = types.ParseTime(sc, val, b.tp.Tp, b.tp.Decimal) | |||
if err != nil { | |||
return res, false, errors.Trace(err) | |||
return types.Time{}, true, handleInvalidTimeError(b.ctx, err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happen if b.tp.Tp is mysql.TypeTimestamp? 00-00-00 00:00:00 seems not a legal timestamp value ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here the return value is either a NULL or an error. The returned types.Time{}
is never used.
LGTM |
should we cherry-pick this commit to release-2.1? @XuHuaiyu |
What problem does this PR solve?
castStringAsTime returns null when sql_mode is not strict.
Before this commit, the following query will raise an error:
What is changed and how it works?
Check List
Tests
Code changes
Side effects
It's really hard to make all the behavior to be compatiable with MySQL when cast a string as datetime. The results of MySQL are different between implicit cast and explict cast.
e.g.
We return NULL here despite of implict cast or explicit cast. Thus it may break some backward compatibility with MySQL.
e.g.
Maybe we need to check the warning as this comment mentioned.
e.g.
Related changes
This change is