Skip to content

Commit

Permalink
ddl: reorganize in conversion between double and float
Browse files Browse the repository at this point in the history
Signed-off-by: unconsolable <chenzhipeng2012@gmail.com>
  • Loading branch information
unconsolable committed Jan 7, 2022
1 parent 40c0567 commit 26633cc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
6 changes: 1 addition & 5 deletions ddl/column.go
Original file line number Diff line number Diff line change
Expand Up @@ -736,11 +736,7 @@ func needChangeColumnData(oldCol, newCol *model.ColumnInfo) bool {
case mysql.TypeTiny, mysql.TypeShort, mysql.TypeInt24, mysql.TypeLong, mysql.TypeLonglong:
return needTruncationOrToggleSignForInteger()
}
case mysql.TypeFloat, mysql.TypeDouble:
switch newCol.Tp {
case mysql.TypeFloat, mysql.TypeDouble:
return needTruncationOrToggleSign()
}
// conversion between float and double needs reorganization, see issue #31372
}

return true
Expand Down
16 changes: 16 additions & 0 deletions ddl/column_type_change_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2352,3 +2352,19 @@ func (s *testColumnTypeChangeSuite) TestChangeNullValueFromOtherTypeToTimestamp(
_, err = tk.Exec("insert into t values(null)")
c.Assert(err.Error(), Equals, "[table:1048]Column 'a' cannot be null")
}

func (s *testColumnTypeChangeSuite) TestColumnTypeChangeFromFloatToDouble(c *C) {
// issue #31372
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")

prepare := func() {
tk.MustExec("drop table if exists t;")
tk.MustExec("create table t (a float(6,2));")
tk.MustExec("insert into t values (36.4), (24.1);")
}

prepare()
tk.MustExec("alter table t modify a double(6,2)")
tk.MustQuery("select a from t;").Check(testkit.Rows("36.4", "24.1"))
}

0 comments on commit 26633cc

Please sign in to comment.