mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-10-20 02:37:15 +00:00
Support multiple-table DELETE syntax (#855)
This commit is contained in:
parent
5ecf633e31
commit
f72e2ec382
3 changed files with 131 additions and 26 deletions
|
@ -1229,10 +1229,12 @@ pub enum Statement {
|
|||
},
|
||||
/// DELETE
|
||||
Delete {
|
||||
/// Multi tables delete are supported in mysql
|
||||
tables: Vec<ObjectName>,
|
||||
/// FROM
|
||||
table_name: TableFactor,
|
||||
/// USING (Snowflake, Postgres)
|
||||
using: Option<TableFactor>,
|
||||
from: Vec<TableWithJoins>,
|
||||
/// USING (Snowflake, Postgres, MySQL)
|
||||
using: Option<Vec<TableWithJoins>>,
|
||||
/// WHERE
|
||||
selection: Option<Expr>,
|
||||
/// RETURNING
|
||||
|
@ -1982,14 +1984,19 @@ impl fmt::Display for Statement {
|
|||
Ok(())
|
||||
}
|
||||
Statement::Delete {
|
||||
table_name,
|
||||
tables,
|
||||
from,
|
||||
using,
|
||||
selection,
|
||||
returning,
|
||||
} => {
|
||||
write!(f, "DELETE FROM {table_name}")?;
|
||||
write!(f, "DELETE ")?;
|
||||
if !tables.is_empty() {
|
||||
write!(f, "{} ", display_comma_separated(tables))?;
|
||||
}
|
||||
write!(f, "FROM {}", display_comma_separated(from))?;
|
||||
if let Some(using) = using {
|
||||
write!(f, " USING {using}")?;
|
||||
write!(f, " USING {}", display_comma_separated(using))?;
|
||||
}
|
||||
if let Some(selection) = selection {
|
||||
write!(f, " WHERE {selection}")?;
|
||||
|
|
|
@ -4813,10 +4813,17 @@ impl<'a> Parser<'a> {
|
|||
}
|
||||
|
||||
pub fn parse_delete(&mut self) -> Result<Statement, ParserError> {
|
||||
self.expect_keyword(Keyword::FROM)?;
|
||||
let table_name = self.parse_table_factor()?;
|
||||
let tables = if !self.parse_keyword(Keyword::FROM) {
|
||||
let tables = self.parse_comma_separated(Parser::parse_object_name)?;
|
||||
self.expect_keyword(Keyword::FROM)?;
|
||||
tables
|
||||
} else {
|
||||
vec![]
|
||||
};
|
||||
|
||||
let from = self.parse_comma_separated(Parser::parse_table_and_joins)?;
|
||||
let using = if self.parse_keyword(Keyword::USING) {
|
||||
Some(self.parse_table_factor()?)
|
||||
Some(self.parse_comma_separated(Parser::parse_table_and_joins)?)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
@ -4833,7 +4840,8 @@ impl<'a> Parser<'a> {
|
|||
};
|
||||
|
||||
Ok(Statement::Delete {
|
||||
table_name,
|
||||
tables,
|
||||
from,
|
||||
using,
|
||||
selection,
|
||||
returning,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue