Skip to content

Commit

Permalink
executor: set length and frac when we change zero to decimal t… (#16518)
Browse files Browse the repository at this point in the history
  • Loading branch information
Reminiscent authored Apr 17, 2020
1 parent 31ff075 commit a0c7407
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
10 changes: 10 additions & 0 deletions executor/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5397,3 +5397,13 @@ func (s *testSuite1) TestIssue15767(c *C) {
tk.MustExec("insert into t select * from t;")
tk.MustQuery("select b, count(*) from ( select b from t order by a limit 20 offset 2) as s group by b order by b;").Check(testkit.Rows("a 6", "c 7", "s 7"))
}

func (s *testSuite1) TestIssue16025(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test;")
tk.MustExec("drop table if exists t0;")
tk.MustExec("CREATE TABLE t0(c0 NUMERIC PRIMARY KEY);")
tk.MustExec("INSERT IGNORE INTO t0(c0) VALUES (NULL);")
tk.MustQuery("SELECT * FROM t0 WHERE c0;").Check(testkit.Rows())

}
11 changes: 11 additions & 0 deletions executor/insert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1132,3 +1132,14 @@ func (s *testSuite9) TestInsertErrorMsg(c *C) {
c.Assert(err, NotNil)
c.Assert(strings.Contains(err.Error(), "Incorrect datetime value: '2019-02-11 30:00:00' for column 'b' at row 1"), IsTrue, Commentf("%v", err))
}

func (s *testSuite9) TestIssue16366(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec(`use test;`)
tk.MustExec(`drop table if exists t;`)
tk.MustExec(`create table t(c numeric primary key);`)
tk.MustExec("insert ignore into t values(null);")
_, err := tk.Exec(`insert into t values(0);`)
c.Assert(err, NotNil)
c.Assert(strings.Contains(err.Error(), "Duplicate entry '0' for key 'PRIMARY'"), IsTrue, Commentf("%v", err))
}
2 changes: 2 additions & 0 deletions table/column.go
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,8 @@ func GetZeroValue(col *model.ColumnInfo) types.Datum {
case mysql.TypeDouble:
d.SetFloat64(0)
case mysql.TypeNewDecimal:
d.SetLength(col.Flen)
d.SetFrac(col.Decimal)
d.SetMysqlDecimal(new(types.MyDecimal))
case mysql.TypeString:
if col.Flen > 0 && col.Charset == charset.CharsetBin {
Expand Down

0 comments on commit a0c7407

Please sign in to comment.