mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-10-12 15:02:07 +00:00
Support VALUES clauses in FROM
VALUES clauses are not just valid in INSERT statements. They're also valid (basically) anywhere table expressions are accepted, like in FROM clauses.
This commit is contained in:
parent
a3aaa49a7e
commit
9420070a0d
4 changed files with 83 additions and 39 deletions
|
@ -1352,6 +1352,8 @@ impl Parser {
|
|||
let subquery = self.parse_query()?;
|
||||
self.expect_token(&Token::RParen)?;
|
||||
SQLSetExpr::Query(Box::new(subquery))
|
||||
} else if self.parse_keyword("VALUES") {
|
||||
SQLSetExpr::Values(self.parse_values()?)
|
||||
} else {
|
||||
return self.expected("SELECT or a subquery in the query body", self.peek_token());
|
||||
};
|
||||
|
@ -1564,13 +1566,11 @@ impl Parser {
|
|||
let table_name = self.parse_object_name()?;
|
||||
let columns = self.parse_parenthesized_column_list(Optional)?;
|
||||
self.expect_keyword("VALUES")?;
|
||||
self.expect_token(&Token::LParen)?;
|
||||
let values = self.parse_expr_list()?;
|
||||
self.expect_token(&Token::RParen)?;
|
||||
let values = self.parse_values()?;
|
||||
Ok(SQLStatement::SQLInsert {
|
||||
table_name,
|
||||
columns,
|
||||
values: vec![values],
|
||||
values,
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -1688,6 +1688,20 @@ impl Parser {
|
|||
quantity,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn parse_values(&mut self) -> Result<SQLValues, ParserError> {
|
||||
let mut values = vec![];
|
||||
loop {
|
||||
self.expect_token(&Token::LParen)?;
|
||||
values.push(self.parse_expr_list()?);
|
||||
self.expect_token(&Token::RParen)?;
|
||||
match self.peek_token() {
|
||||
Some(Token::Comma) => self.next_token(),
|
||||
_ => break,
|
||||
};
|
||||
}
|
||||
Ok(SQLValues(values))
|
||||
}
|
||||
}
|
||||
|
||||
impl SQLWord {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue