diff --git a/errors.toml b/errors.toml index cf529842919f0..ed5b374dc7c84 100644 --- a/errors.toml +++ b/errors.toml @@ -2846,6 +2846,11 @@ error = ''' invalid year ''' +["types:8034"] +error = ''' +Incorrect datetime value: '%s' +''' + ["types:8037"] error = ''' invalid week mode format: '%v' diff --git a/executor/executor_test.go b/executor/executor_test.go index 5679158971ebe..1cca04941e212 100644 --- a/executor/executor_test.go +++ b/executor/executor_test.go @@ -5515,6 +5515,10 @@ func TestStrToDateBuiltinWithWarnings(t *testing.T) { tk.MustExec("use test") tk.MustQuery(`SELECT STR_TO_DATE('0000-1-01', '%Y-%m-%d');`).Check(testkit.Rows("")) tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1411 Incorrect datetime value: '0000-1-01' for function str_to_date")) + tk.MustQuery("SELECT CAST('4#,8?Q' AS DATE);").Check(testkit.Rows("")) + tk.MustQuery(`show warnings;`).Check(testkit.Rows( + `Warning 8034 Incorrect datetime value: '4#,8?Q'`, + )) } func TestReadPartitionedTable(t *testing.T) { diff --git a/expression/builtin_cast_vec.go b/expression/builtin_cast_vec.go index d06bf3b346418..2dbbbc685a8a5 100644 --- a/expression/builtin_cast_vec.go +++ b/expression/builtin_cast_vec.go @@ -15,6 +15,7 @@ package expression import ( + "errors" "math" "strconv" "strings" @@ -1764,6 +1765,9 @@ func (b *builtinCastStringAsTimeSig) vecEvalTime(input *chunk.Chunk, result *chu } tm, err := types.ParseTime(stmtCtx, buf.GetString(i), b.tp.GetType(), fsp, nil) if err != nil { + if errors.Is(err, strconv.ErrSyntax) { + err = types.ErrIncorrectDatetimeValue.GenWithStackByArgs(buf.GetString(i)) + } if err = handleInvalidTimeError(b.ctx, err); err != nil { return err } diff --git a/expression/errors.go b/expression/errors.go index 0db38645f78d4..845bb3ac51653 100644 --- a/expression/errors.go +++ b/expression/errors.go @@ -67,7 +67,7 @@ var ( func handleInvalidTimeError(ctx sessionctx.Context, err error) error { if err == nil || !(types.ErrWrongValue.Equal(err) || types.ErrWrongValueForType.Equal(err) || types.ErrTruncatedWrongVal.Equal(err) || types.ErrInvalidWeekModeFormat.Equal(err) || - types.ErrDatetimeFunctionOverflow.Equal(err)) { + types.ErrDatetimeFunctionOverflow.Equal(err) || types.ErrIncorrectDatetimeValue.Equal(err)) { return err } sc := ctx.GetSessionVars().StmtCtx diff --git a/sessionctx/stmtctx/stmtctx.go b/sessionctx/stmtctx/stmtctx.go index 4261e5f3287ad..110812a8ad58b 100644 --- a/sessionctx/stmtctx/stmtctx.go +++ b/sessionctx/stmtctx/stmtctx.go @@ -880,7 +880,27 @@ func (sc *StatementContext) HandleTruncate(err error) error { if err == nil { return nil } +<<<<<<< HEAD if sc.IgnoreTruncate { +======= + + err = errors.Cause(err) + if e, ok := err.(*errors.Error); !ok || + (e.Code() != errno.ErrTruncatedWrongValue && + e.Code() != errno.ErrDataTooLong && + e.Code() != errno.ErrTruncatedWrongValueForField && + e.Code() != errno.ErrWarnDataOutOfRange && + e.Code() != errno.ErrDataOutOfRange && + e.Code() != errno.ErrBadNumber && + e.Code() != errno.ErrWrongValueForType && + e.Code() != errno.ErrDatetimeFunctionOverflow && + e.Code() != errno.WarnDataTruncated && + e.Code() != errno.ErrIncorrectDatetimeValue) { + return err + } + + if sc.IgnoreTruncate.Load() { +>>>>>>> 4f2ef40a0fe (*: fix warning message when to meet strconv.ErrSyntax (#43358)) return nil } if sc.TruncateAsWarning { diff --git a/types/errors.go b/types/errors.go index 94ac823891aa2..0542f3f5f2bd0 100644 --- a/types/errors.go +++ b/types/errors.go @@ -92,4 +92,6 @@ var ( // ErrPartitionColumnStatsMissing is returned when the partition-level column stats is missing and the build global-level stats fails. // Put this error here is to prevent `import cycle not allowed`. ErrPartitionColumnStatsMissing = dbterror.ClassTypes.NewStd(mysql.ErrPartitionColumnStatsMissing) + // ErrIncorrectDatetimeValue is returned when the input value is in wrong format for datetime. + ErrIncorrectDatetimeValue = dbterror.ClassTypes.NewStd(mysql.ErrIncorrectDatetimeValue) )