diff --git a/expression/builtin_time.go b/expression/builtin_time.go index dca1b5dc96a5b..55c91a9ff3355 100644 --- a/expression/builtin_time.go +++ b/expression/builtin_time.go @@ -2574,7 +2574,7 @@ type baseDateArithmitical struct { func newDateArighmeticalUtil() baseDateArithmitical { return baseDateArithmitical{ - intervalRegexp: regexp.MustCompile(`[\d]+`), + intervalRegexp: regexp.MustCompile(`-?[\d]+`), } } diff --git a/expression/integration_test.go b/expression/integration_test.go index 2229e855062a1..2f21d0c97b875 100644 --- a/expression/integration_test.go +++ b/expression/integration_test.go @@ -3796,6 +3796,12 @@ func (s *testIntegrationSuite) TestTimeLiteral(c *C) { "Warning|1292|Incorrect datetime value: '2008-1-34'")) } +func (s *testIntegrationSuite) TestIssue13822(c *C) { + tk := testkit.NewTestKitWithInit(c, s.store) + tk.MustQuery("select ADDDATE(20111111, interval '-123' DAY);").Check(testkit.Rows("2011-07-11")) + tk.MustQuery("select SUBDATE(20111111, interval '-123' DAY);").Check(testkit.Rows("2012-03-13")) +} + func (s *testIntegrationSuite) TestTimestampLiteral(c *C) { defer s.cleanEnv(c) tk := testkit.NewTestKit(c, s.store)