feat: support REPLACE INTO statement (#5820)

* feat: support replace into

* feat: support replace into
This commit is contained in:
Yingwen
2025-04-03 11:22:43 +08:00
committed by GitHub
parent f797de3497
commit 2acecd3620
4 changed files with 29 additions and 1 deletions

View File

@@ -147,6 +147,8 @@ impl ParserContext<'_> {
Keyword::INSERT => self.parse_insert(),
Keyword::REPLACE => self.parse_replace(),
Keyword::SELECT | Keyword::WITH | Keyword::VALUES => self.parse_query(),
Keyword::ALTER => self.parse_alter(),

View File

@@ -20,7 +20,7 @@ use crate::parser::ParserContext;
use crate::statements::insert::Insert;
use crate::statements::statement::Statement;
/// INSERT statement parser implementation
/// INSERT/REPLACE statement parser implementation
impl ParserContext<'_> {
pub(crate) fn parse_insert(&mut self) -> Result<Statement> {
let _ = self.parser.next_token();
@@ -36,6 +36,24 @@ impl ParserContext<'_> {
.fail(),
}
}
pub(crate) fn parse_replace(&mut self) -> Result<Statement> {
let _ = self.parser.next_token();
let spstatement = self.parser.parse_insert().context(error::SyntaxSnafu)?;
match spstatement {
SpStatement::Insert(mut insert_stmt) => {
insert_stmt.replace_into = true;
Ok(Statement::Insert(Box::new(Insert {
inner: SpStatement::Insert(insert_stmt),
})))
}
unexp => error::UnsupportedSnafu {
keyword: unexp.to_string(),
}
.fail(),
}
}
}
#[cfg(test)]

View File

@@ -9,6 +9,10 @@ INSERT INTO integers VALUES (1), (2), (3), (4), (5);
Affected Rows: 5
REPLACE INTO integers VALUES (6), (7);
Affected Rows: 2
SELECT * FROM integers;
+-------------------------+
@@ -19,6 +23,8 @@ SELECT * FROM integers;
| 1970-01-01T00:00:00.003 |
| 1970-01-01T00:00:00.004 |
| 1970-01-01T00:00:00.005 |
| 1970-01-01T00:00:00.006 |
| 1970-01-01T00:00:00.007 |
+-------------------------+
-- Test insert with long string constant

View File

@@ -5,6 +5,8 @@ CREATE TABLE integers (
INSERT INTO integers VALUES (1), (2), (3), (4), (5);
REPLACE INTO integers VALUES (6), (7);
SELECT * FROM integers;
-- Test insert with long string constant