Edit on GitHub

# sqlglot.optimizer.normalize_identifiers

View Source

     1from sqlglot._typing import E
     2from sqlglot.dialects.dialect import Dialect, DialectType
     3
     4
     5def normalize_identifiers(expression: E, dialect: DialectType = None) -> E:
     6    """
     7    Normalize all unquoted identifiers to either lower or upper case, depending
     8    on the dialect. This essentially makes those identifiers case-insensitive.
     9
    10    Note:
    11        Some dialects (e.g. BigQuery) treat identifiers as case-insensitive even
    12        when they're quoted, so in these cases all identifiers are normalized.
    13
    14    Example:
    15        >>> import sqlglot
    16        >>> expression = sqlglot.parse_one('SELECT Bar.A AS A FROM "Foo".Bar')
    17        >>> normalize_identifiers(expression).sql()
    18        'SELECT bar.a AS a FROM "Foo".bar'
    19
    20    Args:
    21        expression: The expression to transform.
    22        dialect: The dialect to use in order to decide how to normalize identifiers.
    23
    24    Returns:
    25        The transformed expression.
    26    """
    27    return expression.transform(Dialect.get_or_raise(dialect).normalize_identifier, copy=False)

def normalize_identifiers( expression: ~E, dialect: Union[str, sqlglot.dialects.dialect.Dialect, Type[sqlglot.dialects.dialect.Dialect], NoneType] = None) -> ~E: View Source

     6def normalize_identifiers(expression: E, dialect: DialectType = None) -> E:
     7    """
     8    Normalize all unquoted identifiers to either lower or upper case, depending
     9    on the dialect. This essentially makes those identifiers case-insensitive.
    10
    11    Note:
    12        Some dialects (e.g. BigQuery) treat identifiers as case-insensitive even
    13        when they're quoted, so in these cases all identifiers are normalized.
    14
    15    Example:
    16        >>> import sqlglot
    17        >>> expression = sqlglot.parse_one('SELECT Bar.A AS A FROM "Foo".Bar')
    18        >>> normalize_identifiers(expression).sql()
    19        'SELECT bar.a AS a FROM "Foo".bar'
    20
    21    Args:
    22        expression: The expression to transform.
    23        dialect: The dialect to use in order to decide how to normalize identifiers.
    24
    25    Returns:
    26        The transformed expression.
    27    """
    28    return expression.transform(Dialect.get_or_raise(dialect).normalize_identifier, copy=False)

Normalize all unquoted identifiers to either lower or upper case, depending on the dialect. This essentially makes those identifiers case-insensitive.

###### Note:

> Some dialects (e.g. BigQuery) treat identifiers as case-insensitive even when they're quoted, so in these cases all identifiers are normalized.

###### Example:

>     >>> import sqlglot
>     >>> expression = sqlglot.parse_one('SELECT Bar.A AS A FROM "Foo".Bar')
>     >>> normalize_identifiers(expression).sql()
>     'SELECT bar.a AS a FROM "Foo".bar'

###### Arguments:

- expression: The expression to transform.
- dialect: The dialect to use in order to decide how to normalize identifiers.

###### Returns:

> The transformed expression.