summaryrefslogtreecommitdiffstats
path: root/sqlglot/optimizer/scope.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-15 05:02:18 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-15 05:02:18 +0000
commit41f1f5740d2140bfd3b2a282ca1087a4b576679a (patch)
tree0b1eb5ba5c759d08b05d56e50675784b6170f955 /sqlglot/optimizer/scope.py
parentReleasing debian version 23.7.0-1. (diff)
downloadsqlglot-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/scope.py')
-rw-r--r--sqlglot/optimizer/scope.py12
1 files changed, 3 insertions, 9 deletions
diff --git a/sqlglot/optimizer/scope.py b/sqlglot/optimizer/scope.py
index 073ced2..c589e24 100644
--- a/sqlglot/optimizer/scope.py
+++ b/sqlglot/optimizer/scope.py
@@ -600,7 +600,7 @@ def _traverse_ctes(scope):
sources = {}
for cte in scope.ctes:
- recursive_scope = None
+ cte_name = cte.alias
# if the scope is a recursive cte, it must be in the form of base_case UNION recursive.
# thus the recursive scope is the first section of the union.
@@ -609,7 +609,7 @@ def _traverse_ctes(scope):
union = cte.this
if isinstance(union, exp.Union):
- recursive_scope = scope.branch(union.this, scope_type=ScopeType.CTE)
+ sources[cte_name] = scope.branch(union.this, scope_type=ScopeType.CTE)
child_scope = None
@@ -623,15 +623,9 @@ def _traverse_ctes(scope):
):
yield child_scope
- alias = cte.alias
- sources[alias] = child_scope
-
- if recursive_scope:
- child_scope.add_source(alias, recursive_scope)
- child_scope.cte_sources[alias] = recursive_scope
-
# append the final child_scope yielded
if child_scope:
+ sources[cte_name] = child_scope
scope.cte_scopes.append(child_scope)
scope.sources.update(sources)