mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-10-11 14:32:04 +00:00
commit
a594375966
3 changed files with 80 additions and 3 deletions
|
@ -117,6 +117,7 @@ impl Parser {
|
|||
"DROP" => Ok(self.parse_drop()?),
|
||||
"DELETE" => Ok(self.parse_delete()?),
|
||||
"INSERT" => Ok(self.parse_insert()?),
|
||||
"UPDATE" => Ok(self.parse_update()?),
|
||||
"ALTER" => Ok(self.parse_alter()?),
|
||||
"COPY" => Ok(self.parse_copy()?),
|
||||
_ => parser_err!(format!(
|
||||
|
@ -1615,6 +1616,31 @@ impl Parser {
|
|||
})
|
||||
}
|
||||
|
||||
pub fn parse_update(&mut self) -> Result<SQLStatement, ParserError> {
|
||||
let table_name = self.parse_object_name()?;
|
||||
self.expect_keyword("SET")?;
|
||||
let mut assignments = vec![];
|
||||
loop {
|
||||
let id = self.parse_identifier()?;
|
||||
self.expect_token(&Token::Eq)?;
|
||||
let value = self.parse_expr()?;
|
||||
assignments.push(SQLAssignment { id, value });
|
||||
if !self.consume_token(&Token::Comma) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
let selection = if self.parse_keyword("WHERE") {
|
||||
Some(self.parse_expr()?)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
Ok(SQLStatement::SQLUpdate {
|
||||
table_name,
|
||||
assignments,
|
||||
selection,
|
||||
})
|
||||
}
|
||||
|
||||
/// Parse a comma-delimited list of SQL expressions
|
||||
pub fn parse_expr_list(&mut self) -> Result<Vec<ASTNode>, ParserError> {
|
||||
let mut expr_list: Vec<ASTNode> = vec![];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue