Skip to content

Commit a7bfc0a

Browse files
committed
Throw an error on CREATE VIEW statements, which were parsing as CREATE TABLE with an empty table spec prior to this change.
Signed-off-by: Zach Musgrave <zach@liquidata.co>
1 parent 994fc51 commit a7bfc0a

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

sql/parse/parse.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ var (
4747
unlockTablesRegex = regexp.MustCompile(`^unlock\s+tables$`)
4848
lockTablesRegex = regexp.MustCompile(`^lock\s+tables\s`)
4949
setRegex = regexp.MustCompile(`^set\s+`)
50+
createViewRegex = regexp.MustCompile(`^create\s+view\s+`)
5051
)
5152

5253
// These constants aren't exported from vitess for some reason. This could be removed if we changed this.
@@ -103,6 +104,9 @@ func Parse(ctx *sql.Context, query string) (sql.Node, error) {
103104
return parseLockTables(ctx, s)
104105
case setRegex.MatchString(lowerQuery):
105106
s = fixSetQuery(s)
107+
case createViewRegex.MatchString(lowerQuery):
108+
// CREATE VIEW parses as a CREATE DDL statement with an empty table spec
109+
return nil, ErrUnsupportedFeature.New("CREATE VIEW")
106110
}
107111

108112
stmt, err := sqlparser.Parse(s)

sql/parse/parse_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1296,6 +1296,7 @@ var fixturesErrors = map[string]*errors.Kind{
12961296
`SELECT INTERVAL 1 DAY + INTERVAL 1 DAY`: ErrUnsupportedSyntax,
12971297
`SELECT '2018-05-01' + (INTERVAL 1 DAY + INTERVAL 1 DAY)`: ErrUnsupportedSyntax,
12981298
`SELECT AVG(DISTINCT foo) FROM b`: ErrUnsupportedSyntax,
1299+
`CREATE VIEW view1 AS SELECT x FROM t1 WHERE x>0`: ErrUnsupportedFeature,
12991300
}
13001301

13011302
func TestParseErrors(t *testing.T) {

0 commit comments

Comments
 (0)