Skip to content

Commit

Permalink
Fix: comments above limit
Browse files Browse the repository at this point in the history
  • Loading branch information
tobymao committed Jul 18, 2023
1 parent d6c8722 commit a523c8b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
5 changes: 4 additions & 1 deletion sqlglot/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2766,6 +2766,7 @@ def _parse_limit(
self, this: t.Optional[exp.Expression] = None, top: bool = False
) -> t.Optional[exp.Expression]:
if self._match(TokenType.TOP if top else TokenType.LIMIT):
comments = self._prev_comments
limit_paren = self._match(TokenType.L_PAREN)
expression = self._parse_number() if top else self._parse_term()

Expand All @@ -2775,7 +2776,9 @@ def _parse_limit(
else:
offset = None

limit_exp = self.expression(exp.Limit, this=this, expression=expression, offset=offset)
limit_exp = self.expression(
exp.Limit, this=this, expression=expression, offset=offset, comments=comments
)

if limit_paren:
self._match_r_paren()
Expand Down
7 changes: 5 additions & 2 deletions tests/test_transpile.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,12 @@ def test_comments(self):
-- comment 1
AND bar
-- comment 2
AND bla;
AND bla
-- comment 3
LIMIT 10
;
""",
"SELECT a FROM b WHERE foo AND /* comment 1 */ bar AND /* comment 2 */ bla",
"SELECT a FROM b WHERE foo AND /* comment 1 */ bar AND /* comment 2 */ bla LIMIT 10 /* comment 3 */",
)
self.validate(
"""
Expand Down

0 comments on commit a523c8b

Please sign in to comment.