Skip to content

Commit

Permalink
Fix(planner): ensure aggregate variable is bound
Browse files Browse the repository at this point in the history
  • Loading branch information
georgesittas committed Dec 17, 2024
1 parent 946cd42 commit 8ca0696
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion sqlglot/planner.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,11 +201,13 @@ def set_ops_and_aggs(step):

aggregate.add_dependency(step)
step = aggregate
else:
aggregate = None

order = expression.args.get("order")

if order:
if isinstance(step, Aggregate):
if aggregate and isinstance(step, Aggregate):
for i, ordered in enumerate(order.expressions):
if extract_agg_operands(exp.alias_(ordered.this, f"_o_{i}", quoted=True)):
ordered.this.replace(exp.column(f"_o_{i}", step.name, quoted=True))
Expand Down

0 comments on commit 8ca0696

Please sign in to comment.