@@ -4135,6 +4135,37 @@ func (s *testIntegrationSuite) TestDecimalConvertToTime(c *C) {
41354135 tk .MustQuery ("select * from t" ).Check (testkit .Rows ("2001-01-01 10:00:00.123456 2011-07-07 10:11:12" ))
41364136}
41374137
4138+ func (s * testIntegrationSuite ) TestIssue9732 (c * C ) {
4139+ tk := testkit .NewTestKit (c , s .store )
4140+ defer s .cleanEnv (c )
4141+
4142+ tk .MustQuery (`select monthname(str_to_date(null, '%m')), monthname(str_to_date(null, '%m')),
4143+ monthname(str_to_date(1, '%m')), monthname(str_to_date(0, '%m'));` ).Check (testkit .Rows ("<nil> <nil> <nil> <nil>" ))
4144+
4145+ nullCases := []struct {
4146+ sql string
4147+ ret string
4148+ }{
4149+ {"select str_to_date(1, '%m')" , "0000-01-00" },
4150+ {"select str_to_date(01, '%d')" , "0000-00-01" },
4151+ {"select str_to_date(2019, '%Y')" , "2019-00-00" },
4152+ {"select str_to_date('5,2019','%m,%Y')" , "2019-05-00" },
4153+ {"select str_to_date('01,2019','%d,%Y')" , "2019-00-01" },
4154+ {"select str_to_date('01,5','%d,%m')" , "0000-05-01" },
4155+ }
4156+
4157+ for _ , nullCase := range nullCases {
4158+ tk .MustQuery (nullCase .sql ).Check (testkit .Rows ("<nil>" ))
4159+ }
4160+
4161+ // remove NO_ZERO_DATE mode
4162+ tk .MustExec ("set sql_mode='ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'" )
4163+
4164+ for _ , nullCase := range nullCases {
4165+ tk .MustQuery (nullCase .sql ).Check (testkit .Rows (nullCase .ret ))
4166+ }
4167+ }
4168+
41384169func (s * testIntegrationSuite ) TestDaynameArithmetic (c * C ) {
41394170 tk := testkit .NewTestKit (c , s .store )
41404171 defer s .cleanEnv (c )
0 commit comments