Skip to content

Commit

Permalink
Merge pull request #350 from pingcap/sheni/issue-320
Browse files Browse the repository at this point in the history
*: SubSelect can be used as select statement
  • Loading branch information
shenli committed Oct 13, 2015
2 parents f004aec + 522aa0c commit 8fec2e4
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 1 deletion.
6 changes: 6 additions & 0 deletions parser/parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -3481,6 +3481,12 @@ Statement:
| UnionStmt
| UpdateStmt
| UseStmt
| SubSelect
{
// `(select 1)`; is a valid select statement
// TODO: This is used to fix issue #320. There may be a better solution.
$$ = $1.(*subquery.SubQuery).Stmt
}

ExplainableStmt:
SelectStmt
Expand Down
3 changes: 3 additions & 0 deletions parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,9 @@ func (s *testParserSuite) TestDMLStmt(c *C) {
// For show create table
{"show create table test.t", true},
{"show create table t", true},

// For https://github.com/pingcap/tidb/issues/320
{`(select 1);`, true},
}
s.RunTest(c, table)
}
Expand Down
3 changes: 2 additions & 1 deletion tidb.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,8 @@ func trimSQL(sql string) string {
}
break
}
return sql
// Trim leading '('. For `(select 1);` is also a query.
return strings.TrimLeft(sql, "( ")
}

// IsQuery checks if a sql statement is a query statement.
Expand Down
1 change: 1 addition & 0 deletions tidb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ func (s *testMainSuite) TestIsQuery(c *C) {
{"/*comment*/ select 1;", true},
{"/*comment*/ /*comment*/ select 1;", true},
{"select /*comment*/ 1 /*comment*/;", true},
{"(select /*comment*/ 1 /*comment*/);", true},
}
for _, t := range tbl {
c.Assert(IsQuery(t.sql), Equals, t.ok, Commentf(t.sql))
Expand Down

0 comments on commit 8fec2e4

Please sign in to comment.