diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2023-03-19 10:22:09 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2023-03-19 10:22:09 +0000 |
commit | 66af5c6fc22f6f11e9ea807b274e011a6f64efb7 (patch) | |
tree | 08ceed3b311b7b343935c1e55941b9d15e6f56d8 /sqlglot/optimizer/scope.py | |
parent | Releasing debian version 11.3.6-1. (diff) | |
download | sqlglot-66af5c6fc22f6f11e9ea807b274e011a6f64efb7.tar.xz sqlglot-66af5c6fc22f6f11e9ea807b274e011a6f64efb7.zip |
Merging upstream version 11.4.1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'sqlglot/optimizer/scope.py')
-rw-r--r-- | sqlglot/optimizer/scope.py | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/sqlglot/optimizer/scope.py b/sqlglot/optimizer/scope.py index 335ff3e..9c0768c 100644 --- a/sqlglot/optimizer/scope.py +++ b/sqlglot/optimizer/scope.py @@ -4,6 +4,7 @@ from enum import Enum, auto from sqlglot import exp from sqlglot.errors import OptimizeError +from sqlglot.helper import find_new_name class ScopeType(Enum): @@ -293,6 +294,8 @@ class Scope: result = {} for name, node in referenced_names: + if name in result: + raise OptimizeError(f"Alias already used: {name}") if name in self.sources: result[name] = (node, self.sources[name]) @@ -594,6 +597,8 @@ def _traverse_tables(scope): if table_name in scope.sources: # This is a reference to a parent source (e.g. a CTE), not an actual table. sources[source_name] = scope.sources[table_name] + elif source_name in sources: + sources[find_new_name(sources, table_name)] = expression else: sources[source_name] = expression continue |