Skip to content

Commit

Permalink
Refactor: split out when matched
Browse files Browse the repository at this point in the history
  • Loading branch information
tobymao committed Oct 13, 2023
1 parent f024ac5 commit d83f242
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions sqlglot/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -5025,7 +5025,17 @@ def _parse_merge(self) -> exp.Merge:
self._match(TokenType.ON)
on = self._parse_conjunction()

return self.expression(
exp.Merge,
this=target,
using=using,
on=on,
expressions=self._parse_when_matched(),
)

def _parse_when_matched(self) -> t.List[exp.When]:
whens = []

while self._match(TokenType.WHEN):
matched = not self._match(TokenType.NOT)
self._match_text_seq("MATCHED")
Expand Down Expand Up @@ -5072,14 +5082,7 @@ def _parse_merge(self) -> exp.Merge:
then=then,
)
)

return self.expression(
exp.Merge,
this=target,
using=using,
on=on,
expressions=whens,
)
return whens

def _parse_show(self) -> t.Optional[exp.Expression]:
parser = self._find_parser(self.SHOW_PARSERS, self.SHOW_TRIE)
Expand Down

0 comments on commit d83f242

Please sign in to comment.