diff --git a/ddl/db_integration_test.go b/ddl/db_integration_test.go index 65439f822ec22..d5029076b64df 100644 --- a/ddl/db_integration_test.go +++ b/ddl/db_integration_test.go @@ -1430,3 +1430,13 @@ func (s *testIntegrationSuite) TestTreatOldVersionUTF8AsUTF8MB4(c *C) { " `b` varchar(50) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin")) } + +func (s *testIntegrationSuite) TestDefaultValueIsString(c *C) { + s.tk = testkit.NewTestKit(c, s.store) + s.tk.MustExec("use test") + s.tk.MustExec("drop table if exists t") + defer s.tk.MustExec("drop table if exists t") + s.tk.MustExec("create table t (a int default b'1');") + tbl := testGetTableByName(c, s.ctx, "test", "t") + c.Assert(tbl.Meta().Columns[0].DefaultValue, Equals, "1") +} diff --git a/ddl/ddl_api.go b/ddl/ddl_api.go index d020b6ce08f56..23903d73982fc 100644 --- a/ddl/ddl_api.go +++ b/ddl/ddl_api.go @@ -21,6 +21,7 @@ import ( "bytes" "context" "fmt" + "strconv" "strings" "sync/atomic" "time" @@ -532,8 +533,12 @@ func getDefaultValue(ctx sessionctx.Context, colName string, c *ast.ColumnOption // its raw string content here. return v.GetBinaryLiteral().ToString(), nil } - // For other kind of fields (e.g. INT), we supply its integer value so that it acts as integers. - return v.GetBinaryLiteral().ToInt(ctx.GetSessionVars().StmtCtx) + // For other kind of fields (e.g. INT), we supply its integer as string value. + value, err := v.GetBinaryLiteral().ToInt(ctx.GetSessionVars().StmtCtx) + if err != nil { + return nil, err + } + return strconv.FormatUint(value, 10), nil } if tp == mysql.TypeDuration {