1
1
use crate :: {
2
- parser:: select:: SelectStatementParser , Identifier , InsertStatement , InsertValues , Keyword ,
3
- QualifiedTableName , TokenType , UpsertAction , UpsertClause , UpsertConflictTarget , UpsertUpdate ,
2
+ parser:: select:: SelectStatementParser , ConflictClause , Identifier , InsertStatement ,
3
+ InsertValues , Keyword , QualifiedTableName , TokenType , UpsertAction , UpsertClause ,
4
+ UpsertConflictTarget , UpsertUpdate ,
4
5
} ;
5
6
6
7
use super :: {
@@ -32,6 +33,17 @@ pub trait InsertStatementParser {
32
33
33
34
impl < ' a > InsertStatementParser for Parser < ' a > {
34
35
fn parse_insert_statement ( & mut self ) -> Result < InsertStatement , ParsingError > {
36
+ if self . consume_as_keyword ( Keyword :: Replace ) . is_ok ( ) {
37
+ return Ok ( InsertStatement {
38
+ conflict_clause : ConflictClause :: None ,
39
+ table_name : self . parse_table_name ( ) ?,
40
+ columns : self . parse_insert_columns ( ) ?,
41
+ values : self . parse_insert_values ( ) ?,
42
+ upsert_clause : self . parse_upsert_clauses ( ) ?,
43
+ returning_clause : self . parse_returning_clause ( ) ?,
44
+ } ) ;
45
+ }
46
+
35
47
self . consume_as_keyword ( Keyword :: Insert ) ?;
36
48
37
49
Ok ( InsertStatement {
@@ -45,13 +57,11 @@ impl<'a> InsertStatementParser for Parser<'a> {
45
57
}
46
58
47
59
fn parse_table_name ( & mut self ) -> Result < QualifiedTableName , ParsingError > {
48
- dbg ! ( "parse_table_name" ) ;
49
60
self . consume_as_keyword ( Keyword :: Into ) ?;
50
61
self . parse_qualified_table_name ( )
51
62
}
52
63
53
64
fn parse_insert_columns ( & mut self ) -> Result < Vec < Identifier > , ParsingError > {
54
- dbg ! ( "parse_insert_columns" ) ;
55
65
let mut columns = vec ! [ ] ;
56
66
57
67
if self . consume_as ( TokenType :: LeftParen ) . is_ok ( ) {
@@ -69,7 +79,6 @@ impl<'a> InsertStatementParser for Parser<'a> {
69
79
}
70
80
71
81
fn parse_insert_values ( & mut self ) -> Result < InsertValues , ParsingError > {
72
- dbg ! ( "parse_insert_values" ) ;
73
82
if self . consume_as_keyword ( Keyword :: Values ) . is_ok ( ) {
74
83
let mut values = vec ! [ ] ;
75
84
@@ -131,12 +140,7 @@ impl<'a> InsertStatementParser for Parser<'a> {
131
140
self . consume_as_keyword ( Keyword :: Conflict ) ?;
132
141
133
142
let conflict_target = self . parse_upsert_conflict_target ( ) ?;
134
- dbg ! ( "conflict_target" , & conflict_target) ;
135
-
136
- dbg ! ( "parse_upsert_action" ) ;
137
- dbg ! ( "self.peek_token()" , self . peek_token( ) ?) ;
138
143
let action = self . parse_upsert_action ( ) ?;
139
- dbg ! ( "action" , & action) ;
140
144
141
145
Ok ( UpsertClause {
142
146
conflict_target,
@@ -176,10 +180,6 @@ impl<'a> InsertStatementParser for Parser<'a> {
176
180
}
177
181
178
182
if self . consume_as_keyword ( Keyword :: Update ) . is_ok ( ) {
179
- dbg ! ( "parse_upsert_action update" ) ;
180
- dbg ! ( "self.peek_token()" , self . peek_token( ) ?) ;
181
- // self.consume_as_keyword(Keyword::Set)?;
182
-
183
183
let set_clauses = self . parse_set_clauses ( ) ?;
184
184
185
185
let where_clause = self . parse_where_clause ( ) ?;
@@ -509,4 +509,14 @@ mod tests_insert_statement {
509
509
Statement :: WithCte ( expected_statement) ,
510
510
) ;
511
511
}
512
+
513
+ #[ test]
514
+ fn test_parse_insert_statement_with_replace ( ) {
515
+ let mut expected_statement = insert_statement ( ) ;
516
+ expected_statement. conflict_clause = ConflictClause :: None ;
517
+ run_sunny_day_test (
518
+ "REPLACE INTO table1 DEFAULT VALUES" ,
519
+ Statement :: Insert ( expected_statement) ,
520
+ ) ;
521
+ }
512
522
}
0 commit comments