Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sqlglot-integration-tests
7 changes: 4 additions & 3 deletions sqlglot/optimizer/canonicalize_internal_names.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,11 @@ def _canon(ident: exp.Identifier, name: str) -> None:

scope_outputs[id(scope_expr)] = output_map

# Unqualified alias references (ORDER BY a, HAVING a > 5, ...)
# Unqualified alias references (ORDER BY a, HAVING a > 5, ...).
for col in find_all_in_scope(scope_expr, exp.Column):
if not col.table and col.name in output_map:
_canon(col.this, output_map[col.name])
# Only rewrite when the alias is actually being renamed
if not col.table and (canon := output_map.get(col.name)) and canon != col.name:
_canon(col.this, canon)

# UBN matches branches by original alias. When both branches are internal
# and aliased to distinct _cN, matching originals land on different slots
Expand Down
Loading