Skip to content

Commit

Permalink
Fix!: store expressions in Limit.expression when using builder (#2249)
Browse files Browse the repository at this point in the history
* Fix!: store expressions in Limit.expression when using builder

* Rename wrap_arg to into_arg
  • Loading branch information
georgesittas authored Sep 17, 2023
1 parent ff19f4c commit 8ebbfe2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
4 changes: 3 additions & 1 deletion sqlglot/expressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2861,6 +2861,7 @@ def limit(
prefix="LIMIT",
dialect=dialect,
copy=copy,
into_arg="expression",
**opts,
)

Expand Down Expand Up @@ -5130,10 +5131,11 @@ def _apply_builder(
prefix=None,
into=None,
dialect=None,
into_arg="this",
**opts,
):
if _is_wrong_expression(expression, into):
expression = into(this=expression)
expression = into(**{into_arg: expression})
instance = maybe_copy(instance, copy)
expression = maybe_parse(
sql_or_expression=expression,
Expand Down
5 changes: 5 additions & 0 deletions tests/dialects/test_duckdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ class TestDuckDB(Validator):
dialect = "duckdb"

def test_duckdb(self):
self.assertEqual(
parse_one("select * from t limit (select 5)").sql(dialect="duckdb"),
exp.select("*").from_("t").limit(exp.select("5").subquery()).sql(dialect="duckdb"),
)

for join_type in ("SEMI", "ANTI"):
exists = "EXISTS" if join_type == "SEMI" else "NOT EXISTS"

Expand Down

0 comments on commit 8ebbfe2

Please sign in to comment.