diff options
Diffstat (limited to 'sqlglot/optimizer/eliminate_subqueries.py')
-rw-r--r-- | sqlglot/optimizer/eliminate_subqueries.py | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/sqlglot/optimizer/eliminate_subqueries.py b/sqlglot/optimizer/eliminate_subqueries.py index 728493d..af42f25 100644 --- a/sqlglot/optimizer/eliminate_subqueries.py +++ b/sqlglot/optimizer/eliminate_subqueries.py @@ -136,8 +136,10 @@ def _eliminate_union(scope, existing_ctes, taken): def _eliminate_derived_table(scope, existing_ctes, taken): - # This ensures we don't drop the "pivot" arg from a pivoted subquery - if scope.parent.pivots: + # This makes sure that we don't: + # - drop the "pivot" arg from a pivoted subquery + # - eliminate a lateral correlated subquery + if scope.parent.pivots or isinstance(scope.parent.expression, exp.Lateral): return None parent = scope.expression.parent |