diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-15 05:02:18 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-15 05:02:18 +0000 |
commit | 41f1f5740d2140bfd3b2a282ca1087a4b576679a (patch) | |
tree | 0b1eb5ba5c759d08b05d56e50675784b6170f955 /sqlglot/optimizer/unnest_subqueries.py | |
parent | Releasing debian version 23.7.0-1. (diff) | |
download | sqlglot-41f1f5740d2140bfd3b2a282ca1087a4b576679a.tar.xz sqlglot-41f1f5740d2140bfd3b2a282ca1087a4b576679a.zip |
Merging upstream version 23.10.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'sqlglot/optimizer/unnest_subqueries.py')
-rw-r--r-- | sqlglot/optimizer/unnest_subqueries.py | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/sqlglot/optimizer/unnest_subqueries.py b/sqlglot/optimizer/unnest_subqueries.py index b83abe6..be3ab6f 100644 --- a/sqlglot/optimizer/unnest_subqueries.py +++ b/sqlglot/optimizer/unnest_subqueries.py @@ -41,8 +41,6 @@ def unnest(select, parent_select, next_alias_name): return predicate = select.find_ancestor(exp.Condition) - alias = next_alias_name() - if ( not predicate or parent_select is not predicate.parent_select @@ -50,6 +48,10 @@ def unnest(select, parent_select, next_alias_name): ): return + if isinstance(select, exp.Union): + select = exp.select(*select.selects).from_(select.subquery(next_alias_name())) + + alias = next_alias_name() clause = predicate.find_ancestor(exp.Having, exp.Where, exp.Join) # This subquery returns a scalar and can just be converted to a cross join |