diff --git a/ddl/ddl_api.go b/ddl/ddl_api.go index d47b40259a749..f028da0c2f1c6 100644 --- a/ddl/ddl_api.go +++ b/ddl/ddl_api.go @@ -870,7 +870,10 @@ func checkDefaultValue(ctx sessionctx.Context, c *table.Column, hasDefaultValue return nil } - if c.GetDefaultValue() != nil && !c.DefaultIsExpr { + if c.GetDefaultValue() != nil { + if c.DefaultIsExpr { + return nil + } if _, err := table.GetColDefaultValue(ctx, c.ToInfo()); err != nil { return types.ErrInvalidDefault.GenWithStackByArgs(c.Name) } diff --git a/ddl/sequence_test.go b/ddl/sequence_test.go index b52e3e7430c00..49920030c6f0e 100644 --- a/ddl/sequence_test.go +++ b/ddl/sequence_test.go @@ -255,6 +255,11 @@ func (s *testSequenceSuite) TestSequenceAsDefaultValue(c *C) { s.tk.MustExec("create sequence seq") // test the use sequence's nextval as default. + s.tk.MustExec("drop table if exists t") + s.tk.MustExec("create table t(a int not null default next value for seq key)") + s.tk.MustExec("drop table if exists t") + s.tk.MustExec("create table t(a int not null default nextval(seq), b int, primary key(a))") + s.tk.MustExec("create table t1 (a int default next value for seq)") s.tk.MustGetErrMsg("create table t2 (a char(1) default next value for seq)", "[ddl:8228]Unsupported sequence default value for column type 'a'")