diff --git a/go/vt/sqlparser/ast.go b/go/vt/sqlparser/ast.go index 2d7f65268ec..1a3c24317a0 100644 --- a/go/vt/sqlparser/ast.go +++ b/go/vt/sqlparser/ast.go @@ -1685,7 +1685,9 @@ func (node *CaseExpr) Format(buf *TrackedBuffer) { func (node *Default) Format(buf *TrackedBuffer) { buf.astPrintf(node, "default") if node.ColName != "" { - buf.astPrintf(node, "(%s)", node.ColName) + buf.WriteString("(") + formatID(buf, node.ColName, strings.ToLower(node.ColName), NoAt) + buf.WriteString(")") } } diff --git a/go/vt/sqlparser/ast_test.go b/go/vt/sqlparser/ast_test.go index 82d680567b8..ad0f190958e 100644 --- a/go/vt/sqlparser/ast_test.go +++ b/go/vt/sqlparser/ast_test.go @@ -24,6 +24,7 @@ import ( "testing" "unsafe" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -784,3 +785,9 @@ func TestSplitStatementToPieces(t *testing.T) { } } } + +func TestDefaultStatus(t *testing.T) { + assert.Equal(t, + String(&Default{ColName: "status"}), + "default(`status`)") +} diff --git a/go/vt/sqlparser/parse_test.go b/go/vt/sqlparser/parse_test.go index 915af6dbd3f..3b8681205f4 100644 --- a/go/vt/sqlparser/parse_test.go +++ b/go/vt/sqlparser/parse_test.go @@ -693,6 +693,8 @@ var ( input: "insert /* bool in on duplicate */ into a values (1, 2, 3) on duplicate key update b = values(a.b), c = d", }, { input: "insert /* bool expression on duplicate */ into a values (1, 2) on duplicate key update b = func(a), c = a > d", + }, { + input: "insert into user(username, `status`) values ('Chuck', default(`status`))", }, { input: "update /* simple */ a set b = 3", }, {