Support Mysql REPLACE statement and PRIORITY clause of INSERT (#1072)

This commit is contained in:
Mehmet Emin KARAKAŞ 2023-12-24 15:24:53 +03:00 committed by GitHub
parent 7ea47c71fb
commit c62ecb1100
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 211 additions and 2 deletions

View file

@ -490,6 +490,7 @@ impl<'a> Parser<'a> {
Keyword::FETCH => Ok(self.parse_fetch_statement()?),
Keyword::DELETE => Ok(self.parse_delete()?),
Keyword::INSERT => Ok(self.parse_insert()?),
Keyword::REPLACE => Ok(self.parse_replace()?),
Keyword::UNCACHE => Ok(self.parse_uncache_table()?),
Keyword::UPDATE => Ok(self.parse_update()?),
Keyword::ALTER => Ok(self.parse_alter()?),
@ -7379,6 +7380,20 @@ impl<'a> Parser<'a> {
})
}
/// Parse an REPLACE statement
pub fn parse_replace(&mut self) -> Result<Statement, ParserError> {
if !dialect_of!(self is MySqlDialect | GenericDialect) {
return parser_err!("Unsupported statement REPLACE", self.peek_token().location);
}
let insert = &mut self.parse_insert().unwrap();
if let Statement::Insert { replace_into, .. } = insert {
*replace_into = true;
}
Ok(insert.clone())
}
/// Parse an INSERT statement
pub fn parse_insert(&mut self) -> Result<Statement, ParserError> {
let or = if !dialect_of!(self is SQLiteDialect) {
@ -7399,9 +7414,23 @@ impl<'a> Parser<'a> {
None
};
let priority = if !dialect_of!(self is MySqlDialect | GenericDialect) {
None
} else if self.parse_keyword(Keyword::LOW_PRIORITY) {
Some(MysqlInsertPriority::LowPriority)
} else if self.parse_keyword(Keyword::DELAYED) {
Some(MysqlInsertPriority::Delayed)
} else if self.parse_keyword(Keyword::HIGH_PRIORITY) {
Some(MysqlInsertPriority::HighPriority)
} else {
None
};
let ignore = dialect_of!(self is MySqlDialect | GenericDialect)
&& self.parse_keyword(Keyword::IGNORE);
let replace_into = false;
let action = self.parse_one_of_keywords(&[Keyword::INTO, Keyword::OVERWRITE]);
let into = action == Some(Keyword::INTO);
let overwrite = action == Some(Keyword::OVERWRITE);
@ -7511,6 +7540,8 @@ impl<'a> Parser<'a> {
table,
on,
returning,
replace_into,
priority,
})
}
}