Skip to content

fix(exasol): case-insensitive alias matching for LOCAL. prefix #7631

Merged
georgesittas merged 4 commits into
tobymao:mainfrom
exasol:fix-group-by-local
May 13, 2026
Merged

fix(exasol): case-insensitive alias matching for LOCAL. prefix #7631
georgesittas merged 4 commits into
tobymao:mainfrom
exasol:fix-group-by-local

Conversation

@antonireus
Copy link
Copy Markdown
Contributor

_add_local_prefix_for_aliases did case-sensitive string matching when rewriting alias references to LOCAL.<alias> in WHERE/GROUP BY/HAVING. Exasol folds unquoted identifiers to uppercase, so an alias idField and a reference idfield are the same identifier but the lookup missed, producing invalid SQL:

  sqlglot.transpile(                                                                                                                                              
      "SELECT 1 AS idField FROM t GROUP BY idfield",            
      read="mysql", write="exasol",   
  )
  # before: ... GROUP BY idfield        → Exasol error
  # after:  ... GROUP BY LOCAL.idField  → ok                                                                                                                      

Fix: use dialect.normalize_identifier() to compute the comparison key. The exp.Select preprocessing moves into a select_sql override so self.dialect is available.

We went with this approach, because now Exasol supports setting a different normalization strategy, so the function would work consistently when using an extended Exasol dialect using a different normalization strategy.

Tests added to test_local_prefix_for_alias. Verified against a live Exasol instance.

Comment thread sqlglot/generators/exasol.py
Comment thread sqlglot/generators/exasol.py Outdated
@georgesittas georgesittas merged commit 9e37283 into tobymao:main May 13, 2026
8 checks passed
@antonireus antonireus deleted the fix-group-by-local branch May 13, 2026 08:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants