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
4 changes: 4 additions & 0 deletions sql/parser/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ func TestParse(t *testing.T) {
testData := []struct {
sql string
}{
// TODO(tschottdorf): shouldn't these below error?
{``},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The postgres grammar allows empty statements so that multiple semicolons in statement lists are ignored. For example, SELECT a FROM b; ; SELECT c FROM d;. Would be easy to call out an empty statement list as an error in Parse().

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, will do.

{`VALUES ("")`},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VALUES is actually considered a type of "select statement". I don't know if this is ANSI SQL, but postgres allows it:

pmattis=# VALUES (1, 2);
 column1 | column2
---------+---------
       1 |       2
(1 row)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, good to know. I'll update the comments in a future commit.


{`CREATE DATABASE a`},
{`CREATE DATABASE IF NOT EXISTS a`},
{`CREATE TABLE a ()`},
Expand Down
2 changes: 1 addition & 1 deletion sql/parser/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ func isDigit(ch int) bool {
}

func isIdent(s string) bool {
if !isIdentStart(int(s[0])) {
if len(s) == 0 || !isIdentStart(int(s[0])) {
return false
}
for i := 1; i < len(s); i++ {
Expand Down