Skip to content

Commit

Permalink
fix(snowflake): generate LIMIT when OFFSET exists #4575 (#4581)
Browse files Browse the repository at this point in the history
* fix(snowflake): generate LIMIT when OFFSET exists

* PR feedback 1

Co-authored-by: Jo <[email protected]>

* PR feedback 1 (change snowflake test)

---------

Co-authored-by: Jo <[email protected]>
  • Loading branch information
geooo109 and georgesittas authored Jan 9, 2025
1 parent 6d6060b commit d250846
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
7 changes: 7 additions & 0 deletions sqlglot/dialects/snowflake.py
Original file line number Diff line number Diff line change
Expand Up @@ -1224,3 +1224,10 @@ def datesub_sql(self, expression: exp.DateSub) -> str:
self.unsupported("DateSub cannot be transpiled if the subtracted count is unknown")

return date_delta_sql("DATEADD")(self, expression)

def select_sql(self, expression: exp.Select) -> str:
limit = expression.args.get("limit")
offset = expression.args.get("offset")
if offset and not limit:
expression.limit(exp.Null(), copy=False)
return super().select_sql(expression)
8 changes: 8 additions & 0 deletions tests/dialects/test_snowflake.py
Original file line number Diff line number Diff line change
Expand Up @@ -2360,3 +2360,11 @@ def test_window_function_arg(self):
self.assertEqual(ast.sql("snowflake"), query)
self.assertEqual(len(list(ast.find_all(exp.Column))), 1)
self.assertEqual(window.this.sql("snowflake"), "db.schema.FUNC(a)")

def test_offset_without_limit(self):
self.validate_all(
"SELECT 1 ORDER BY 1 LIMIT NULL OFFSET 0",
read={
"trino": "SELECT 1 ORDER BY 1 OFFSET 0",
},
)

0 comments on commit d250846

Please sign in to comment.