Skip to content

Commit

Permalink
Merge pull request #8502 from planetscale/default-bool
Browse files Browse the repository at this point in the history
boolean values should not be parenthesised in default clause
  • Loading branch information
systay authored Jul 20, 2021
2 parents c9575b6 + ae10f2f commit ede1c3b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
3 changes: 2 additions & 1 deletion go/vt/sqlparser/ast_format.go
Original file line number Diff line number Diff line change
Expand Up @@ -473,8 +473,9 @@ func (ct *ColumnType) Format(buf *TrackedBuffer) {
if ct.Options.Default != nil {
buf.astPrintf(ct, " %s", keywordStrings[DEFAULT])
_, isLiteral := ct.Options.Default.(*Literal)
_, isBool := ct.Options.Default.(BoolVal)
_, isNullVal := ct.Options.Default.(*NullVal)
if isLiteral || isNullVal || isExprAliasForCurrentTimeStamp(ct.Options.Default) {
if isLiteral || isNullVal || isBool || isExprAliasForCurrentTimeStamp(ct.Options.Default) {
buf.astPrintf(ct, " %v", ct.Options.Default)
} else {
buf.astPrintf(ct, " (%v)", ct.Options.Default)
Expand Down
3 changes: 2 additions & 1 deletion go/vt/sqlparser/ast_format_fast.go

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

3 changes: 3 additions & 0 deletions go/vt/sqlparser/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1178,6 +1178,9 @@ var (
}, {
input: "create table function_default3 (x bool DEFAULT (true AND false));",
output: "create table function_default3 (\n\tx bool default (true and false)\n)",
}, {
input: "create table function_default (x bool DEFAULT true);",
output: "create table function_default (\n\tx bool default true\n)",
}, {
input: "create table a (\n\t`a` int\n)",
output: "create table a (\n\ta int\n)",
Expand Down

0 comments on commit ede1c3b

Please sign in to comment.