mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-01-05 21:02:58 +00:00
feat: support REPLACE INTO statement (#5820)
* feat: support replace into * feat: support replace into
This commit is contained in:
@@ -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(),
|
||||
|
||||
@@ -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)]
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user