Merge pull request #91 from benesch/from-values

Improve VALUES-related syntax parsing
This commit is contained in:
Nikhil Benesch 2019-06-03 11:44:52 -04:00 committed by GitHub
commit b8ba188191
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 95 additions and 45 deletions

View file

@ -1361,6 +1361,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());
};
@ -1572,14 +1574,11 @@ impl Parser {
self.expect_keyword("INTO")?;
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 source = Box::new(self.parse_query()?);
Ok(SQLStatement::SQLInsert {
table_name,
columns,
values: vec![values],
source,
})
}
@ -1697,6 +1696,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 {