diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2023-10-04 12:14:45 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2023-10-04 12:14:45 +0000 |
commit | a34653eb21369376f0e054dd989311afcb167f5b (patch) | |
tree | 5a0280adce195af0be654f79fd99395fd2932c19 /sqlglot/optimizer/normalize_identifiers.py | |
parent | Releasing debian version 18.7.0-1. (diff) | |
download | sqlglot-a34653eb21369376f0e054dd989311afcb167f5b.tar.xz sqlglot-a34653eb21369376f0e054dd989311afcb167f5b.zip |
Merging upstream version 18.11.2.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | sqlglot/optimizer/normalize_identifiers.py | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/sqlglot/optimizer/normalize_identifiers.py b/sqlglot/optimizer/normalize_identifiers.py index 54cf02b..32f3a92 100644 --- a/sqlglot/optimizer/normalize_identifiers.py +++ b/sqlglot/optimizer/normalize_identifiers.py @@ -22,6 +22,13 @@ def normalize_identifiers(expression, dialect=None): Normalize all unquoted identifiers to either lower or upper case, depending on the dialect. This essentially makes those identifiers case-insensitive. + It's possible to make this a no-op by adding a special comment next to the + identifier of interest: + + SELECT a /* sqlglot.meta case_sensitive */ FROM table + + In this example, the identifier `a` will not be normalized. + Note: Some dialects (e.g. BigQuery) treat identifiers as case-insensitive even when they're quoted, so in these cases all identifiers are normalized. @@ -43,4 +50,13 @@ def normalize_identifiers(expression, dialect=None): """ if isinstance(expression, str): expression = exp.to_identifier(expression) - return expression.transform(Dialect.get_or_raise(dialect).normalize_identifier, copy=False) + + dialect = Dialect.get_or_raise(dialect) + + def _normalize(node: E) -> E: + if not node.meta.get("case_sensitive"): + exp.replace_children(node, _normalize) + node = dialect.normalize_identifier(node) + return node + + return _normalize(expression) |