diff --git a/executor/insert_test.go b/executor/insert_test.go index 93ad86e648e33..bc3e2d612d940 100644 --- a/executor/insert_test.go +++ b/executor/insert_test.go @@ -1309,3 +1309,20 @@ func (s *testSuite9) TestBinaryLiteralInsertToSet(c *C) { tk.MustExec("insert into bintest(h) values(0x61)") tk.MustQuery("select * from bintest").Check(testkit.Rows("a")) } + +func (s *testSuite9) TestIssue26762(c *C) { + tk := testkit.NewTestKit(c, s.store) + tk.MustExec(`use test`) + tk.MustExec("drop table if exists t1;") + tk.MustExec("create table t1(c1 date);") + _, err := tk.Exec("insert into t1 values('2020-02-31');") + c.Assert(err.Error(), Equals, `[table:1366]Incorrect date value: '2020-02-31' for column 'c1' at row 1`) + + tk.MustExec("set @@sql_mode='ALLOW_INVALID_DATES';") + tk.MustExec("insert into t1 values('2020-02-31');") + tk.MustQuery("select * from t1").Check(testkit.Rows("2020-02-31")) + + tk.MustExec("set @@sql_mode='STRICT_TRANS_TABLES';") + _, err = tk.Exec("insert into t1 values('2020-02-31');") + c.Assert(err.Error(), Equals, `[table:1366]Incorrect date value: '2020-02-31' for column 'c1' at row 1`) +} diff --git a/table/column.go b/table/column.go index 72fedda4fd796..2e78678056000 100644 --- a/table/column.go +++ b/table/column.go @@ -217,7 +217,8 @@ func handleZeroDatetime(ctx sessionctx.Context, col *model.ColumnInfo, casted ty return types.NewDatum(zeroV), true, nil } else if tm.IsZero() || tm.InvalidZero() { if tm.IsZero() { - if !mode.HasNoZeroDateMode() { + // Don't care NoZeroDate mode if time val is invalid. + if !tmIsInvalid && !mode.HasNoZeroDateMode() { return types.NewDatum(zeroV), true, nil } } else if tm.InvalidZero() {