mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-10-09 13:40:22 +00:00
Support VALUES and parenthesized SELECTs as top-level statements
This commit is contained in:
parent
b841dccc2c
commit
ce171c2a3d
2 changed files with 13 additions and 1 deletions
|
@ -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),
|
||||
|
|
|
@ -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";
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue