Skip to content
This repository has been archived by the owner on Dec 16, 2022. It is now read-only.

Commit

Permalink
Partially apply bugfix in vitessio#8468
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Mason <amason@slack-corp.com>
  • Loading branch information
ajm188 committed Jul 18, 2021
1 parent 6ec68f1 commit 767d29c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
6 changes: 3 additions & 3 deletions go/vt/sqlparser/ast_format.go
Original file line number Diff line number Diff line change
Expand Up @@ -467,10 +467,10 @@ func (ct *ColumnType) Format(buf *TrackedBuffer) {
buf.astPrintf(ct, " %s", keywordStrings[DEFAULT])
_, isLiteral := ct.Options.Default.(*Literal)
_, isNullVal := ct.Options.Default.(*NullVal)
if isLiteral || isNullVal {
buf.astPrintf(ct, " %v", String(ct.Options.Default))
if isLiteral || isNullVal || isExprAliasForCurrentTimeStamp(ct.Options.Default) {
buf.astPrintf(ct, " %v", ct.Options.Default)
} else {
buf.astPrintf(ct, " (%v)", String(ct.Options.Default))
buf.astPrintf(ct, " (%v)", ct.Options.Default)
}
}
if ct.Options.OnUpdate != nil {
Expand Down
6 changes: 3 additions & 3 deletions go/vt/sqlparser/ast_format_fast.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions go/vt/sqlparser/ast_funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1301,6 +1301,17 @@ func (node *ColName) CompliantName(suffix string) string {
return node.Name.CompliantName() + suffix
}

// isExprAliasForCurrentTimeStamp returns true if the Expr provided is an alias for CURRENT_TIMESTAMP
func isExprAliasForCurrentTimeStamp(expr Expr) bool {
switch node := expr.(type) {
case *FuncExpr:
return node.Name.EqualString("current_timestamp") || node.Name.EqualString("now") || node.Name.EqualString("localtimestamp") || node.Name.EqualString("localtime")
case *CurTimeFuncExpr:
return node.Name.EqualString("current_timestamp") || node.Name.EqualString("now") || node.Name.EqualString("localtimestamp") || node.Name.EqualString("localtime")
}
return false
}

// AtCount represents the '@' count in ColIdent
type AtCount int

Expand Down

0 comments on commit 767d29c

Please sign in to comment.