diff --git a/expression/builtin_time_vec.go b/expression/builtin_time_vec.go index 0d6b4321095f5..5715a26e73e68 100644 --- a/expression/builtin_time_vec.go +++ b/expression/builtin_time_vec.go @@ -1133,7 +1133,6 @@ func (b *builtinStrToDateDurationSig) vecEvalDuration(input *chunk.Chunk, result result.MergeNulls(bufStrings, bufFormats) d64s := result.GoDurations() sc := b.ctx.GetSessionVars().StmtCtx - hasNoZeroDateMode := b.ctx.GetSessionVars().SQLMode.HasNoZeroDateMode() for i := 0; i < n; i++ { if result.IsNull(i) { continue @@ -1147,13 +1146,6 @@ func (b *builtinStrToDateDurationSig) vecEvalDuration(input *chunk.Chunk, result result.SetNull(i, true) continue } - if hasNoZeroDateMode && (t.Year() == 0 || t.Month() == 0 || t.Day() == 0) { - if err := handleInvalidTimeError(b.ctx, types.ErrWrongValue.GenWithStackByArgs(types.DateTimeStr, t.String())); err != nil { - return err - } - result.SetNull(i, true) - continue - } t.SetFsp(b.tp.GetDecimal()) dur, err := t.ConvertToDuration() if err != nil { diff --git a/expression/integration_test.go b/expression/integration_test.go index cf1ab5efa08e5..cd35a0c2fa497 100644 --- a/expression/integration_test.go +++ b/expression/integration_test.go @@ -7597,3 +7597,17 @@ func TestIssue36358(t *testing.T) { tk.MustQuery("select extract(day_microsecond from cast('2001-01-01 02:03:04.050607' as datetime(6))) from t").Check(testkit.Rows("1020304050607")) tk.MustQuery("select extract(day_microsecond from c) from t").Check(testkit.Rows("1020304050607")) } + +func TestIssue39146(t *testing.T) { + store, clean := testkit.CreateMockStore(t) + defer clean() + tk := testkit.NewTestKit(t, store) + tk.MustExec("use test") + tk.MustExec("CREATE TABLE `sun` ( `dest` varchar(10) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;") + tk.MustExec("insert into sun values('20231020');") + tk.MustExec("set @@sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';") + tk.MustExec("set @@tidb_enable_vectorized_expression = on;") + tk.MustQuery(`select str_to_date(substr(dest,1,6),'%H%i%s') from sun;`).Check(testkit.Rows("20:23:10")) + tk.MustExec("set @@tidb_enable_vectorized_expression = off;") + tk.MustQuery(`select str_to_date(substr(dest,1,6),'%H%i%s') from sun;`).Check(testkit.Rows("20:23:10")) +}