@@ -17229,20 +17229,30 @@ impl<'a> Parser<'a> {
1722917229
1723017230 self.expect_keyword_is(Keyword::THEN)?;
1723117231
17232+ macro_rules! not_allowed {
17233+ ($action:literal, $not_allowed_in_clauses:pat) => {
17234+ if matches!(clause_kind, $not_allowed_in_clauses) {
17235+ return parser_err!(
17236+ format_args!(
17237+ concat!($action, " is not allowed in a {} merge clause"),
17238+ clause_kind
17239+ ),
17240+ self.get_current_token().span.start
17241+ );
17242+ }
17243+ };
17244+ }
1723217245 let merge_clause = match self.parse_one_of_keywords(&[
1723317246 Keyword::UPDATE,
1723417247 Keyword::INSERT,
1723517248 Keyword::DELETE,
1723617249 ]) {
1723717250 Some(Keyword::UPDATE) => {
17238- if matches !(
17239- clause_kind ,
17251+ not_allowed !(
17252+ "UPDATE" ,
1724017253 MergeClauseKind::NotMatched | MergeClauseKind::NotMatchedByTarget
17241- ) {
17242- return Err(ParserError::ParserError(format!(
17243- "UPDATE is not allowed in a {clause_kind} merge clause"
17244- )));
17245- }
17254+ );
17255+
1724617256 let update_token = self.get_current_token().clone();
1724717257 self.expect_keyword_is(Keyword::SET)?;
1724817258 MergeAction::Update {
@@ -17251,28 +17261,22 @@ impl<'a> Parser<'a> {
1725117261 }
1725217262 }
1725317263 Some(Keyword::DELETE) => {
17254- if matches !(
17255- clause_kind ,
17264+ not_allowed !(
17265+ "DELETE" ,
1725617266 MergeClauseKind::NotMatched | MergeClauseKind::NotMatchedByTarget
17257- ) {
17258- return Err(ParserError::ParserError(format!(
17259- "DELETE is not allowed in a {clause_kind} merge clause"
17260- )));
17261- }
17267+ );
17268+
1726217269 let delete_token = self.get_current_token().clone();
1726317270 MergeAction::Delete {
1726417271 delete_token: delete_token.into(),
1726517272 }
1726617273 }
1726717274 Some(Keyword::INSERT) => {
17268- if !matches!(
17269- clause_kind,
17270- MergeClauseKind::NotMatched | MergeClauseKind::NotMatchedByTarget
17271- ) {
17272- return Err(ParserError::ParserError(format!(
17273- "INSERT is not allowed in a {clause_kind} merge clause"
17274- )));
17275- }
17275+ not_allowed!(
17276+ "INSERT",
17277+ MergeClauseKind::Matched | MergeClauseKind::NotMatchedBySource
17278+ );
17279+
1727617280 let insert_token = self.get_current_token().clone();
1727717281 let is_mysql = dialect_of!(self is MySqlDialect);
1727817282
@@ -17295,9 +17299,10 @@ impl<'a> Parser<'a> {
1729517299 })
1729617300 }
1729717301 _ => {
17298- return Err(ParserError::ParserError(
17299- "expected UPDATE, DELETE or INSERT in merge clause".to_string(),
17300- ));
17302+ return parser_err!(
17303+ "expected UPDATE, DELETE or INSERT in merge clause",
17304+ self.peek_token_ref().span.start
17305+ );
1730117306 }
1730217307 };
1730317308 clauses.push(MergeClause {
0 commit comments