Support VALUES and parenthesized SELECTs as top-level statements

This commit is contained in:
Nikhil Benesch 2019-06-10 10:58:10 -04:00
parent b841dccc2c
commit ce171c2a3d
No known key found for this signature in database
GPG key ID: FCF98542083C5A69
2 changed files with 13 additions and 1 deletions

View file

@ -109,7 +109,7 @@ impl Parser {
match self.next_token() {
Some(t) => match t {
Token::SQLWord(ref w) if w.keyword != "" => match w.keyword.as_ref() {
"SELECT" | "WITH" => {
"SELECT" | "WITH" | "VALUES" => {
self.prev_token();
Ok(SQLStatement::SQLQuery(Box::new(self.parse_query()?)))
}
@ -133,6 +133,10 @@ impl Parser {
w.to_string()
)),
},
Token::LParen => {
self.prev_token();
Ok(SQLStatement::SQLQuery(Box::new(self.parse_query()?)))
}
unexpected => self.expected(
"a keyword at the beginning of a statement",
Some(unexpected),

View file

@ -181,6 +181,14 @@ fn parse_where_delete_statement() {
}
}
#[test]
fn parse_top_level() {
verified_stmt("SELECT 1");
verified_stmt("(SELECT 1)");
verified_stmt("((SELECT 1))");
verified_stmt("VALUES (1)");
}
#[test]
fn parse_simple_select() {
let sql = "SELECT id, fname, lname FROM customer WHERE id = 1 LIMIT 5";