Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support default for insert #600

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions sqlparser/analyzer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ func TestGetDBName(t *testing.T) {
"insert into a values(1)",
"update a set c=1",
"delete from a where c=d",
"insert into a(b, c) values (default, 2)",
"insert into a values (default, 2)",
"insert into a(b, c) values (1, default(c))",
}
for _, stmt := range wantNo {
result, err := GetDBName(stmt)
Expand Down
36 changes: 25 additions & 11 deletions sqlparser/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,7 @@ func (*BinaryExpr) IExpr() {}
func (*UnaryExpr) IExpr() {}
func (*FuncExpr) IExpr() {}
func (*CaseExpr) IExpr() {}
func (*DefaultExpr) IExpr() {}

// BoolExpr represents a boolean expression.
type BoolExpr interface {
Expand Down Expand Up @@ -600,17 +601,18 @@ type ValExpr interface {
Expr
}

func (StrVal) IValExpr() {}
func (NumVal) IValExpr() {}
func (ValArg) IValExpr() {}
func (*NullVal) IValExpr() {}
func (*ColName) IValExpr() {}
func (ValTuple) IValExpr() {}
func (*Subquery) IValExpr() {}
func (*BinaryExpr) IValExpr() {}
func (*UnaryExpr) IValExpr() {}
func (*FuncExpr) IValExpr() {}
func (*CaseExpr) IValExpr() {}
func (StrVal) IValExpr() {}
func (NumVal) IValExpr() {}
func (ValArg) IValExpr() {}
func (*NullVal) IValExpr() {}
func (*ColName) IValExpr() {}
func (ValTuple) IValExpr() {}
func (*Subquery) IValExpr() {}
func (*BinaryExpr) IValExpr() {}
func (*UnaryExpr) IValExpr() {}
func (*FuncExpr) IValExpr() {}
func (*CaseExpr) IValExpr() {}
func (*DefaultExpr) IValExpr() {}

// StrVal represents a string value.
type StrVal []byte
Expand Down Expand Up @@ -774,6 +776,18 @@ func (node *CaseExpr) Format(buf *TrackedBuffer) {
buf.Fprintf("end")
}

// DefaultExpr represents a DEFAULT expression.
type DefaultExpr struct {
Name *ColName
}

func (node *DefaultExpr) Format(buf *TrackedBuffer) {
buf.Fprintf("default")
if node.Name != nil {
buf.Fprintf("(%v)", node.Name)
}
}

// When represents a WHEN sub-expression.
type When struct {
Cond BoolExpr
Expand Down
Loading