Skip to content

Commit

Permalink
ddl: fix sequence default value will cause primary-key occur not-null…
Browse files Browse the repository at this point in the history
… error (#16437) (#16510)
  • Loading branch information
sre-bot authored Apr 17, 2020
1 parent cb208cd commit cbe75ce
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
5 changes: 4 additions & 1 deletion ddl/ddl_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
5 changes: 5 additions & 0 deletions ddl/sequence_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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'")

Expand Down

0 comments on commit cbe75ce

Please sign in to comment.