diff --git a/go/vt/sqlparser/ast.go b/go/vt/sqlparser/ast.go index 859ce6d1c39..ec2ddaaea68 100644 --- a/go/vt/sqlparser/ast.go +++ b/go/vt/sqlparser/ast.go @@ -2014,6 +2014,10 @@ type AlterCollationSpec struct { Collation string } +type AlterCommentSpec struct { + Comment string +} + type ProcedureSpec struct { ProcName ProcedureName Definer string @@ -2272,6 +2276,9 @@ type DDL struct { // AlterCollationSpec is set for CHARACTER SET / COLLATE operations on ALTER statements AlterCollationSpec *AlterCollationSpec + // AlterCommentSpec is set for COMMENT operations on ALTER statements + AlterCommentSpec *AlterCommentSpec + // EventSpec is set for CREATE EVENT operations EventSpec *EventSpec @@ -2676,6 +2683,8 @@ func (node *DDL) alterFormat(buf *TrackedBuffer) { if len(node.AlterCollationSpec.Collation) > 0 { buf.Myprintf(" collate %s", node.AlterCollationSpec.Collation) } + } else if node.AlterCommentSpec != nil { + buf.Myprintf(" comment '%s'", node.AlterCommentSpec.Comment) } } diff --git a/go/vt/sqlparser/parse_test.go b/go/vt/sqlparser/parse_test.go index b06cecf66e1..07d3e4b29e8 100644 --- a/go/vt/sqlparser/parse_test.go +++ b/go/vt/sqlparser/parse_test.go @@ -4245,7 +4245,19 @@ var ( }, { input: "alter table t comment='asdf'", - output: "alter table t", + output: "alter table t comment 'asdf'", + }, + { + input: `alter table t comment="asdf"`, + output: "alter table t comment 'asdf'", + }, + { + input: "alter table t comment 'asdf'", + output: "alter table t comment 'asdf'", + }, + { + input: `alter table t comment "asdf"`, + output: "alter table t comment 'asdf'", }, { input: "alter table t compression='asdf'", diff --git a/go/vt/sqlparser/sql.go b/go/vt/sqlparser/sql.go index ecd8139d985..a8b82988bd9 100644 --- a/go/vt/sqlparser/sql.go +++ b/go/vt/sqlparser/sql.go @@ -19645,7 +19645,7 @@ yydefault: yyDollar = yyS[yypt-3 : yypt+1] //line sql.y:6075 { - yyVAL.val = &DDL{Action: AlterStr} + yyVAL.val = &DDL{Action: AlterStr, AlterCommentSpec: &AlterCommentSpec{Comment: string(yyDollar[3].bytes)}} } case 998: yyDollar = yyS[yypt-3 : yypt+1] diff --git a/go/vt/sqlparser/sql.y b/go/vt/sqlparser/sql.y index deecbf44946..f2872db0dfd 100644 --- a/go/vt/sqlparser/sql.y +++ b/go/vt/sqlparser/sql.y @@ -6073,7 +6073,7 @@ alter_table_options: } | COMMENT_KEYWORD equal_opt STRING { - $$ = &DDL{Action: AlterStr} + $$ = &DDL{Action: AlterStr, AlterCommentSpec: &AlterCommentSpec{Comment: string($3)}} } | COMPRESSION equal_opt STRING {