mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-08-22 15:04:04 +00:00
feat: support sqlite insert or statement (#281)
This commit is contained in:
parent
07342d5853
commit
add8991144
4 changed files with 105 additions and 9 deletions
|
@ -163,6 +163,10 @@ impl<'a> Parser<'a> {
|
|||
Keyword::DEALLOCATE => Ok(self.parse_deallocate()?),
|
||||
Keyword::EXECUTE => Ok(self.parse_execute()?),
|
||||
Keyword::PREPARE => Ok(self.parse_prepare()?),
|
||||
Keyword::REPLACE if dialect_of!(self is SQLiteDialect ) => {
|
||||
self.prev_token();
|
||||
Ok(self.parse_insert()?)
|
||||
}
|
||||
_ => self.expected("an SQL statement", Token::Word(w)),
|
||||
},
|
||||
Token::LParen => {
|
||||
|
@ -2719,6 +2723,23 @@ impl<'a> Parser<'a> {
|
|||
|
||||
/// Parse an INSERT statement
|
||||
pub fn parse_insert(&mut self) -> Result<Statement, ParserError> {
|
||||
let or = if !dialect_of!(self is SQLiteDialect) {
|
||||
None
|
||||
} else if self.parse_keywords(&[Keyword::OR, Keyword::REPLACE]) {
|
||||
Some(SqliteOnConflict::Replace)
|
||||
} else if self.parse_keywords(&[Keyword::OR, Keyword::ROLLBACK]) {
|
||||
Some(SqliteOnConflict::Rollback)
|
||||
} else if self.parse_keywords(&[Keyword::OR, Keyword::ABORT]) {
|
||||
Some(SqliteOnConflict::Abort)
|
||||
} else if self.parse_keywords(&[Keyword::OR, Keyword::FAIL]) {
|
||||
Some(SqliteOnConflict::Fail)
|
||||
} else if self.parse_keywords(&[Keyword::OR, Keyword::IGNORE]) {
|
||||
Some(SqliteOnConflict::Ignore)
|
||||
} else if self.parse_keyword(Keyword::REPLACE) {
|
||||
Some(SqliteOnConflict::Replace)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let action = self.expect_one_of_keywords(&[Keyword::INTO, Keyword::OVERWRITE])?;
|
||||
let overwrite = action == Keyword::OVERWRITE;
|
||||
let local = self.parse_keyword(Keyword::LOCAL);
|
||||
|
@ -2758,6 +2779,7 @@ impl<'a> Parser<'a> {
|
|||
|
||||
let source = Box::new(self.parse_query()?);
|
||||
Ok(Statement::Insert {
|
||||
or,
|
||||
table_name,
|
||||
overwrite,
|
||||
partitioned,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue