Skip to content
Merged
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
5 changes: 4 additions & 1 deletion go/vt/sqlparser/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -1220,7 +1220,10 @@ func (ii *IndexInfo) Format(buf *TrackedBuffer) {
if ii.Primary {
buf.Myprintf("%s", ii.Type)
} else {
buf.Myprintf("%s %v", ii.Type, ii.Name)
buf.Myprintf("%s", ii.Type)
if !ii.Name.IsEmpty() {
buf.Myprintf(" %v", ii.Name)
}
}
}

Expand Down
15 changes: 15 additions & 0 deletions go/vt/sqlparser/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1842,6 +1842,7 @@ func TestCreateTable(t *testing.T) {
" c int,\n" +
" primary key (id, username),\n" +
" unique key by_abc (a, b, c),\n" +
" unique key (a, b, c),\n" +
" key by_email (email(10), username)\n" +
")",

Expand Down Expand Up @@ -1938,6 +1939,20 @@ func TestCreateTable(t *testing.T) {
" unique key by_username2 (username) key_block_size 8,\n" +
" unique by_username3 (username) key_block_size 4\n" +
")",
}, {
// test current_timestamp with and without ()
input: "create table t (\n" +
" time1 timestamp default current_timestamp,\n" +
" time2 timestamp default current_timestamp(),\n" +
" time3 timestamp default current_timestamp on update current_timestamp,\n" +
" time4 timestamp default current_timestamp() on update current_timestamp()\n" +
")",
output: "create table t (\n" +
" time1 timestamp default current_timestamp,\n" +
" time2 timestamp default current_timestamp,\n" +
" time3 timestamp default current_timestamp on update current_timestamp,\n" +
" time4 timestamp default current_timestamp on update current_timestamp\n" +
")",
},
}
for _, tcase := range testCases {
Expand Down
Loading