Skip to content

Commit

Permalink
sql: fix create database reparse issue
Browse files Browse the repository at this point in the history
The create database test were having reparse issues
because the syntax requires an integer constant for
the CONNECTION LIMIT parameter. This change replaces
the underscore with an integer.

Release note: None
  • Loading branch information
e-mbrown committed Aug 4, 2021
1 parent 2317cc8 commit 8da5cd4
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
6 changes: 2 additions & 4 deletions pkg/sql/parser/testdata/create_database
Original file line number Diff line number Diff line change
Expand Up @@ -128,17 +128,15 @@ CREATE DATABASE a CONNECTION LIMIT = 13
----
CREATE DATABASE a CONNECTION LIMIT = 13
CREATE DATABASE a CONNECTION LIMIT = 13 -- fully parenthesized
CREATE DATABASE a CONNECTION LIMIT = _ -- literals removed
REPARSE WITHOUT LITERALS FAILS: at or near "_": syntax error
CREATE DATABASE a CONNECTION LIMIT = 0 -- literals removed
CREATE DATABASE _ CONNECTION LIMIT = 13 -- identifiers removed

parse
CREATE DATABASE a WITH CONNECTION LIMIT = 13
----
CREATE DATABASE a CONNECTION LIMIT = 13 -- normalized!
CREATE DATABASE a CONNECTION LIMIT = 13 -- fully parenthesized
CREATE DATABASE a CONNECTION LIMIT = _ -- literals removed
REPARSE WITHOUT LITERALS FAILS: at or near "_": syntax error
CREATE DATABASE a CONNECTION LIMIT = 0 -- literals removed
CREATE DATABASE _ CONNECTION LIMIT = 13 -- identifiers removed

parse
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/sem/tree/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func (node *CreateDatabase) Format(ctx *FmtCtx) {
if node.ConnectionLimit != -1 {
ctx.WriteString(" CONNECTION LIMIT = ")
if ctx.flags.HasFlags(FmtHideConstants) {
ctx.WriteByte('_')
ctx.WriteByte('0')
} else {
// NB: use ctx.FormatNode when the connection limit becomes an expression.
ctx.WriteString(strconv.Itoa(int(node.ConnectionLimit)))
Expand Down

0 comments on commit 8da5cd4

Please sign in to comment.