diff --git a/executor/insert_common.go b/executor/insert_common.go index 520d594fb41a7..a4ea2a566b5f6 100644 --- a/executor/insert_common.go +++ b/executor/insert_common.go @@ -499,10 +499,10 @@ func (e *InsertValues) getColDefaultValue(idx int, col *table.Column) (d types.D } var defaultVal types.Datum - if !col.DefaultIsExpr { - defaultVal, err = table.GetColDefaultValue(e.ctx, col.ToInfo()) - } else { + if col.DefaultIsExpr && col.DefaultExpr != nil { defaultVal, err = table.EvalColDefaultExpr(e.ctx, col.ToInfo(), col.DefaultExpr) + } else { + defaultVal, err = table.GetColDefaultValue(e.ctx, col.ToInfo()) } if err != nil { return types.Datum{}, err diff --git a/go.sum b/go.sum index ed94b8ad844a1..79473a8cb3cd0 100644 --- a/go.sum +++ b/go.sum @@ -195,8 +195,6 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/pty v1.1.5/go.mod h1:9r2w37qlBe7rQ6e1fg1S/9xpWHSnaqNdHD3WcMdbPDA= github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= -github.com/lawyerphx/parser v0.0.0-20200316023126-7af13c9e0b85 h1:my5oTuBLzT1knvQnwaF7RXxNuzvzqhioNM8OcHYF2/A= -github.com/lawyerphx/parser v0.0.0-20200316023126-7af13c9e0b85/go.mod h1:9v0Edh8IbgjGYW2ArJr19E+bvL8zKahsFp+ixWeId+4= github.com/leodido/go-urn v1.1.0/go.mod h1:+cyI34gQWZcE1eQU7NVgKkkzdXDQHr1dBMtdAPozLkw= github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII= github.com/lib/pq v1.1.1/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= diff --git a/planner/core/planbuilder.go b/planner/core/planbuilder.go index 68c85eabf9900..ec0787d756848 100644 --- a/planner/core/planbuilder.go +++ b/planner/core/planbuilder.go @@ -1821,10 +1821,10 @@ func (b *PlanBuilder) getDefaultValue(col *table.Column) (*expression.Constant, value types.Datum err error ) - if !col.DefaultIsExpr { - value, err = table.GetColDefaultValue(b.ctx, col.ToInfo()) - } else { + if col.DefaultIsExpr && col.DefaultExpr != nil { value, err = table.EvalColDefaultExpr(b.ctx, col.ToInfo(), col.DefaultExpr) + } else { + value, err = table.GetColDefaultValue(b.ctx, col.ToInfo()) } if err != nil { return nil, err