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
  • Loading branch information
AilinKid authored and lysu committed Apr 18, 2020
1 parent a19dc97 commit bdfec90
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 bdfec90

Please sign in to comment.