Edit on GitHub

# sqlglot.dialects.teradata

View Source

      1from __future__ import annotations
      2
      3import typing as t
      4
      5from sqlglot import exp, generator, parser, tokens, transforms
      6from sqlglot.dialects.dialect import Dialect, max_or_greatest, min_or_least
      7from sqlglot.tokens import TokenType
      8
      9
     10class Teradata(Dialect):
     11    SUPPORTS_SEMI_ANTI_JOIN = False
     12
     13    TIME_MAPPING = {
     14        "Y": "%Y",
     15        "YYYY": "%Y",
     16        "YY": "%y",
     17        "MMMM": "%B",
     18        "MMM": "%b",
     19        "DD": "%d",
     20        "D": "%-d",
     21        "HH": "%H",
     22        "H": "%-H",
     23        "MM": "%M",
     24        "M": "%-M",
     25        "SS": "%S",
     26        "S": "%-S",
     27        "SSSSSS": "%f",
     28        "E": "%a",
     29        "EE": "%a",
     30        "EEE": "%a",
     31        "EEEE": "%A",
     32    }
     33
     34    class Tokenizer(tokens.Tokenizer):
     35        # https://docs.teradata.com/r/Teradata-Database-SQL-Functions-Operators-Expressions-and-Predicates/March-2017/Comparison-Operators-and-Functions/Comparison-Operators/ANSI-Compliance
     36        KEYWORDS = {
     37            **tokens.Tokenizer.KEYWORDS,
     38            "^=": TokenType.NEQ,
     39            "BYTEINT": TokenType.SMALLINT,
     40            "COLLECT": TokenType.COMMAND,
     41            "GE": TokenType.GTE,
     42            "GT": TokenType.GT,
     43            "HELP": TokenType.COMMAND,
     44            "INS": TokenType.INSERT,
     45            "LE": TokenType.LTE,
     46            "LT": TokenType.LT,
     47            "MOD": TokenType.MOD,
     48            "NE": TokenType.NEQ,
     49            "NOT=": TokenType.NEQ,
     50            "SAMPLE": TokenType.TABLE_SAMPLE,
     51            "SEL": TokenType.SELECT,
     52            "ST_GEOMETRY": TokenType.GEOMETRY,
     53            "TOP": TokenType.TOP,
     54        }
     55
     56        # Teradata does not support % as a modulo operator
     57        SINGLE_TOKENS = {**tokens.Tokenizer.SINGLE_TOKENS}
     58        SINGLE_TOKENS.pop("%")
     59
     60    class Parser(parser.Parser):
     61        TABLESAMPLE_CSV = True
     62
     63        CHARSET_TRANSLATORS = {
     64            "GRAPHIC_TO_KANJISJIS",
     65            "GRAPHIC_TO_LATIN",
     66            "GRAPHIC_TO_UNICODE",
     67            "GRAPHIC_TO_UNICODE_PadSpace",
     68            "KANJI1_KanjiEBCDIC_TO_UNICODE",
     69            "KANJI1_KanjiEUC_TO_UNICODE",
     70            "KANJI1_KANJISJIS_TO_UNICODE",
     71            "KANJI1_SBC_TO_UNICODE",
     72            "KANJISJIS_TO_GRAPHIC",
     73            "KANJISJIS_TO_LATIN",
     74            "KANJISJIS_TO_UNICODE",
     75            "LATIN_TO_GRAPHIC",
     76            "LATIN_TO_KANJISJIS",
     77            "LATIN_TO_UNICODE",
     78            "LOCALE_TO_UNICODE",
     79            "UNICODE_TO_GRAPHIC",
     80            "UNICODE_TO_GRAPHIC_PadGraphic",
     81            "UNICODE_TO_GRAPHIC_VarGraphic",
     82            "UNICODE_TO_KANJI1_KanjiEBCDIC",
     83            "UNICODE_TO_KANJI1_KanjiEUC",
     84            "UNICODE_TO_KANJI1_KANJISJIS",
     85            "UNICODE_TO_KANJI1_SBC",
     86            "UNICODE_TO_KANJISJIS",
     87            "UNICODE_TO_LATIN",
     88            "UNICODE_TO_LOCALE",
     89            "UNICODE_TO_UNICODE_FoldSpace",
     90            "UNICODE_TO_UNICODE_Fullwidth",
     91            "UNICODE_TO_UNICODE_Halfwidth",
     92            "UNICODE_TO_UNICODE_NFC",
     93            "UNICODE_TO_UNICODE_NFD",
     94            "UNICODE_TO_UNICODE_NFKC",
     95            "UNICODE_TO_UNICODE_NFKD",
     96        }
     97
     98        FUNC_TOKENS = {*parser.Parser.FUNC_TOKENS}
     99        FUNC_TOKENS.remove(TokenType.REPLACE)
    100
    101        STATEMENT_PARSERS = {
    102            **parser.Parser.STATEMENT_PARSERS,
    103            TokenType.DATABASE: lambda self: self.expression(
    104                exp.Use, this=self._parse_table(schema=False)
    105            ),
    106            TokenType.REPLACE: lambda self: self._parse_create(),
    107        }
    108
    109        FUNCTION_PARSERS = {
    110            **parser.Parser.FUNCTION_PARSERS,
    111            "RANGE_N": lambda self: self._parse_rangen(),
    112            "TRANSLATE": lambda self: self._parse_translate(self.STRICT_CAST),
    113        }
    114
    115        def _parse_translate(self, strict: bool) -> exp.Expression:
    116            this = self._parse_conjunction()
    117
    118            if not self._match(TokenType.USING):
    119                self.raise_error("Expected USING in TRANSLATE")
    120
    121            if self._match_texts(self.CHARSET_TRANSLATORS):
    122                charset_split = self._prev.text.split("_TO_")
    123                to = self.expression(exp.CharacterSet, this=charset_split[1])
    124            else:
    125                self.raise_error("Expected a character set translator after USING in TRANSLATE")
    126
    127            return self.expression(exp.Cast if strict else exp.TryCast, this=this, to=to)
    128
    129        # FROM before SET in Teradata UPDATE syntax
    130        # https://docs.teradata.com/r/Enterprise_IntelliFlex_VMware/Teradata-VantageTM-SQL-Data-Manipulation-Language-17.20/Statement-Syntax/UPDATE/UPDATE-Syntax-Basic-Form-FROM-Clause
    131        def _parse_update(self) -> exp.Update:
    132            return self.expression(
    133                exp.Update,
    134                **{  # type: ignore
    135                    "this": self._parse_table(alias_tokens=self.UPDATE_ALIAS_TOKENS),
    136                    "from": self._parse_from(joins=True),
    137                    "expressions": self._match(TokenType.SET)
    138                    and self._parse_csv(self._parse_equality),
    139                    "where": self._parse_where(),
    140                },
    141            )
    142
    143        def _parse_rangen(self):
    144            this = self._parse_id_var()
    145            self._match(TokenType.BETWEEN)
    146
    147            expressions = self._parse_csv(self._parse_conjunction)
    148            each = self._match_text_seq("EACH") and self._parse_conjunction()
    149
    150            return self.expression(exp.RangeN, this=this, expressions=expressions, each=each)
    151
    152    class Generator(generator.Generator):
    153        JOIN_HINTS = False
    154        TABLE_HINTS = False
    155        QUERY_HINTS = False
    156
    157        TYPE_MAPPING = {
    158            **generator.Generator.TYPE_MAPPING,
    159            exp.DataType.Type.GEOMETRY: "ST_GEOMETRY",
    160        }
    161
    162        PROPERTIES_LOCATION = {
    163            **generator.Generator.PROPERTIES_LOCATION,
    164            exp.OnCommitProperty: exp.Properties.Location.POST_INDEX,
    165            exp.PartitionedByProperty: exp.Properties.Location.POST_EXPRESSION,
    166            exp.StabilityProperty: exp.Properties.Location.POST_CREATE,
    167        }
    168
    169        TRANSFORMS = {
    170            **generator.Generator.TRANSFORMS,
    171            exp.Max: max_or_greatest,
    172            exp.Min: min_or_least,
    173            exp.Select: transforms.preprocess(
    174                [transforms.eliminate_distinct_on, transforms.eliminate_semi_and_anti_joins]
    175            ),
    176            exp.StrToDate: lambda self, e: f"CAST({self.sql(e, 'this')} AS DATE FORMAT {self.format_time(e)})",
    177            exp.ToChar: lambda self, e: self.function_fallback_sql(e),
    178            exp.Use: lambda self, e: f"DATABASE {self.sql(e, 'this')}",
    179        }
    180
    181        def tablesample_sql(
    182            self, expression: exp.TableSample, seed_prefix: str = "SEED", sep=" AS "
    183        ) -> str:
    184            return f"{self.sql(expression, 'this')} SAMPLE {self.expressions(expression)}"
    185
    186        def partitionedbyproperty_sql(self, expression: exp.PartitionedByProperty) -> str:
    187            return f"PARTITION BY {self.sql(expression, 'this')}"
    188
    189        # FROM before SET in Teradata UPDATE syntax
    190        # https://docs.teradata.com/r/Enterprise_IntelliFlex_VMware/Teradata-VantageTM-SQL-Data-Manipulation-Language-17.20/Statement-Syntax/UPDATE/UPDATE-Syntax-Basic-Form-FROM-Clause
    191        def update_sql(self, expression: exp.Update) -> str:
    192            this = self.sql(expression, "this")
    193            from_sql = self.sql(expression, "from")
    194            set_sql = self.expressions(expression, flat=True)
    195            where_sql = self.sql(expression, "where")
    196            sql = f"UPDATE {this}{from_sql} SET {set_sql}{where_sql}"
    197            return self.prepend_ctes(expression, sql)
    198
    199        def mod_sql(self, expression: exp.Mod) -> str:
    200            return self.binary(expression, "MOD")
    201
    202        def datatype_sql(self, expression: exp.DataType) -> str:
    203            type_sql = super().datatype_sql(expression)
    204            prefix_sql = expression.args.get("prefix")
    205            return f"SYSUDTLIB.{type_sql}" if prefix_sql else type_sql
    206
    207        def rangen_sql(self, expression: exp.RangeN) -> str:
    208            this = self.sql(expression, "this")
    209            expressions_sql = self.expressions(expression)
    210            each_sql = self.sql(expression, "each")
    211            each_sql = f" EACH {each_sql}" if each_sql else ""
    212
    213            return f"RANGE_N({this} BETWEEN {expressions_sql}{each_sql})"
    214
    215        def createable_sql(self, expression: exp.Create, locations: t.DefaultDict) -> str:
    216            kind = self.sql(expression, "kind").upper()
    217            if kind == "TABLE" and locations.get(exp.Properties.Location.POST_NAME):
    218                this_name = self.sql(expression.this, "this")
    219                this_properties = self.properties(
    220                    exp.Properties(expressions=locations[exp.Properties.Location.POST_NAME]),
    221                    wrapped=False,
    222                    prefix=",",
    223                )
    224                this_schema = self.schema_columns_sql(expression.this)
    225                return f"{this_name}{this_properties}{self.sep()}{this_schema}"
    226
    227            return super().createable_sql(expression, locations)

class Teradata(sqlglot.dialects.dialect.Dialect): View Source

     11class Teradata(Dialect):
     12    SUPPORTS_SEMI_ANTI_JOIN = False
     13
     14    TIME_MAPPING = {
     15        "Y": "%Y",
     16        "YYYY": "%Y",
     17        "YY": "%y",
     18        "MMMM": "%B",
     19        "MMM": "%b",
     20        "DD": "%d",
     21        "D": "%-d",
     22        "HH": "%H",
     23        "H": "%-H",
     24        "MM": "%M",
     25        "M": "%-M",
     26        "SS": "%S",
     27        "S": "%-S",
     28        "SSSSSS": "%f",
     29        "E": "%a",
     30        "EE": "%a",
     31        "EEE": "%a",
     32        "EEEE": "%A",
     33    }
     34
     35    class Tokenizer(tokens.Tokenizer):
     36        # https://docs.teradata.com/r/Teradata-Database-SQL-Functions-Operators-Expressions-and-Predicates/March-2017/Comparison-Operators-and-Functions/Comparison-Operators/ANSI-Compliance
     37        KEYWORDS = {
     38            **tokens.Tokenizer.KEYWORDS,
     39            "^=": TokenType.NEQ,
     40            "BYTEINT": TokenType.SMALLINT,
     41            "COLLECT": TokenType.COMMAND,
     42            "GE": TokenType.GTE,
     43            "GT": TokenType.GT,
     44            "HELP": TokenType.COMMAND,
     45            "INS": TokenType.INSERT,
     46            "LE": TokenType.LTE,
     47            "LT": TokenType.LT,
     48            "MOD": TokenType.MOD,
     49            "NE": TokenType.NEQ,
     50            "NOT=": TokenType.NEQ,
     51            "SAMPLE": TokenType.TABLE_SAMPLE,
     52            "SEL": TokenType.SELECT,
     53            "ST_GEOMETRY": TokenType.GEOMETRY,
     54            "TOP": TokenType.TOP,
     55        }
     56
     57        # Teradata does not support % as a modulo operator
     58        SINGLE_TOKENS = {**tokens.Tokenizer.SINGLE_TOKENS}
     59        SINGLE_TOKENS.pop("%")
     60
     61    class Parser(parser.Parser):
     62        TABLESAMPLE_CSV = True
     63
     64        CHARSET_TRANSLATORS = {
     65            "GRAPHIC_TO_KANJISJIS",
     66            "GRAPHIC_TO_LATIN",
     67            "GRAPHIC_TO_UNICODE",
     68            "GRAPHIC_TO_UNICODE_PadSpace",
     69            "KANJI1_KanjiEBCDIC_TO_UNICODE",
     70            "KANJI1_KanjiEUC_TO_UNICODE",
     71            "KANJI1_KANJISJIS_TO_UNICODE",
     72            "KANJI1_SBC_TO_UNICODE",
     73            "KANJISJIS_TO_GRAPHIC",
     74            "KANJISJIS_TO_LATIN",
     75            "KANJISJIS_TO_UNICODE",
     76            "LATIN_TO_GRAPHIC",
     77            "LATIN_TO_KANJISJIS",
     78            "LATIN_TO_UNICODE",
     79            "LOCALE_TO_UNICODE",
     80            "UNICODE_TO_GRAPHIC",
     81            "UNICODE_TO_GRAPHIC_PadGraphic",
     82            "UNICODE_TO_GRAPHIC_VarGraphic",
     83            "UNICODE_TO_KANJI1_KanjiEBCDIC",
     84            "UNICODE_TO_KANJI1_KanjiEUC",
     85            "UNICODE_TO_KANJI1_KANJISJIS",
     86            "UNICODE_TO_KANJI1_SBC",
     87            "UNICODE_TO_KANJISJIS",
     88            "UNICODE_TO_LATIN",
     89            "UNICODE_TO_LOCALE",
     90            "UNICODE_TO_UNICODE_FoldSpace",
     91            "UNICODE_TO_UNICODE_Fullwidth",
     92            "UNICODE_TO_UNICODE_Halfwidth",
     93            "UNICODE_TO_UNICODE_NFC",
     94            "UNICODE_TO_UNICODE_NFD",
     95            "UNICODE_TO_UNICODE_NFKC",
     96            "UNICODE_TO_UNICODE_NFKD",
     97        }
     98
     99        FUNC_TOKENS = {*parser.Parser.FUNC_TOKENS}
    100        FUNC_TOKENS.remove(TokenType.REPLACE)
    101
    102        STATEMENT_PARSERS = {
    103            **parser.Parser.STATEMENT_PARSERS,
    104            TokenType.DATABASE: lambda self: self.expression(
    105                exp.Use, this=self._parse_table(schema=False)
    106            ),
    107            TokenType.REPLACE: lambda self: self._parse_create(),
    108        }
    109
    110        FUNCTION_PARSERS = {
    111            **parser.Parser.FUNCTION_PARSERS,
    112            "RANGE_N": lambda self: self._parse_rangen(),
    113            "TRANSLATE": lambda self: self._parse_translate(self.STRICT_CAST),
    114        }
    115
    116        def _parse_translate(self, strict: bool) -> exp.Expression:
    117            this = self._parse_conjunction()
    118
    119            if not self._match(TokenType.USING):
    120                self.raise_error("Expected USING in TRANSLATE")
    121
    122            if self._match_texts(self.CHARSET_TRANSLATORS):
    123                charset_split = self._prev.text.split("_TO_")
    124                to = self.expression(exp.CharacterSet, this=charset_split[1])
    125            else:
    126                self.raise_error("Expected a character set translator after USING in TRANSLATE")
    127
    128            return self.expression(exp.Cast if strict else exp.TryCast, this=this, to=to)
    129
    130        # FROM before SET in Teradata UPDATE syntax
    131        # https://docs.teradata.com/r/Enterprise_IntelliFlex_VMware/Teradata-VantageTM-SQL-Data-Manipulation-Language-17.20/Statement-Syntax/UPDATE/UPDATE-Syntax-Basic-Form-FROM-Clause
    132        def _parse_update(self) -> exp.Update:
    133            return self.expression(
    134                exp.Update,
    135                **{  # type: ignore
    136                    "this": self._parse_table(alias_tokens=self.UPDATE_ALIAS_TOKENS),
    137                    "from": self._parse_from(joins=True),
    138                    "expressions": self._match(TokenType.SET)
    139                    and self._parse_csv(self._parse_equality),
    140                    "where": self._parse_where(),
    141                },
    142            )
    143
    144        def _parse_rangen(self):
    145            this = self._parse_id_var()
    146            self._match(TokenType.BETWEEN)
    147
    148            expressions = self._parse_csv(self._parse_conjunction)
    149            each = self._match_text_seq("EACH") and self._parse_conjunction()
    150
    151            return self.expression(exp.RangeN, this=this, expressions=expressions, each=each)
    152
    153    class Generator(generator.Generator):
    154        JOIN_HINTS = False
    155        TABLE_HINTS = False
    156        QUERY_HINTS = False
    157
    158        TYPE_MAPPING = {
    159            **generator.Generator.TYPE_MAPPING,
    160            exp.DataType.Type.GEOMETRY: "ST_GEOMETRY",
    161        }
    162
    163        PROPERTIES_LOCATION = {
    164            **generator.Generator.PROPERTIES_LOCATION,
    165            exp.OnCommitProperty: exp.Properties.Location.POST_INDEX,
    166            exp.PartitionedByProperty: exp.Properties.Location.POST_EXPRESSION,
    167            exp.StabilityProperty: exp.Properties.Location.POST_CREATE,
    168        }
    169
    170        TRANSFORMS = {
    171            **generator.Generator.TRANSFORMS,
    172            exp.Max: max_or_greatest,
    173            exp.Min: min_or_least,
    174            exp.Select: transforms.preprocess(
    175                [transforms.eliminate_distinct_on, transforms.eliminate_semi_and_anti_joins]
    176            ),
    177            exp.StrToDate: lambda self, e: f"CAST({self.sql(e, 'this')} AS DATE FORMAT {self.format_time(e)})",
    178            exp.ToChar: lambda self, e: self.function_fallback_sql(e),
    179            exp.Use: lambda self, e: f"DATABASE {self.sql(e, 'this')}",
    180        }
    181
    182        def tablesample_sql(
    183            self, expression: exp.TableSample, seed_prefix: str = "SEED", sep=" AS "
    184        ) -> str:
    185            return f"{self.sql(expression, 'this')} SAMPLE {self.expressions(expression)}"
    186
    187        def partitionedbyproperty_sql(self, expression: exp.PartitionedByProperty) -> str:
    188            return f"PARTITION BY {self.sql(expression, 'this')}"
    189
    190        # FROM before SET in Teradata UPDATE syntax
    191        # https://docs.teradata.com/r/Enterprise_IntelliFlex_VMware/Teradata-VantageTM-SQL-Data-Manipulation-Language-17.20/Statement-Syntax/UPDATE/UPDATE-Syntax-Basic-Form-FROM-Clause
    192        def update_sql(self, expression: exp.Update) -> str:
    193            this = self.sql(expression, "this")
    194            from_sql = self.sql(expression, "from")
    195            set_sql = self.expressions(expression, flat=True)
    196            where_sql = self.sql(expression, "where")
    197            sql = f"UPDATE {this}{from_sql} SET {set_sql}{where_sql}"
    198            return self.prepend_ctes(expression, sql)
    199
    200        def mod_sql(self, expression: exp.Mod) -> str:
    201            return self.binary(expression, "MOD")
    202
    203        def datatype_sql(self, expression: exp.DataType) -> str:
    204            type_sql = super().datatype_sql(expression)
    205            prefix_sql = expression.args.get("prefix")
    206            return f"SYSUDTLIB.{type_sql}" if prefix_sql else type_sql
    207
    208        def rangen_sql(self, expression: exp.RangeN) -> str:
    209            this = self.sql(expression, "this")
    210            expressions_sql = self.expressions(expression)
    211            each_sql = self.sql(expression, "each")
    212            each_sql = f" EACH {each_sql}" if each_sql else ""
    213
    214            return f"RANGE_N({this} BETWEEN {expressions_sql}{each_sql})"
    215
    216        def createable_sql(self, expression: exp.Create, locations: t.DefaultDict) -> str:
    217            kind = self.sql(expression, "kind").upper()
    218            if kind == "TABLE" and locations.get(exp.Properties.Location.POST_NAME):
    219                this_name = self.sql(expression.this, "this")
    220                this_properties = self.properties(
    221                    exp.Properties(expressions=locations[exp.Properties.Location.POST_NAME]),
    222                    wrapped=False,
    223                    prefix=",",
    224                )
    225                this_schema = self.schema_columns_sql(expression.this)
    226                return f"{this_name}{this_properties}{self.sep()}{this_schema}"
    227
    228            return super().createable_sql(expression, locations)

SUPPORTS_SEMI_ANTI_JOIN = False
TIME_MAPPING: Dict[str, str] = {'Y': '%Y', 'YYYY': '%Y', 'YY': '%y', 'MMMM': '%B', 'MMM': '%b', 'DD': '%d', 'D': '%-d', 'HH': '%H', 'H': '%-H', 'MM': '%M', 'M': '%-M', 'SS': '%S', 'S': '%-S', 'SSSSSS': '%f', 'E': '%a', 'EE': '%a', 'EEE': '%a', 'EEEE': '%A'}
tokenizer_class = <class 'Teradata.Tokenizer'>
parser_class = <class 'Teradata.Parser'>
generator_class = <class 'Teradata.Generator'>
TIME_TRIE: Dict = {'Y': {0: True, 'Y': {'Y': {'Y': {0: True}}, 0: True}}, 'M': {'M': {'M': {'M': {0: True}, 0: True}, 0: True}, 0: True}, 'D': {'D': {0: True}, 0: True}, 'H': {'H': {0: True}, 0: True}, 'S': {'S': {0: True, 'S': {'S': {'S': {'S': {0: True}}}}}, 0: True}, 'E': {0: True, 'E': {0: True, 'E': {0: True, 'E': {0: True}}}}}
FORMAT_TRIE: Dict = {'Y': {0: True, 'Y': {'Y': {'Y': {0: True}}, 0: True}}, 'M': {'M': {'M': {'M': {0: True}, 0: True}, 0: True}, 0: True}, 'D': {'D': {0: True}, 0: True}, 'H': {'H': {0: True}, 0: True}, 'S': {'S': {0: True, 'S': {'S': {'S': {'S': {0: True}}}}}, 0: True}, 'E': {0: True, 'E': {0: True, 'E': {0: True, 'E': {0: True}}}}}
INVERSE_TIME_MAPPING: Dict[str, str] = {'%Y': 'YYYY', '%y': 'YY', '%B': 'MMMM', '%b': 'MMM', '%d': 'DD', '%-d': 'D', '%H': 'HH', '%-H': 'H', '%M': 'MM', '%-M': 'M', '%S': 'SS', '%-S': 'S', '%f': 'SSSSSS', '%a': 'EEE', '%A': 'EEEE'}
INVERSE_TIME_TRIE: Dict = {'%': {'Y': {0: True}, 'y': {0: True}, 'B': {0: True}, 'b': {0: True}, 'd': {0: True}, '-': {'d': {0: True}, 'H': {0: True}, 'M': {0: True}, 'S': {0: True}}, 'H': {0: True}, 'M': {0: True}, 'S': {0: True}, 'f': {0: True}, 'a': {0: True}, 'A': {0: True}}}
INVERSE_ESCAPE_SEQUENCES: Dict[str, str] = {}
QUOTE_START = "'"
QUOTE_END = "'"
IDENTIFIER_START = '"'
IDENTIFIER_END = '"'
BIT_START = None
BIT_END = None
HEX_START = None
HEX_END = None
BYTE_START = None
BYTE_END = None

##### Inherited Members

sqlglot.dialects.dialect.Dialect
  INDEX_OFFSET
  UNNEST_COLUMN_ONLY
  ALIAS_POST_TABLESAMPLE
  RESOLVES_IDENTIFIERS_AS_UPPERCASE
  IDENTIFIERS_CAN_START_WITH_DIGIT
  DPIPE_IS_STRING_CONCAT
  STRICT_STRING_CONCAT
  SUPPORTS_USER_DEFINED_TYPES
  NORMALIZE_FUNCTIONS
  LOG_BASE_FIRST
  NULL_ORDERING
  DATE_FORMAT
  DATEINT_FORMAT
  TIME_FORMAT
  FORMAT_MAPPING
  ESCAPE_SEQUENCES
  PSEUDOCOLUMNS
  get_or_raise
  format_time
  normalize_identifier
  case_sensitive
  can_identify
  quote_identifier
  parse
  parse_into
  generate
  transpile
  tokenize
  tokenizer
  parser
  generator

class Teradata.Tokenizer(sqlglot.tokens.Tokenizer): View Source

    35    class Tokenizer(tokens.Tokenizer):
    36        # https://docs.teradata.com/r/Teradata-Database-SQL-Functions-Operators-Expressions-and-Predicates/March-2017/Comparison-Operators-and-Functions/Comparison-Operators/ANSI-Compliance
    37        KEYWORDS = {
    38            **tokens.Tokenizer.KEYWORDS,
    39            "^=": TokenType.NEQ,
    40            "BYTEINT": TokenType.SMALLINT,
    41            "COLLECT": TokenType.COMMAND,
    42            "GE": TokenType.GTE,
    43            "GT": TokenType.GT,
    44            "HELP": TokenType.COMMAND,
    45            "INS": TokenType.INSERT,
    46            "LE": TokenType.LTE,
    47            "LT": TokenType.LT,
    48            "MOD": TokenType.MOD,
    49            "NE": TokenType.NEQ,
    50            "NOT=": TokenType.NEQ,
    51            "SAMPLE": TokenType.TABLE_SAMPLE,
    52            "SEL": TokenType.SELECT,
    53            "ST_GEOMETRY": TokenType.GEOMETRY,
    54            "TOP": TokenType.TOP,
    55        }
    56
    57        # Teradata does not support % as a modulo operator
    58        SINGLE_TOKENS = {**tokens.Tokenizer.SINGLE_TOKENS}
    59        SINGLE_TOKENS.pop("%")

KEYWORDS = {'{%': <TokenType.BLOCK_START: 'BLOCK_START'>, '{%+': <TokenType.BLOCK_START: 'BLOCK_START'>, '{%-': <TokenType.BLOCK_START: 'BLOCK_START'>, '%}': <TokenType.BLOCK_END: 'BLOCK_END'>, '+%}': <TokenType.BLOCK_END: 'BLOCK_END'>, '-%}': <TokenType.BLOCK_END: 'BLOCK_END'>, '{{+': <TokenType.BLOCK_START: 'BLOCK_START'>, '{{-': <TokenType.BLOCK_START: 'BLOCK_START'>, '+}}': <TokenType.BLOCK_END: 'BLOCK_END'>, '-}}': <TokenType.BLOCK_END: 'BLOCK_END'>, '/*+': <TokenType.HINT: 'HINT'>, '==': <TokenType.EQ: 'EQ'>, '::': <TokenType.DCOLON: 'DCOLON'>, '||': <TokenType.DPIPE: 'DPIPE'>, '>=': <TokenType.GTE: 'GTE'>, '<=': <TokenType.LTE: 'LTE'>, '<>': <TokenType.NEQ: 'NEQ'>, '!=': <TokenType.NEQ: 'NEQ'>, '<=>': <TokenType.NULLSAFE_EQ: 'NULLSAFE_EQ'>, '->': <TokenType.ARROW: 'ARROW'>, '->>': <TokenType.DARROW: 'DARROW'>, '=>': <TokenType.FARROW: 'FARROW'>, '#>': <TokenType.HASH_ARROW: 'HASH_ARROW'>, '#>>': <TokenType.DHASH_ARROW: 'DHASH_ARROW'>, '<->': <TokenType.LR_ARROW: 'LR_ARROW'>, '&&': <TokenType.DAMP: 'DAMP'>, '??': <TokenType.DQMARK: 'DQMARK'>, 'ALL': <TokenType.ALL: 'ALL'>, 'ALWAYS': <TokenType.ALWAYS: 'ALWAYS'>, 'AND': <TokenType.AND: 'AND'>, 'ANTI': <TokenType.ANTI: 'ANTI'>, 'ANY': <TokenType.ANY: 'ANY'>, 'ASC': <TokenType.ASC: 'ASC'>, 'AS': <TokenType.ALIAS: 'ALIAS'>, 'ASOF': <TokenType.ASOF: 'ASOF'>, 'AUTOINCREMENT': <TokenType.AUTO_INCREMENT: 'AUTO_INCREMENT'>, 'AUTO_INCREMENT': <TokenType.AUTO_INCREMENT: 'AUTO_INCREMENT'>, 'BEGIN': <TokenType.BEGIN: 'BEGIN'>, 'BETWEEN': <TokenType.BETWEEN: 'BETWEEN'>, 'CACHE': <TokenType.CACHE: 'CACHE'>, 'UNCACHE': <TokenType.UNCACHE: 'UNCACHE'>, 'CASE': <TokenType.CASE: 'CASE'>, 'CHARACTER SET': <TokenType.CHARACTER_SET: 'CHARACTER_SET'>, 'CLUSTER BY': <TokenType.CLUSTER_BY: 'CLUSTER_BY'>, 'COLLATE': <TokenType.COLLATE: 'COLLATE'>, 'COLUMN': <TokenType.COLUMN: 'COLUMN'>, 'COMMIT': <TokenType.COMMIT: 'COMMIT'>, 'CONNECT BY': <TokenType.CONNECT_BY: 'CONNECT_BY'>, 'CONSTRAINT': <TokenType.CONSTRAINT: 'CONSTRAINT'>, 'CREATE': <TokenType.CREATE: 'CREATE'>, 'CROSS': <TokenType.CROSS: 'CROSS'>, 'CUBE': <TokenType.CUBE: 'CUBE'>, 'CURRENT_DATE': <TokenType.CURRENT_DATE: 'CURRENT_DATE'>, 'CURRENT_TIME': <TokenType.CURRENT_TIME: 'CURRENT_TIME'>, 'CURRENT_TIMESTAMP': <TokenType.CURRENT_TIMESTAMP: 'CURRENT_TIMESTAMP'>, 'CURRENT_USER': <TokenType.CURRENT_USER: 'CURRENT_USER'>, 'DATABASE': <TokenType.DATABASE: 'DATABASE'>, 'DEFAULT': <TokenType.DEFAULT: 'DEFAULT'>, 'DELETE': <TokenType.DELETE: 'DELETE'>, 'DESC': <TokenType.DESC: 'DESC'>, 'DESCRIBE': <TokenType.DESCRIBE: 'DESCRIBE'>, 'DISTINCT': <TokenType.DISTINCT: 'DISTINCT'>, 'DISTRIBUTE BY': <TokenType.DISTRIBUTE_BY: 'DISTRIBUTE_BY'>, 'DIV': <TokenType.DIV: 'DIV'>, 'DROP': <TokenType.DROP: 'DROP'>, 'ELSE': <TokenType.ELSE: 'ELSE'>, 'END': <TokenType.END: 'END'>, 'ESCAPE': <TokenType.ESCAPE: 'ESCAPE'>, 'EXCEPT': <TokenType.EXCEPT: 'EXCEPT'>, 'EXECUTE': <TokenType.EXECUTE: 'EXECUTE'>, 'EXISTS': <TokenType.EXISTS: 'EXISTS'>, 'FALSE': <TokenType.FALSE: 'FALSE'>, 'FETCH': <TokenType.FETCH: 'FETCH'>, 'FILTER': <TokenType.FILTER: 'FILTER'>, 'FIRST': <TokenType.FIRST: 'FIRST'>, 'FULL': <TokenType.FULL: 'FULL'>, 'FUNCTION': <TokenType.FUNCTION: 'FUNCTION'>, 'FOR': <TokenType.FOR: 'FOR'>, 'FOREIGN KEY': <TokenType.FOREIGN_KEY: 'FOREIGN_KEY'>, 'FORMAT': <TokenType.FORMAT: 'FORMAT'>, 'FROM': <TokenType.FROM: 'FROM'>, 'GEOGRAPHY': <TokenType.GEOGRAPHY: 'GEOGRAPHY'>, 'GEOMETRY': <TokenType.GEOMETRY: 'GEOMETRY'>, 'GLOB': <TokenType.GLOB: 'GLOB'>, 'GROUP BY': <TokenType.GROUP_BY: 'GROUP_BY'>, 'GROUPING SETS': <TokenType.GROUPING_SETS: 'GROUPING_SETS'>, 'HAVING': <TokenType.HAVING: 'HAVING'>, 'ILIKE': <TokenType.ILIKE: 'ILIKE'>, 'IN': <TokenType.IN: 'IN'>, 'INDEX': <TokenType.INDEX: 'INDEX'>, 'INET': <TokenType.INET: 'INET'>, 'INNER': <TokenType.INNER: 'INNER'>, 'INSERT': <TokenType.INSERT: 'INSERT'>, 'INTERVAL': <TokenType.INTERVAL: 'INTERVAL'>, 'INTERSECT': <TokenType.INTERSECT: 'INTERSECT'>, 'INTO': <TokenType.INTO: 'INTO'>, 'IS': <TokenType.IS: 'IS'>, 'ISNULL': <TokenType.ISNULL: 'ISNULL'>, 'JOIN': <TokenType.JOIN: 'JOIN'>, 'KEEP': <TokenType.KEEP: 'KEEP'>, 'KILL': <TokenType.KILL: 'KILL'>, 'LATERAL': <TokenType.LATERAL: 'LATERAL'>, 'LEFT': <TokenType.LEFT: 'LEFT'>, 'LIKE': <TokenType.LIKE: 'LIKE'>, 'LIMIT': <TokenType.LIMIT: 'LIMIT'>, 'LOAD': <TokenType.LOAD: 'LOAD'>, 'LOCK': <TokenType.LOCK: 'LOCK'>, 'MERGE': <TokenType.MERGE: 'MERGE'>, 'NATURAL': <TokenType.NATURAL: 'NATURAL'>, 'NEXT': <TokenType.NEXT: 'NEXT'>, 'NOT': <TokenType.NOT: 'NOT'>, 'NOTNULL': <TokenType.NOTNULL: 'NOTNULL'>, 'NULL': <TokenType.NULL: 'NULL'>, 'OBJECT': <TokenType.OBJECT: 'OBJECT'>, 'OFFSET': <TokenType.OFFSET: 'OFFSET'>, 'ON': <TokenType.ON: 'ON'>, 'OR': <TokenType.OR: 'OR'>, 'XOR': <TokenType.XOR: 'XOR'>, 'ORDER BY': <TokenType.ORDER_BY: 'ORDER_BY'>, 'ORDINALITY': <TokenType.ORDINALITY: 'ORDINALITY'>, 'OUTER': <TokenType.OUTER: 'OUTER'>, 'OVER': <TokenType.OVER: 'OVER'>, 'OVERLAPS': <TokenType.OVERLAPS: 'OVERLAPS'>, 'OVERWRITE': <TokenType.OVERWRITE: 'OVERWRITE'>, 'PARTITION': <TokenType.PARTITION: 'PARTITION'>, 'PARTITION BY': <TokenType.PARTITION_BY: 'PARTITION_BY'>, 'PARTITIONED BY': <TokenType.PARTITION_BY: 'PARTITION_BY'>, 'PARTITIONED_BY': <TokenType.PARTITION_BY: 'PARTITION_BY'>, 'PERCENT': <TokenType.PERCENT: 'PERCENT'>, 'PIVOT': <TokenType.PIVOT: 'PIVOT'>, 'PRAGMA': <TokenType.PRAGMA: 'PRAGMA'>, 'PRIMARY KEY': <TokenType.PRIMARY_KEY: 'PRIMARY_KEY'>, 'PROCEDURE': <TokenType.PROCEDURE: 'PROCEDURE'>, 'QUALIFY': <TokenType.QUALIFY: 'QUALIFY'>, 'RANGE': <TokenType.RANGE: 'RANGE'>, 'RECURSIVE': <TokenType.RECURSIVE: 'RECURSIVE'>, 'REGEXP': <TokenType.RLIKE: 'RLIKE'>, 'REPLACE': <TokenType.REPLACE: 'REPLACE'>, 'RETURNING': <TokenType.RETURNING: 'RETURNING'>, 'REFERENCES': <TokenType.REFERENCES: 'REFERENCES'>, 'RIGHT': <TokenType.RIGHT: 'RIGHT'>, 'RLIKE': <TokenType.RLIKE: 'RLIKE'>, 'ROLLBACK': <TokenType.ROLLBACK: 'ROLLBACK'>, 'ROLLUP': <TokenType.ROLLUP: 'ROLLUP'>, 'ROW': <TokenType.ROW: 'ROW'>, 'ROWS': <TokenType.ROWS: 'ROWS'>, 'SCHEMA': <TokenType.SCHEMA: 'SCHEMA'>, 'SELECT': <TokenType.SELECT: 'SELECT'>, 'SEMI': <TokenType.SEMI: 'SEMI'>, 'SET': <TokenType.SET: 'SET'>, 'SETTINGS': <TokenType.SETTINGS: 'SETTINGS'>, 'SHOW': <TokenType.SHOW: 'SHOW'>, 'SIMILAR TO': <TokenType.SIMILAR_TO: 'SIMILAR_TO'>, 'SOME': <TokenType.SOME: 'SOME'>, 'SORT BY': <TokenType.SORT_BY: 'SORT_BY'>, 'START WITH': <TokenType.START_WITH: 'START_WITH'>, 'TABLE': <TokenType.TABLE: 'TABLE'>, 'TABLESAMPLE': <TokenType.TABLE_SAMPLE: 'TABLE_SAMPLE'>, 'TEMP': <TokenType.TEMPORARY: 'TEMPORARY'>, 'TEMPORARY': <TokenType.TEMPORARY: 'TEMPORARY'>, 'THEN': <TokenType.THEN: 'THEN'>, 'TRUE': <TokenType.TRUE: 'TRUE'>, 'UNION': <TokenType.UNION: 'UNION'>, 'UNKNOWN': <TokenType.UNKNOWN: 'UNKNOWN'>, 'UNNEST': <TokenType.UNNEST: 'UNNEST'>, 'UNPIVOT': <TokenType.UNPIVOT: 'UNPIVOT'>, 'UPDATE': <TokenType.UPDATE: 'UPDATE'>, 'USE': <TokenType.USE: 'USE'>, 'USING': <TokenType.USING: 'USING'>, 'UUID': <TokenType.UUID: 'UUID'>, 'VALUES': <TokenType.VALUES: 'VALUES'>, 'VIEW': <TokenType.VIEW: 'VIEW'>, 'VOLATILE': <TokenType.VOLATILE: 'VOLATILE'>, 'WHEN': <TokenType.WHEN: 'WHEN'>, 'WHERE': <TokenType.WHERE: 'WHERE'>, 'WINDOW': <TokenType.WINDOW: 'WINDOW'>, 'WITH': <TokenType.WITH: 'WITH'>, 'APPLY': <TokenType.APPLY: 'APPLY'>, 'ARRAY': <TokenType.ARRAY: 'ARRAY'>, 'BIT': <TokenType.BIT: 'BIT'>, 'BOOL': <TokenType.BOOLEAN: 'BOOLEAN'>, 'BOOLEAN': <TokenType.BOOLEAN: 'BOOLEAN'>, 'BYTE': <TokenType.TINYINT: 'TINYINT'>, 'MEDIUMINT': <TokenType.MEDIUMINT: 'MEDIUMINT'>, 'TINYINT': <TokenType.TINYINT: 'TINYINT'>, 'SHORT': <TokenType.SMALLINT: 'SMALLINT'>, 'SMALLINT': <TokenType.SMALLINT: 'SMALLINT'>, 'INT128': <TokenType.INT128: 'INT128'>, 'INT2': <TokenType.SMALLINT: 'SMALLINT'>, 'INTEGER': <TokenType.INT: 'INT'>, 'INT': <TokenType.INT: 'INT'>, 'INT4': <TokenType.INT: 'INT'>, 'LONG': <TokenType.BIGINT: 'BIGINT'>, 'BIGINT': <TokenType.BIGINT: 'BIGINT'>, 'INT8': <TokenType.BIGINT: 'BIGINT'>, 'DEC': <TokenType.DECIMAL: 'DECIMAL'>, 'DECIMAL': <TokenType.DECIMAL: 'DECIMAL'>, 'BIGDECIMAL': <TokenType.BIGDECIMAL: 'BIGDECIMAL'>, 'BIGNUMERIC': <TokenType.BIGDECIMAL: 'BIGDECIMAL'>, 'MAP': <TokenType.MAP: 'MAP'>, 'NULLABLE': <TokenType.NULLABLE: 'NULLABLE'>, 'NUMBER': <TokenType.DECIMAL: 'DECIMAL'>, 'NUMERIC': <TokenType.DECIMAL: 'DECIMAL'>, 'FIXED': <TokenType.DECIMAL: 'DECIMAL'>, 'REAL': <TokenType.FLOAT: 'FLOAT'>, 'FLOAT': <TokenType.FLOAT: 'FLOAT'>, 'FLOAT4': <TokenType.FLOAT: 'FLOAT'>, 'FLOAT8': <TokenType.DOUBLE: 'DOUBLE'>, 'DOUBLE': <TokenType.DOUBLE: 'DOUBLE'>, 'DOUBLE PRECISION': <TokenType.DOUBLE: 'DOUBLE'>, 'JSON': <TokenType.JSON: 'JSON'>, 'CHAR': <TokenType.CHAR: 'CHAR'>, 'CHARACTER': <TokenType.CHAR: 'CHAR'>, 'NCHAR': <TokenType.NCHAR: 'NCHAR'>, 'VARCHAR': <TokenType.VARCHAR: 'VARCHAR'>, 'VARCHAR2': <TokenType.VARCHAR: 'VARCHAR'>, 'NVARCHAR': <TokenType.NVARCHAR: 'NVARCHAR'>, 'NVARCHAR2': <TokenType.NVARCHAR: 'NVARCHAR'>, 'STR': <TokenType.TEXT: 'TEXT'>, 'STRING': <TokenType.TEXT: 'TEXT'>, 'TEXT': <TokenType.TEXT: 'TEXT'>, 'LONGTEXT': <TokenType.LONGTEXT: 'LONGTEXT'>, 'MEDIUMTEXT': <TokenType.MEDIUMTEXT: 'MEDIUMTEXT'>, 'TINYTEXT': <TokenType.TINYTEXT: 'TINYTEXT'>, 'CLOB': <TokenType.TEXT: 'TEXT'>, 'LONGVARCHAR': <TokenType.TEXT: 'TEXT'>, 'BINARY': <TokenType.BINARY: 'BINARY'>, 'BLOB': <TokenType.VARBINARY: 'VARBINARY'>, 'LONGBLOB': <TokenType.LONGBLOB: 'LONGBLOB'>, 'MEDIUMBLOB': <TokenType.MEDIUMBLOB: 'MEDIUMBLOB'>, 'TINYBLOB': <TokenType.TINYBLOB: 'TINYBLOB'>, 'BYTEA': <TokenType.VARBINARY: 'VARBINARY'>, 'VARBINARY': <TokenType.VARBINARY: 'VARBINARY'>, 'TIME': <TokenType.TIME: 'TIME'>, 'TIMETZ': <TokenType.TIMETZ: 'TIMETZ'>, 'TIMESTAMP': <TokenType.TIMESTAMP: 'TIMESTAMP'>, 'TIMESTAMPTZ': <TokenType.TIMESTAMPTZ: 'TIMESTAMPTZ'>, 'TIMESTAMPLTZ': <TokenType.TIMESTAMPLTZ: 'TIMESTAMPLTZ'>, 'DATE': <TokenType.DATE: 'DATE'>, 'DATETIME': <TokenType.DATETIME: 'DATETIME'>, 'INT4RANGE': <TokenType.INT4RANGE: 'INT4RANGE'>, 'INT4MULTIRANGE': <TokenType.INT4MULTIRANGE: 'INT4MULTIRANGE'>, 'INT8RANGE': <TokenType.INT8RANGE: 'INT8RANGE'>, 'INT8MULTIRANGE': <TokenType.INT8MULTIRANGE: 'INT8MULTIRANGE'>, 'NUMRANGE': <TokenType.NUMRANGE: 'NUMRANGE'>, 'NUMMULTIRANGE': <TokenType.NUMMULTIRANGE: 'NUMMULTIRANGE'>, 'TSRANGE': <TokenType.TSRANGE: 'TSRANGE'>, 'TSMULTIRANGE': <TokenType.TSMULTIRANGE: 'TSMULTIRANGE'>, 'TSTZRANGE': <TokenType.TSTZRANGE: 'TSTZRANGE'>, 'TSTZMULTIRANGE': <TokenType.TSTZMULTIRANGE: 'TSTZMULTIRANGE'>, 'DATERANGE': <TokenType.DATERANGE: 'DATERANGE'>, 'DATEMULTIRANGE': <TokenType.DATEMULTIRANGE: 'DATEMULTIRANGE'>, 'UNIQUE': <TokenType.UNIQUE: 'UNIQUE'>, 'STRUCT': <TokenType.STRUCT: 'STRUCT'>, 'VARIANT': <TokenType.VARIANT: 'VARIANT'>, 'ALTER': <TokenType.ALTER: 'ALTER'>, 'ANALYZE': <TokenType.COMMAND: 'COMMAND'>, 'CALL': <TokenType.COMMAND: 'COMMAND'>, 'COMMENT': <TokenType.COMMENT: 'COMMENT'>, 'COPY': <TokenType.COMMAND: 'COMMAND'>, 'EXPLAIN': <TokenType.COMMAND: 'COMMAND'>, 'GRANT': <TokenType.COMMAND: 'COMMAND'>, 'OPTIMIZE': <TokenType.COMMAND: 'COMMAND'>, 'PREPARE': <TokenType.COMMAND: 'COMMAND'>, 'TRUNCATE': <TokenType.COMMAND: 'COMMAND'>, 'VACUUM': <TokenType.COMMAND: 'COMMAND'>, 'USER-DEFINED': <TokenType.USERDEFINED: 'USERDEFINED'>, 'FOR VERSION': <TokenType.VERSION_SNAPSHOT: 'VERSION_SNAPSHOT'>, 'FOR TIMESTAMP': <TokenType.TIMESTAMP_SNAPSHOT: 'TIMESTAMP_SNAPSHOT'>, '^=': <TokenType.NEQ: 'NEQ'>, 'BYTEINT': <TokenType.SMALLINT: 'SMALLINT'>, 'COLLECT': <TokenType.COMMAND: 'COMMAND'>, 'GE': <TokenType.GTE: 'GTE'>, 'GT': <TokenType.GT: 'GT'>, 'HELP': <TokenType.COMMAND: 'COMMAND'>, 'INS': <TokenType.INSERT: 'INSERT'>, 'LE': <TokenType.LTE: 'LTE'>, 'LT': <TokenType.LT: 'LT'>, 'MOD': <TokenType.MOD: 'MOD'>, 'NE': <TokenType.NEQ: 'NEQ'>, 'NOT=': <TokenType.NEQ: 'NEQ'>, 'SAMPLE': <TokenType.TABLE_SAMPLE: 'TABLE_SAMPLE'>, 'SEL': <TokenType.SELECT: 'SELECT'>, 'ST_GEOMETRY': <TokenType.GEOMETRY: 'GEOMETRY'>, 'TOP': <TokenType.TOP: 'TOP'>}
SINGLE_TOKENS = {'(': <TokenType.L_PAREN: 'L_PAREN'>, ')': <TokenType.R_PAREN: 'R_PAREN'>, '[': <TokenType.L_BRACKET: 'L_BRACKET'>, ']': <TokenType.R_BRACKET: 'R_BRACKET'>, '{': <TokenType.L_BRACE: 'L_BRACE'>, '}': <TokenType.R_BRACE: 'R_BRACE'>, '&': <TokenType.AMP: 'AMP'>, '^': <TokenType.CARET: 'CARET'>, ':': <TokenType.COLON: 'COLON'>, ',': <TokenType.COMMA: 'COMMA'>, '.': <TokenType.DOT: 'DOT'>, '-': <TokenType.DASH: 'DASH'>, '=': <TokenType.EQ: 'EQ'>, '>': <TokenType.GT: 'GT'>, '<': <TokenType.LT: 'LT'>, '!': <TokenType.NOT: 'NOT'>, '|': <TokenType.PIPE: 'PIPE'>, '+': <TokenType.PLUS: 'PLUS'>, ';': <TokenType.SEMICOLON: 'SEMICOLON'>, '/': <TokenType.SLASH: 'SLASH'>, '\\': <TokenType.BACKSLASH: 'BACKSLASH'>, '*': <TokenType.STAR: 'STAR'>, '~': <TokenType.TILDA: 'TILDA'>, '?': <TokenType.PLACEHOLDER: 'PLACEHOLDER'>, '@': <TokenType.PARAMETER: 'PARAMETER'>, "'": <TokenType.QUOTE: 'QUOTE'>, '`': <TokenType.IDENTIFIER: 'IDENTIFIER'>, '"': <TokenType.IDENTIFIER: 'IDENTIFIER'>, '#': <TokenType.HASH: 'HASH'>}

##### Inherited Members

sqlglot.tokens.Tokenizer
  BIT_STRINGS
  BYTE_STRINGS
  HEX_STRINGS
  RAW_STRINGS
  HEREDOC_STRINGS
  IDENTIFIERS
  IDENTIFIER_ESCAPES
  QUOTES
  STRING_ESCAPES
  VAR_SINGLE_TOKENS
  ESCAPE_SEQUENCES
  IDENTIFIERS_CAN_START_WITH_DIGIT
  WHITE_SPACE
  COMMANDS
  COMMAND_PREFIX_TOKENS
  NUMERIC_LITERALS
  ENCODE
  COMMENTS
  reset
  tokenize
  peek
  size
  sql
  tokens

class Teradata.Parser(sqlglot.parser.Parser): View Source

     61    class Parser(parser.Parser):
     62        TABLESAMPLE_CSV = True
     63
     64        CHARSET_TRANSLATORS = {
     65            "GRAPHIC_TO_KANJISJIS",
     66            "GRAPHIC_TO_LATIN",
     67            "GRAPHIC_TO_UNICODE",
     68            "GRAPHIC_TO_UNICODE_PadSpace",
     69            "KANJI1_KanjiEBCDIC_TO_UNICODE",
     70            "KANJI1_KanjiEUC_TO_UNICODE",
     71            "KANJI1_KANJISJIS_TO_UNICODE",
     72            "KANJI1_SBC_TO_UNICODE",
     73            "KANJISJIS_TO_GRAPHIC",
     74            "KANJISJIS_TO_LATIN",
     75            "KANJISJIS_TO_UNICODE",
     76            "LATIN_TO_GRAPHIC",
     77            "LATIN_TO_KANJISJIS",
     78            "LATIN_TO_UNICODE",
     79            "LOCALE_TO_UNICODE",
     80            "UNICODE_TO_GRAPHIC",
     81            "UNICODE_TO_GRAPHIC_PadGraphic",
     82            "UNICODE_TO_GRAPHIC_VarGraphic",
     83            "UNICODE_TO_KANJI1_KanjiEBCDIC",
     84            "UNICODE_TO_KANJI1_KanjiEUC",
     85            "UNICODE_TO_KANJI1_KANJISJIS",
     86            "UNICODE_TO_KANJI1_SBC",
     87            "UNICODE_TO_KANJISJIS",
     88            "UNICODE_TO_LATIN",
     89            "UNICODE_TO_LOCALE",
     90            "UNICODE_TO_UNICODE_FoldSpace",
     91            "UNICODE_TO_UNICODE_Fullwidth",
     92            "UNICODE_TO_UNICODE_Halfwidth",
     93            "UNICODE_TO_UNICODE_NFC",
     94            "UNICODE_TO_UNICODE_NFD",
     95            "UNICODE_TO_UNICODE_NFKC",
     96            "UNICODE_TO_UNICODE_NFKD",
     97        }
     98
     99        FUNC_TOKENS = {*parser.Parser.FUNC_TOKENS}
    100        FUNC_TOKENS.remove(TokenType.REPLACE)
    101
    102        STATEMENT_PARSERS = {
    103            **parser.Parser.STATEMENT_PARSERS,
    104            TokenType.DATABASE: lambda self: self.expression(
    105                exp.Use, this=self._parse_table(schema=False)
    106            ),
    107            TokenType.REPLACE: lambda self: self._parse_create(),
    108        }
    109
    110        FUNCTION_PARSERS = {
    111            **parser.Parser.FUNCTION_PARSERS,
    112            "RANGE_N": lambda self: self._parse_rangen(),
    113            "TRANSLATE": lambda self: self._parse_translate(self.STRICT_CAST),
    114        }
    115
    116        def _parse_translate(self, strict: bool) -> exp.Expression:
    117            this = self._parse_conjunction()
    118
    119            if not self._match(TokenType.USING):
    120                self.raise_error("Expected USING in TRANSLATE")
    121
    122            if self._match_texts(self.CHARSET_TRANSLATORS):
    123                charset_split = self._prev.text.split("_TO_")
    124                to = self.expression(exp.CharacterSet, this=charset_split[1])
    125            else:
    126                self.raise_error("Expected a character set translator after USING in TRANSLATE")
    127
    128            return self.expression(exp.Cast if strict else exp.TryCast, this=this, to=to)
    129
    130        # FROM before SET in Teradata UPDATE syntax
    131        # https://docs.teradata.com/r/Enterprise_IntelliFlex_VMware/Teradata-VantageTM-SQL-Data-Manipulation-Language-17.20/Statement-Syntax/UPDATE/UPDATE-Syntax-Basic-Form-FROM-Clause
    132        def _parse_update(self) -> exp.Update:
    133            return self.expression(
    134                exp.Update,
    135                **{  # type: ignore
    136                    "this": self._parse_table(alias_tokens=self.UPDATE_ALIAS_TOKENS),
    137                    "from": self._parse_from(joins=True),
    138                    "expressions": self._match(TokenType.SET)
    139                    and self._parse_csv(self._parse_equality),
    140                    "where": self._parse_where(),
    141                },
    142            )
    143
    144        def _parse_rangen(self):
    145            this = self._parse_id_var()
    146            self._match(TokenType.BETWEEN)
    147
    148            expressions = self._parse_csv(self._parse_conjunction)
    149            each = self._match_text_seq("EACH") and self._parse_conjunction()
    150
    151            return self.expression(exp.RangeN, this=this, expressions=expressions, each=each)

Parser consumes a list of tokens produced by the Tokenizer and produces a parsed syntax tree.

###### Arguments:

- error_level: The desired error level. Default: ErrorLevel.IMMEDIATE
- error_message_context: Determines the amount of context to capture from a query string when displaying the error message (in number of characters). Default: 100
- max_errors: Maximum number of error messages to include in a raised ParseError. This is only relevant if error_level is ErrorLevel.RAISE. Default: 3

TABLESAMPLE_CSV = True
CHARSET_TRANSLATORS = {'GRAPHIC_TO_KANJISJIS', 'UNICODE_TO_KANJI1_KANJISJIS', 'UNICODE_TO_GRAPHIC', 'UNICODE_TO_LOCALE', 'UNICODE_TO_UNICODE_FoldSpace', 'UNICODE_TO_UNICODE_NFKC', 'UNICODE_TO_GRAPHIC_VarGraphic', 'UNICODE_TO_KANJISJIS', 'UNICODE_TO_UNICODE_Halfwidth', 'UNICODE_TO_UNICODE_NFC', 'KANJI1_KanjiEBCDIC_TO_UNICODE', 'KANJI1_SBC_TO_UNICODE', 'GRAPHIC_TO_LATIN', 'KANJI1_KanjiEUC_TO_UNICODE', 'UNICODE_TO_KANJI1_KanjiEUC', 'LATIN_TO_GRAPHIC', 'UNICODE_TO_GRAPHIC_PadGraphic', 'UNICODE_TO_KANJI1_SBC', 'KANJISJIS_TO_LATIN', 'UNICODE_TO_UNICODE_NFD', 'KANJISJIS_TO_GRAPHIC', 'LATIN_TO_KANJISJIS', 'UNICODE_TO_UNICODE_Fullwidth', 'GRAPHIC_TO_UNICODE', 'KANJI1_KANJISJIS_TO_UNICODE', 'UNICODE_TO_LATIN', 'UNICODE_TO_UNICODE_NFKD', 'GRAPHIC_TO_UNICODE_PadSpace', 'LATIN_TO_UNICODE', 'LOCALE_TO_UNICODE', 'KANJISJIS_TO_UNICODE', 'UNICODE_TO_KANJI1_KanjiEBCDIC'}
FUNC_TOKENS = {<TokenType.JSON: 'JSON'>, <TokenType.DATEMULTIRANGE: 'DATEMULTIRANGE'>, <TokenType.CURRENT_TIME: 'CURRENT_TIME'>, <TokenType.NULLABLE: 'NULLABLE'>, <TokenType.NESTED: 'NESTED'>, <TokenType.UNNEST: 'UNNEST'>, <TokenType.BIGDECIMAL: 'BIGDECIMAL'>, <TokenType.UTINYINT: 'UTINYINT'>, <TokenType.NULL: 'NULL'>, <TokenType.TEXT: 'TEXT'>, <TokenType.ISNULL: 'ISNULL'>, <TokenType.OBJECT_IDENTIFIER: 'OBJECT_IDENTIFIER'>, <TokenType.TIME: 'TIME'>, <TokenType.USMALLINT: 'USMALLINT'>, <TokenType.HSTORE: 'HSTORE'>, <TokenType.FORMAT: 'FORMAT'>, <TokenType.INDEX: 'INDEX'>, <TokenType.MONEY: 'MONEY'>, <TokenType.HLLSKETCH: 'HLLSKETCH'>, <TokenType.RIGHT: 'RIGHT'>, <TokenType.MERGE: 'MERGE'>, <TokenType.TINYTEXT: 'TINYTEXT'>, <TokenType.DATERANGE: 'DATERANGE'>, <TokenType.RANGE: 'RANGE'>, <TokenType.TIMETZ: 'TIMETZ'>, <TokenType.JSONB: 'JSONB'>, <TokenType.BIGINT: 'BIGINT'>, <TokenType.INSERT: 'INSERT'>, <TokenType.UINT256: 'UINT256'>, <TokenType.NUMRANGE: 'NUMRANGE'>, <TokenType.BIT: 'BIT'>, <TokenType.UNIQUEIDENTIFIER: 'UNIQUEIDENTIFIER'>, <TokenType.VARIANT: 'VARIANT'>, <TokenType.GEOMETRY: 'GEOMETRY'>, <TokenType.DATE: 'DATE'>, <TokenType.SERIAL: 'SERIAL'>, <TokenType.CURRENT_USER: 'CURRENT_USER'>, <TokenType.BINARY: 'BINARY'>, <TokenType.NCHAR: 'NCHAR'>, <TokenType.ILIKE: 'ILIKE'>, <TokenType.INT256: 'INT256'>, <TokenType.UUID: 'UUID'>, <TokenType.TSRANGE: 'TSRANGE'>, <TokenType.FIXEDSTRING: 'FIXEDSTRING'>, <TokenType.SMALLMONEY: 'SMALLMONEY'>, <TokenType.TIMESTAMP: 'TIMESTAMP'>, <TokenType.UDECIMAL: 'UDECIMAL'>, <TokenType.YEAR: 'YEAR'>, <TokenType.MEDIUMTEXT: 'MEDIUMTEXT'>, <TokenType.IPPREFIX: 'IPPREFIX'>, <TokenType.PRIMARY_KEY: 'PRIMARY_KEY'>, <TokenType.RLIKE: 'RLIKE'>, <TokenType.VARCHAR: 'VARCHAR'>, <TokenType.TIMESTAMPLTZ: 'TIMESTAMPLTZ'>, <TokenType.BOOLEAN: 'BOOLEAN'>, <TokenType.UBIGINT: 'UBIGINT'>, <TokenType.MEDIUMBLOB: 'MEDIUMBLOB'>, <TokenType.ANY: 'ANY'>, <TokenType.FILTER: 'FILTER'>, <TokenType.TINYBLOB: 'TINYBLOB'>, <TokenType.GEOGRAPHY: 'GEOGRAPHY'>, <TokenType.GLOB: 'GLOB'>, <TokenType.FLOAT: 'FLOAT'>, <TokenType.IPADDRESS: 'IPADDRESS'>, <TokenType.TINYINT: 'TINYINT'>, <TokenType.INT4MULTIRANGE: 'INT4MULTIRANGE'>, <TokenType.SMALLINT: 'SMALLINT'>, <TokenType.BIGSERIAL: 'BIGSERIAL'>, <TokenType.MEDIUMINT: 'MEDIUMINT'>, <TokenType.IMAGE: 'IMAGE'>, <TokenType.INT8MULTIRANGE: 'INT8MULTIRANGE'>, <TokenType.XOR: 'XOR'>, <TokenType.INET: 'INET'>, <TokenType.LEFT: 'LEFT'>, <TokenType.SMALLSERIAL: 'SMALLSERIAL'>, <TokenType.CHAR: 'CHAR'>, <TokenType.SUPER: 'SUPER'>, <TokenType.MAP: 'MAP'>, <TokenType.INT128: 'INT128'>, <TokenType.LOWCARDINALITY: 'LOWCARDINALITY'>, <TokenType.TSMULTIRANGE: 'TSMULTIRANGE'>, <TokenType.USERDEFINED: 'USERDEFINED'>, <TokenType.CURRENT_TIMESTAMP: 'CURRENT_TIMESTAMP'>, <TokenType.INT: 'INT'>, <TokenType.UMEDIUMINT: 'UMEDIUMINT'>, <TokenType.INT4RANGE: 'INT4RANGE'>, <TokenType.ENUM16: 'ENUM16'>, <TokenType.CURRENT_DATETIME: 'CURRENT_DATETIME'>, <TokenType.EXISTS: 'EXISTS'>, <TokenType.FIRST: 'FIRST'>, <TokenType.TIMESTAMPTZ: 'TIMESTAMPTZ'>, <TokenType.INTERVAL: 'INTERVAL'>, <TokenType.LONGBLOB: 'LONGBLOB'>, <TokenType.WINDOW: 'WINDOW'>, <TokenType.NVARCHAR: 'NVARCHAR'>, <TokenType.NUMMULTIRANGE: 'NUMMULTIRANGE'>, <TokenType.CURRENT_DATE: 'CURRENT_DATE'>, <TokenType.TSTZRANGE: 'TSTZRANGE'>, <TokenType.DATETIME64: 'DATETIME64'>, <TokenType.DATETIME: 'DATETIME'>, <TokenType.UINT: 'UINT'>, <TokenType.VAR: 'VAR'>, <TokenType.IDENTIFIER: 'IDENTIFIER'>, <TokenType.XML: 'XML'>, <TokenType.ENUM8: 'ENUM8'>, <TokenType.ENUM: 'ENUM'>, <TokenType.PSEUDO_TYPE: 'PSEUDO_TYPE'>, <TokenType.COMMAND: 'COMMAND'>, <TokenType.OFFSET: 'OFFSET'>, <TokenType.DOUBLE: 'DOUBLE'>, <TokenType.SOME: 'SOME'>, <TokenType.VARBINARY: 'VARBINARY'>, <TokenType.TABLE: 'TABLE'>, <TokenType.OBJECT: 'OBJECT'>, <TokenType.LIKE: 'LIKE'>, <TokenType.ROWVERSION: 'ROWVERSION'>, <TokenType.INT8RANGE: 'INT8RANGE'>, <TokenType.ROW: 'ROW'>, <TokenType.LONGTEXT: 'LONGTEXT'>, <TokenType.DECIMAL: 'DECIMAL'>, <TokenType.ARRAY: 'ARRAY'>, <TokenType.UINT128: 'UINT128'>, <TokenType.STRUCT: 'STRUCT'>, <TokenType.TSTZMULTIRANGE: 'TSTZMULTIRANGE'>, <TokenType.COLLATE: 'COLLATE'>, <TokenType.UNKNOWN: 'UNKNOWN'>, <TokenType.ALL: 'ALL'>}
STATEMENT_PARSERS = {<TokenType.ALTER: 'ALTER'>: <function Parser.<lambda>>, <TokenType.BEGIN: 'BEGIN'>: <function Parser.<lambda>>, <TokenType.CACHE: 'CACHE'>: <function Parser.<lambda>>, <TokenType.COMMIT: 'COMMIT'>: <function Parser.<lambda>>, <TokenType.COMMENT: 'COMMENT'>: <function Parser.<lambda>>, <TokenType.CREATE: 'CREATE'>: <function Parser.<lambda>>, <TokenType.DELETE: 'DELETE'>: <function Parser.<lambda>>, <TokenType.DESC: 'DESC'>: <function Parser.<lambda>>, <TokenType.DESCRIBE: 'DESCRIBE'>: <function Parser.<lambda>>, <TokenType.DROP: 'DROP'>: <function Parser.<lambda>>, <TokenType.INSERT: 'INSERT'>: <function Parser.<lambda>>, <TokenType.KILL: 'KILL'>: <function Parser.<lambda>>, <TokenType.LOAD: 'LOAD'>: <function Parser.<lambda>>, <TokenType.MERGE: 'MERGE'>: <function Parser.<lambda>>, <TokenType.PIVOT: 'PIVOT'>: <function Parser.<lambda>>, <TokenType.PRAGMA: 'PRAGMA'>: <function Parser.<lambda>>, <TokenType.ROLLBACK: 'ROLLBACK'>: <function Parser.<lambda>>, <TokenType.SET: 'SET'>: <function Parser.<lambda>>, <TokenType.UNCACHE: 'UNCACHE'>: <function Parser.<lambda>>, <TokenType.UPDATE: 'UPDATE'>: <function Parser.<lambda>>, <TokenType.USE: 'USE'>: <function Parser.<lambda>>, <TokenType.DATABASE: 'DATABASE'>: <function Teradata.Parser.<lambda>>, <TokenType.REPLACE: 'REPLACE'>: <function Teradata.Parser.<lambda>>}
FUNCTION_PARSERS = {'ANY_VALUE': <function Parser.<lambda>>, 'CAST': <function Parser.<lambda>>, 'CONCAT': <function Parser.<lambda>>, 'CONCAT_WS': <function Parser.<lambda>>, 'CONVERT': <function Parser.<lambda>>, 'DECODE': <function Parser.<lambda>>, 'EXTRACT': <function Parser.<lambda>>, 'JSON_OBJECT': <function Parser.<lambda>>, 'LOG': <function Parser.<lambda>>, 'MATCH': <function Parser.<lambda>>, 'OPENJSON': <function Parser.<lambda>>, 'POSITION': <function Parser.<lambda>>, 'SAFE_CAST': <function Parser.<lambda>>, 'STRING_AGG': <function Parser.<lambda>>, 'SUBSTRING': <function Parser.<lambda>>, 'TRIM': <function Parser.<lambda>>, 'TRY_CAST': <function Parser.<lambda>>, 'TRY_CONVERT': <function Parser.<lambda>>, 'RANGE_N': <function Teradata.Parser.<lambda>>, 'TRANSLATE': <function Teradata.Parser.<lambda>>}
TABLE_ALIAS_TOKENS = {<TokenType.LOAD: 'LOAD'>, <TokenType.FUNCTION: 'FUNCTION'>, <TokenType.JSON: 'JSON'>, <TokenType.DATEMULTIRANGE: 'DATEMULTIRANGE'>, <TokenType.CURRENT_TIME: 'CURRENT_TIME'>, <TokenType.TEMPORARY: 'TEMPORARY'>, <TokenType.BEGIN: 'BEGIN'>, <TokenType.NULLABLE: 'NULLABLE'>, <TokenType.NESTED: 'NESTED'>, <TokenType.VIEW: 'VIEW'>, <TokenType.IS: 'IS'>, <TokenType.BIGDECIMAL: 'BIGDECIMAL'>, <TokenType.REFERENCES: 'REFERENCES'>, <TokenType.UTINYINT: 'UTINYINT'>, <TokenType.NULL: 'NULL'>, <TokenType.PARTITION: 'PARTITION'>, <TokenType.TEXT: 'TEXT'>, <TokenType.ISNULL: 'ISNULL'>, <TokenType.OBJECT_IDENTIFIER: 'OBJECT_IDENTIFIER'>, <TokenType.TIME: 'TIME'>, <TokenType.COMMENT: 'COMMENT'>, <TokenType.ANTI: 'ANTI'>, <TokenType.CONSTRAINT: 'CONSTRAINT'>, <TokenType.USMALLINT: 'USMALLINT'>, <TokenType.HSTORE: 'HSTORE'>, <TokenType.FORMAT: 'FORMAT'>, <TokenType.INDEX: 'INDEX'>, <TokenType.MONEY: 'MONEY'>, <TokenType.HLLSKETCH: 'HLLSKETCH'>, <TokenType.COMMIT: 'COMMIT'>, <TokenType.MERGE: 'MERGE'>, <TokenType.TINYTEXT: 'TINYTEXT'>, <TokenType.DATERANGE: 'DATERANGE'>, <TokenType.ROWS: 'ROWS'>, <TokenType.RANGE: 'RANGE'>, <TokenType.TIMETZ: 'TIMETZ'>, <TokenType.OVERLAPS: 'OVERLAPS'>, <TokenType.TSTZMULTIRANGE: 'TSTZMULTIRANGE'>, <TokenType.JSONB: 'JSONB'>, <TokenType.BIGINT: 'BIGINT'>, <TokenType.DESC: 'DESC'>, <TokenType.UINT256: 'UINT256'>, <TokenType.NUMRANGE: 'NUMRANGE'>, <TokenType.BIT: 'BIT'>, <TokenType.EXECUTE: 'EXECUTE'>, <TokenType.UNIQUEIDENTIFIER: 'UNIQUEIDENTIFIER'>, <TokenType.VARIANT: 'VARIANT'>, <TokenType.GEOMETRY: 'GEOMETRY'>, <TokenType.SERIAL: 'SERIAL'>, <TokenType.DATE: 'DATE'>, <TokenType.CURRENT_USER: 'CURRENT_USER'>, <TokenType.BINARY: 'BINARY'>, <TokenType.NCHAR: 'NCHAR'>, <TokenType.PIVOT: 'PIVOT'>, <TokenType.SHOW: 'SHOW'>, <TokenType.KEEP: 'KEEP'>, <TokenType.INT256: 'INT256'>, <TokenType.UUID: 'UUID'>, <TokenType.TSRANGE: 'TSRANGE'>, <TokenType.FIXEDSTRING: 'FIXEDSTRING'>, <TokenType.SMALLMONEY: 'SMALLMONEY'>, <TokenType.TIMESTAMP: 'TIMESTAMP'>, <TokenType.AUTO_INCREMENT: 'AUTO_INCREMENT'>, <TokenType.UDECIMAL: 'UDECIMAL'>, <TokenType.MEDIUMTEXT: 'MEDIUMTEXT'>, <TokenType.IPPREFIX: 'IPPREFIX'>, <TokenType.VARCHAR: 'VARCHAR'>, <TokenType.TIMESTAMPLTZ: 'TIMESTAMPLTZ'>, <TokenType.BOOLEAN: 'BOOLEAN'>, <TokenType.UBIGINT: 'UBIGINT'>, <TokenType.TRUE: 'TRUE'>, <TokenType.DEFAULT: 'DEFAULT'>, <TokenType.COLUMN: 'COLUMN'>, <TokenType.MEDIUMBLOB: 'MEDIUMBLOB'>, <TokenType.ANY: 'ANY'>, <TokenType.FILTER: 'FILTER'>, <TokenType.FALSE: 'FALSE'>, <TokenType.VOLATILE: 'VOLATILE'>, <TokenType.TINYBLOB: 'TINYBLOB'>, <TokenType.SCHEMA: 'SCHEMA'>, <TokenType.GEOGRAPHY: 'GEOGRAPHY'>, <TokenType.PRAGMA: 'PRAGMA'>, <TokenType.FLOAT: 'FLOAT'>, <TokenType.NEXT: 'NEXT'>, <TokenType.IPADDRESS: 'IPADDRESS'>, <TokenType.PROCEDURE: 'PROCEDURE'>, <TokenType.TINYINT: 'TINYINT'>, <TokenType.INT4MULTIRANGE: 'INT4MULTIRANGE'>, <TokenType.SMALLINT: 'SMALLINT'>, <TokenType.BIGSERIAL: 'BIGSERIAL'>, <TokenType.MEDIUMINT: 'MEDIUMINT'>, <TokenType.IMAGE: 'IMAGE'>, <TokenType.INT8MULTIRANGE: 'INT8MULTIRANGE'>, <TokenType.SETTINGS: 'SETTINGS'>, <TokenType.INET: 'INET'>, <TokenType.SET: 'SET'>, <TokenType.SMALLSERIAL: 'SMALLSERIAL'>, <TokenType.CHAR: 'CHAR'>, <TokenType.SUPER: 'SUPER'>, <TokenType.MAP: 'MAP'>, <TokenType.UNIQUE: 'UNIQUE'>, <TokenType.INT128: 'INT128'>, <TokenType.OVERWRITE: 'OVERWRITE'>, <TokenType.LOWCARDINALITY: 'LOWCARDINALITY'>, <TokenType.CASE: 'CASE'>, <TokenType.TSMULTIRANGE: 'TSMULTIRANGE'>, <TokenType.PERCENT: 'PERCENT'>, <TokenType.USERDEFINED: 'USERDEFINED'>, <TokenType.ESCAPE: 'ESCAPE'>, <TokenType.CURRENT_TIMESTAMP: 'CURRENT_TIMESTAMP'>, <TokenType.UNPIVOT: 'UNPIVOT'>, <TokenType.INT: 'INT'>, <TokenType.UMEDIUMINT: 'UMEDIUMINT'>, <TokenType.INT4RANGE: 'INT4RANGE'>, <TokenType.ENUM16: 'ENUM16'>, <TokenType.END: 'END'>, <TokenType.CURRENT_DATETIME: 'CURRENT_DATETIME'>, <TokenType.EXISTS: 'EXISTS'>, <TokenType.FIRST: 'FIRST'>, <TokenType.DELETE: 'DELETE'>, <TokenType.TIMESTAMPTZ: 'TIMESTAMPTZ'>, <TokenType.INTERVAL: 'INTERVAL'>, <TokenType.LONGBLOB: 'LONGBLOB'>, <TokenType.NVARCHAR: 'NVARCHAR'>, <TokenType.KILL: 'KILL'>, <TokenType.NUMMULTIRANGE: 'NUMMULTIRANGE'>, <TokenType.CURRENT_DATE: 'CURRENT_DATE'>, <TokenType.TSTZRANGE: 'TSTZRANGE'>, <TokenType.DATETIME64: 'DATETIME64'>, <TokenType.DATETIME: 'DATETIME'>, <TokenType.UINT: 'UINT'>, <TokenType.VAR: 'VAR'>, <TokenType.SEMI: 'SEMI'>, <TokenType.XML: 'XML'>, <TokenType.ENUM8: 'ENUM8'>, <TokenType.ENUM: 'ENUM'>, <TokenType.PSEUDO_TYPE: 'PSEUDO_TYPE'>, <TokenType.COMMAND: 'COMMAND'>, <TokenType.TOP: 'TOP'>, <TokenType.DOUBLE: 'DOUBLE'>, <TokenType.SOME: 'SOME'>, <TokenType.UPDATE: 'UPDATE'>, <TokenType.VARBINARY: 'VARBINARY'>, <TokenType.DATABASE: 'DATABASE'>, <TokenType.TABLE: 'TABLE'>, <TokenType.OBJECT: 'OBJECT'>, <TokenType.CACHE: 'CACHE'>, <TokenType.ORDINALITY: 'ORDINALITY'>, <TokenType.DICTIONARY: 'DICTIONARY'>, <TokenType.ASC: 'ASC'>, <TokenType.ROWVERSION: 'ROWVERSION'>, <TokenType.INT8RANGE: 'INT8RANGE'>, <TokenType.DIV: 'DIV'>, <TokenType.ROW: 'ROW'>, <TokenType.LONGTEXT: 'LONGTEXT'>, <TokenType.DECIMAL: 'DECIMAL'>, <TokenType.ARRAY: 'ARRAY'>, <TokenType.UINT128: 'UINT128'>, <TokenType.STRUCT: 'STRUCT'>, <TokenType.YEAR: 'YEAR'>, <TokenType.COLLATE: 'COLLATE'>, <TokenType.UNKNOWN: 'UNKNOWN'>, <TokenType.DESCRIBE: 'DESCRIBE'>, <TokenType.ALL: 'ALL'>}
TOKENIZER_CLASS: Type[sqlglot.tokens.Tokenizer] = <class 'Teradata.Tokenizer'>
SHOW_TRIE: Dict = {}
SET_TRIE: Dict = {'GLOBAL': {0: True}, 'LOCAL': {0: True}, 'SESSION': {0: True}, 'TRANSACTION': {0: True}}
FORMAT_TRIE: Dict = {'Y': {0: True, 'Y': {'Y': {'Y': {0: True}}, 0: True}}, 'M': {'M': {'M': {'M': {0: True}, 0: True}, 0: True}, 0: True}, 'D': {'D': {0: True}, 0: True}, 'H': {'H': {0: True}, 0: True}, 'S': {'S': {0: True, 'S': {'S': {'S': {'S': {0: True}}}}}, 0: True}, 'E': {0: True, 'E': {0: True, 'E': {0: True, 'E': {0: True}}}}}
TIME_MAPPING: Dict[str, str] = {'Y': '%Y', 'YYYY': '%Y', 'YY': '%y', 'MMMM': '%B', 'MMM': '%b', 'DD': '%d', 'D': '%-d', 'HH': '%H', 'H': '%-H', 'MM': '%M', 'M': '%-M', 'SS': '%S', 'S': '%-S', 'SSSSSS': '%f', 'E': '%a', 'EE': '%a', 'EEE': '%a', 'EEEE': '%A'}
TIME_TRIE: Dict = {'Y': {0: True, 'Y': {'Y': {'Y': {0: True}}, 0: True}}, 'M': {'M': {'M': {'M': {0: True}, 0: True}, 0: True}, 0: True}, 'D': {'D': {0: True}, 0: True}, 'H': {'H': {0: True}, 0: True}, 'S': {'S': {0: True, 'S': {'S': {'S': {'S': {0: True}}}}}, 0: True}, 'E': {0: True, 'E': {0: True, 'E': {0: True, 'E': {0: True}}}}}

##### Inherited Members

sqlglot.parser.Parser
  Parser
  FUNCTIONS
  NO_PAREN_FUNCTIONS
  STRUCT_TYPE_TOKENS
  NESTED_TYPE_TOKENS
  ENUM_TYPE_TOKENS
  TYPE_TOKENS
  SIGNED_TO_UNSIGNED_TYPE_TOKEN
  SUBQUERY_PREDICATES
  RESERVED_KEYWORDS
  DB_CREATABLES
  CREATABLES
  ID_VAR_TOKENS
  INTERVAL_VARS
  COMMENT_TABLE_ALIAS_TOKENS
  UPDATE_ALIAS_TOKENS
  TRIM_TYPES
  CONJUNCTION
  EQUALITY
  COMPARISON
  BITWISE
  TERM
  FACTOR
  TIMES
  TIMESTAMPS
  SET_OPERATIONS
  JOIN_METHODS
  JOIN_SIDES
  JOIN_KINDS
  JOIN_HINTS
  LAMBDAS
  COLUMN_OPERATORS
  EXPRESSION_PARSERS
  UNARY_PARSERS
  PRIMARY_PARSERS
  PLACEHOLDER_PARSERS
  RANGE_PARSERS
  PROPERTY_PARSERS
  CONSTRAINT_PARSERS
  ALTER_PARSERS
  SCHEMA_UNNAMED_CONSTRAINTS
  NO_PAREN_FUNCTION_PARSERS
  INVALID_FUNC_NAME_TOKENS
  FUNCTIONS_WITH_ALIASED_ARGS
  QUERY_MODIFIER_PARSERS
  SET_PARSERS
  SHOW_PARSERS
  TYPE_LITERAL_PARSERS
  MODIFIABLES
  DDL_SELECT_TOKENS
  PRE_VOLATILE_TOKENS
  TRANSACTION_KIND
  TRANSACTION_CHARACTERISTICS
  INSERT_ALTERNATIVES
  CLONE_KEYWORDS
  CLONE_KINDS
  OPCLASS_FOLLOW_KEYWORDS
  TABLE_INDEX_HINT_TOKENS
  WINDOW_ALIAS_TOKENS
  WINDOW_BEFORE_PAREN_TOKENS
  WINDOW_SIDES
  FETCH_TOKENS
  ADD_CONSTRAINT_TOKENS
  DISTINCT_TOKENS
  NULL_TOKENS
  UNNEST_OFFSET_ALIAS_TOKENS
  STRICT_CAST
  CONCAT_NULL_OUTPUTS_STRING
  PREFIXED_PIVOT_COLUMNS
  IDENTIFY_PIVOT_STRINGS
  LOG_BASE_FIRST
  LOG_DEFAULTS_TO_LN
  ALTER_TABLE_ADD_COLUMN_KEYWORD
  SET_REQUIRES_ASSIGNMENT_DELIMITER
  TRIM_PATTERN_FIRST
  INDEX_OFFSET
  UNNEST_COLUMN_ONLY
  ALIAS_POST_TABLESAMPLE
  STRICT_STRING_CONCAT
  SUPPORTS_USER_DEFINED_TYPES
  NORMALIZE_FUNCTIONS
  NULL_ORDERING
  FORMAT_MAPPING
  error_level
  error_message_context
  max_errors
  reset
  parse
  parse_into
  check_errors
  raise_error
  expression
  validate_expression
  errors
  sql

class Teradata.Generator(sqlglot.generator.Generator): View Source

    153    class Generator(generator.Generator):
    154        JOIN_HINTS = False
    155        TABLE_HINTS = False
    156        QUERY_HINTS = False
    157
    158        TYPE_MAPPING = {
    159            **generator.Generator.TYPE_MAPPING,
    160            exp.DataType.Type.GEOMETRY: "ST_GEOMETRY",
    161        }
    162
    163        PROPERTIES_LOCATION = {
    164            **generator.Generator.PROPERTIES_LOCATION,
    165            exp.OnCommitProperty: exp.Properties.Location.POST_INDEX,
    166            exp.PartitionedByProperty: exp.Properties.Location.POST_EXPRESSION,
    167            exp.StabilityProperty: exp.Properties.Location.POST_CREATE,
    168        }
    169
    170        TRANSFORMS = {
    171            **generator.Generator.TRANSFORMS,
    172            exp.Max: max_or_greatest,
    173            exp.Min: min_or_least,
    174            exp.Select: transforms.preprocess(
    175                [transforms.eliminate_distinct_on, transforms.eliminate_semi_and_anti_joins]
    176            ),
    177            exp.StrToDate: lambda self, e: f"CAST({self.sql(e, 'this')} AS DATE FORMAT {self.format_time(e)})",
    178            exp.ToChar: lambda self, e: self.function_fallback_sql(e),
    179            exp.Use: lambda self, e: f"DATABASE {self.sql(e, 'this')}",
    180        }
    181
    182        def tablesample_sql(
    183            self, expression: exp.TableSample, seed_prefix: str = "SEED", sep=" AS "
    184        ) -> str:
    185            return f"{self.sql(expression, 'this')} SAMPLE {self.expressions(expression)}"
    186
    187        def partitionedbyproperty_sql(self, expression: exp.PartitionedByProperty) -> str:
    188            return f"PARTITION BY {self.sql(expression, 'this')}"
    189
    190        # FROM before SET in Teradata UPDATE syntax
    191        # https://docs.teradata.com/r/Enterprise_IntelliFlex_VMware/Teradata-VantageTM-SQL-Data-Manipulation-Language-17.20/Statement-Syntax/UPDATE/UPDATE-Syntax-Basic-Form-FROM-Clause
    192        def update_sql(self, expression: exp.Update) -> str:
    193            this = self.sql(expression, "this")
    194            from_sql = self.sql(expression, "from")
    195            set_sql = self.expressions(expression, flat=True)
    196            where_sql = self.sql(expression, "where")
    197            sql = f"UPDATE {this}{from_sql} SET {set_sql}{where_sql}"
    198            return self.prepend_ctes(expression, sql)
    199
    200        def mod_sql(self, expression: exp.Mod) -> str:
    201            return self.binary(expression, "MOD")
    202
    203        def datatype_sql(self, expression: exp.DataType) -> str:
    204            type_sql = super().datatype_sql(expression)
    205            prefix_sql = expression.args.get("prefix")
    206            return f"SYSUDTLIB.{type_sql}" if prefix_sql else type_sql
    207
    208        def rangen_sql(self, expression: exp.RangeN) -> str:
    209            this = self.sql(expression, "this")
    210            expressions_sql = self.expressions(expression)
    211            each_sql = self.sql(expression, "each")
    212            each_sql = f" EACH {each_sql}" if each_sql else ""
    213
    214            return f"RANGE_N({this} BETWEEN {expressions_sql}{each_sql})"
    215
    216        def createable_sql(self, expression: exp.Create, locations: t.DefaultDict) -> str:
    217            kind = self.sql(expression, "kind").upper()
    218            if kind == "TABLE" and locations.get(exp.Properties.Location.POST_NAME):
    219                this_name = self.sql(expression.this, "this")
    220                this_properties = self.properties(
    221                    exp.Properties(expressions=locations[exp.Properties.Location.POST_NAME]),
    222                    wrapped=False,
    223                    prefix=",",
    224                )
    225                this_schema = self.schema_columns_sql(expression.this)
    226                return f"{this_name}{this_properties}{self.sep()}{this_schema}"
    227
    228            return super().createable_sql(expression, locations)

Generator converts a given syntax tree to the corresponding SQL string.

###### Arguments:

- pretty: Whether or not to format the produced SQL string. Default: False.
- identify: Determines when an identifier should be quoted. Possible values are: False (default): Never quote, except in cases where it's mandatory by the dialect. True or 'always': Always quote. 'safe': Only quote identifiers that are case insensitive.
- normalize: Whether or not to normalize identifiers to lowercase. Default: False.
- pad: Determines the pad size in a formatted string. Default: 2.
- indent: Determines the indentation size in a formatted string. Default: 2.
- normalize_functions: Whether or not to normalize all function names. Possible values are: "upper" or True (default): Convert names to uppercase. "lower": Convert names to lowercase. False: Disables function name normalization.
- unsupported_level: Determines the generator's behavior when it encounters unsupported expressions. Default ErrorLevel.WARN.
- max_unsupported: Maximum number of unsupported messages to include in a raised UnsupportedError. This is only relevant if unsupported_level is ErrorLevel.RAISE. Default: 3
- leading_comma: Determines whether or not the comma is leading or trailing in select expressions. This is only relevant when generating in pretty mode. Default: False
- max_text_width: The max number of characters in a segment before creating new lines in pretty mode. The default is on the smaller end because the length only represents a segment and not the true line length. Default: 80
- comments: Whether or not to preserve comments in the output SQL code. Default: True

JOIN_HINTS = False
TABLE_HINTS = False
QUERY_HINTS = False
TYPE_MAPPING = {<Type.NCHAR: 'NCHAR'>: 'CHAR', <Type.NVARCHAR: 'NVARCHAR'>: 'VARCHAR', <Type.MEDIUMTEXT: 'MEDIUMTEXT'>: 'TEXT', <Type.LONGTEXT: 'LONGTEXT'>: 'TEXT', <Type.TINYTEXT: 'TINYTEXT'>: 'TEXT', <Type.MEDIUMBLOB: 'MEDIUMBLOB'>: 'BLOB', <Type.LONGBLOB: 'LONGBLOB'>: 'BLOB', <Type.TINYBLOB: 'TINYBLOB'>: 'BLOB', <Type.INET: 'INET'>: 'INET', <Type.GEOMETRY: 'GEOMETRY'>: 'ST_GEOMETRY'}
PROPERTIES_LOCATION = {<class 'sqlglot.expressions.AlgorithmProperty'>: <Location.POST_CREATE: 'POST_CREATE'>, <class 'sqlglot.expressions.AutoIncrementProperty'>: <Location.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.BlockCompressionProperty'>: <Location.POST_NAME: 'POST_NAME'>, <class 'sqlglot.expressions.CharacterSetProperty'>: <Location.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.ChecksumProperty'>: <Location.POST_NAME: 'POST_NAME'>, <class 'sqlglot.expressions.CollateProperty'>: <Location.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.CopyGrantsProperty'>: <Location.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.Cluster'>: <Location.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.ClusteredByProperty'>: <Location.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.DataBlocksizeProperty'>: <Location.POST_NAME: 'POST_NAME'>, <class 'sqlglot.expressions.DefinerProperty'>: <Location.POST_CREATE: 'POST_CREATE'>, <class 'sqlglot.expressions.DictRange'>: <Location.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.DictProperty'>: <Location.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.DistKeyProperty'>: <Location.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.DistStyleProperty'>: <Location.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.EngineProperty'>: <Location.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.ExecuteAsProperty'>: <Location.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.ExternalProperty'>: <Location.POST_CREATE: 'POST_CREATE'>, <class 'sqlglot.expressions.FallbackProperty'>: <Location.POST_NAME: 'POST_NAME'>, <class 'sqlglot.expressions.FileFormatProperty'>: <Location.POST_WITH: 'POST_WITH'>, <class 'sqlglot.expressions.FreespaceProperty'>: <Location.POST_NAME: 'POST_NAME'>, <class 'sqlglot.expressions.HeapProperty'>: <Location.POST_WITH: 'POST_WITH'>, <class 'sqlglot.expressions.IsolatedLoadingProperty'>: <Location.POST_NAME: 'POST_NAME'>, <class 'sqlglot.expressions.JournalProperty'>: <Location.POST_NAME: 'POST_NAME'>, <class 'sqlglot.expressions.LanguageProperty'>: <Location.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.LikeProperty'>: <Location.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.LocationProperty'>: <Location.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.LockingProperty'>: <Location.POST_ALIAS: 'POST_ALIAS'>, <class 'sqlglot.expressions.LogProperty'>: <Location.POST_NAME: 'POST_NAME'>, <class 'sqlglot.expressions.MaterializedProperty'>: <Location.POST_CREATE: 'POST_CREATE'>, <class 'sqlglot.expressions.MergeBlockRatioProperty'>: <Location.POST_NAME: 'POST_NAME'>, <class 'sqlglot.expressions.NoPrimaryIndexProperty'>: <Location.POST_EXPRESSION: 'POST_EXPRESSION'>, <class 'sqlglot.expressions.OnProperty'>: <Location.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.OnCommitProperty'>: <Location.POST_INDEX: 'POST_INDEX'>, <class 'sqlglot.expressions.Order'>: <Location.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.PartitionedByProperty'>: <Location.POST_EXPRESSION: 'POST_EXPRESSION'>, <class 'sqlglot.expressions.PrimaryKey'>: <Location.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.Property'>: <Location.POST_WITH: 'POST_WITH'>, <class 'sqlglot.expressions.ReturnsProperty'>: <Location.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.RowFormatProperty'>: <Location.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.RowFormatDelimitedProperty'>: <Location.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.RowFormatSerdeProperty'>: <Location.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.SampleProperty'>: <Location.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.SchemaCommentProperty'>: <Location.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.SerdeProperties'>: <Location.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.Set'>: <Location.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.SettingsProperty'>: <Location.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.SetProperty'>: <Location.POST_CREATE: 'POST_CREATE'>, <class 'sqlglot.expressions.SortKeyProperty'>: <Location.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.SqlSecurityProperty'>: <Location.POST_CREATE: 'POST_CREATE'>, <class 'sqlglot.expressions.StabilityProperty'>: <Location.POST_CREATE: 'POST_CREATE'>, <class 'sqlglot.expressions.TemporaryProperty'>: <Location.POST_CREATE: 'POST_CREATE'>, <class 'sqlglot.expressions.ToTableProperty'>: <Location.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.TransientProperty'>: <Location.POST_CREATE: 'POST_CREATE'>, <class 'sqlglot.expressions.MergeTreeTTL'>: <Location.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.VolatileProperty'>: <Location.POST_CREATE: 'POST_CREATE'>, <class 'sqlglot.expressions.WithDataProperty'>: <Location.POST_EXPRESSION: 'POST_EXPRESSION'>, <class 'sqlglot.expressions.WithJournalTableProperty'>: <Location.POST_NAME: 'POST_NAME'>}
TRANSFORMS = {<class 'sqlglot.expressions.DateAdd'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.TsOrDsAdd'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.CaseSpecificColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.CharacterSetColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.CharacterSetProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.CheckColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.ClusteredColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.CollateColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.CopyGrantsProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.CommentColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.DateFormatColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.DefaultColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.EncodeColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.ExecuteAsProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.ExternalProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.HeapProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.InlineLengthColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.IntervalSpan'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.LanguageProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.LocationProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.LogProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.MaterializedProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.NoPrimaryIndexProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.NonClusteredColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.NotForReplicationColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.OnCommitProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.OnProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.OnUpdateColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.PathColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.ReturnsProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.SampleProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.SetProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.SettingsProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.SqlSecurityProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.StabilityProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.TemporaryProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.ToTableProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.TransientProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.TitleColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.UppercaseColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.VarMap'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.VolatileProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.WithJournalTableProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.Max'>: <function max_or_greatest>, <class 'sqlglot.expressions.Min'>: <function min_or_least>, <class 'sqlglot.expressions.Select'>: <function preprocess.<locals>._to_sql>, <class 'sqlglot.expressions.StrToDate'>: <function Teradata.Generator.<lambda>>, <class 'sqlglot.expressions.ToChar'>: <function Teradata.Generator.<lambda>>, <class 'sqlglot.expressions.Use'>: <function Teradata.Generator.<lambda>>}
def tablesample_sql( self, expression: sqlglot.expressions.TableSample, seed_prefix: str = 'SEED', sep=' AS ') -> str: View Source

    182        def tablesample_sql(
    183            self, expression: exp.TableSample, seed_prefix: str = "SEED", sep=" AS "
    184        ) -> str:
    185            return f"{self.sql(expression, 'this')} SAMPLE {self.expressions(expression)}"

def partitionedbyproperty_sql(self, expression: sqlglot.expressions.PartitionedByProperty) -> str: View Source

    187        def partitionedbyproperty_sql(self, expression: exp.PartitionedByProperty) -> str:
    188            return f"PARTITION BY {self.sql(expression, 'this')}"

def update_sql(self, expression: sqlglot.expressions.Update) -> str: View Source

    192        def update_sql(self, expression: exp.Update) -> str:
    193            this = self.sql(expression, "this")
    194            from_sql = self.sql(expression, "from")
    195            set_sql = self.expressions(expression, flat=True)
    196            where_sql = self.sql(expression, "where")
    197            sql = f"UPDATE {this}{from_sql} SET {set_sql}{where_sql}"
    198            return self.prepend_ctes(expression, sql)

def mod_sql(self, expression: sqlglot.expressions.Mod) -> str: View Source

    200        def mod_sql(self, expression: exp.Mod) -> str:
    201            return self.binary(expression, "MOD")

def datatype_sql(self, expression: sqlglot.expressions.DataType) -> str: View Source

    203        def datatype_sql(self, expression: exp.DataType) -> str:
    204            type_sql = super().datatype_sql(expression)
    205            prefix_sql = expression.args.get("prefix")
    206            return f"SYSUDTLIB.{type_sql}" if prefix_sql else type_sql

def rangen_sql(self, expression: sqlglot.expressions.RangeN) -> str: View Source

    208        def rangen_sql(self, expression: exp.RangeN) -> str:
    209            this = self.sql(expression, "this")
    210            expressions_sql = self.expressions(expression)
    211            each_sql = self.sql(expression, "each")
    212            each_sql = f" EACH {each_sql}" if each_sql else ""
    213
    214            return f"RANGE_N({this} BETWEEN {expressions_sql}{each_sql})"

def createable_sql( self, expression: sqlglot.expressions.Create, locations: DefaultDict) -> str: View Source

    216        def createable_sql(self, expression: exp.Create, locations: t.DefaultDict) -> str:
    217            kind = self.sql(expression, "kind").upper()
    218            if kind == "TABLE" and locations.get(exp.Properties.Location.POST_NAME):
    219                this_name = self.sql(expression.this, "this")
    220                this_properties = self.properties(
    221                    exp.Properties(expressions=locations[exp.Properties.Location.POST_NAME]),
    222                    wrapped=False,
    223                    prefix=",",
    224                )
    225                this_schema = self.schema_columns_sql(expression.this)
    226                return f"{this_name}{this_properties}{self.sep()}{this_schema}"
    227
    228            return super().createable_sql(expression, locations)

SELECT_KINDS: Tuple[str, ...] = ()
INVERSE_TIME_MAPPING: Dict[str, str] = {'%Y': 'YYYY', '%y': 'YY', '%B': 'MMMM', '%b': 'MMM', '%d': 'DD', '%-d': 'D', '%H': 'HH', '%-H': 'H', '%M': 'MM', '%-M': 'M', '%S': 'SS', '%-S': 'S', '%f': 'SSSSSS', '%a': 'EEE', '%A': 'EEEE'}
INVERSE_TIME_TRIE: Dict = {'%': {'Y': {0: True}, 'y': {0: True}, 'B': {0: True}, 'b': {0: True}, 'd': {0: True}, '-': {'d': {0: True}, 'H': {0: True}, 'M': {0: True}, 'S': {0: True}}, 'H': {0: True}, 'M': {0: True}, 'S': {0: True}, 'f': {0: True}, 'a': {0: True}, 'A': {0: True}}}
INVERSE_ESCAPE_SEQUENCES: Dict[str, str] = {}
@classmethod
def can_identify(text: str, identify: str | bool = 'safe') -> bool: View Source

    279    @classmethod
    280    def can_identify(cls, text: str, identify: str | bool = "safe") -> bool:
    281        """Checks if text can be identified given an identify option.
    282
    283        Args:
    284            text: The text to check.
    285            identify:
    286                "always" or `True`: Always returns true.
    287                "safe": True if the identifier is case-insensitive.
    288
    289        Returns:
    290            Whether or not the given text can be identified.
    291        """
    292        if identify is True or identify == "always":
    293            return True
    294
    295        if identify == "safe":
    296            return not cls.case_sensitive(text)
    297
    298        return False

Checks if text can be identified given an identify option.

###### Arguments:

- text: The text to check.
- identify: "always" or `True`: Always returns true. "safe": True if the identifier is case-insensitive.

###### Returns:

> Whether or not the given text can be identified.

QUOTE_START = "'"
QUOTE_END = "'"
IDENTIFIER_START = '"'
IDENTIFIER_END = '"'
TOKENIZER_CLASS = <class 'Teradata.Tokenizer'>
BIT_START: Optional[str] = None
BIT_END: Optional[str] = None
HEX_START: Optional[str] = None
HEX_END: Optional[str] = None
BYTE_START: Optional[str] = None
BYTE_END: Optional[str] = None

##### Inherited Members

sqlglot.generator.Generator
  Generator
  LOG_BASE_FIRST
  NULL_ORDERING_SUPPORTED
  LOCKING_READS_SUPPORTED
  EXPLICIT_UNION
  WRAP_DERIVED_VALUES
  CREATE_FUNCTION_RETURN_AS
  MATCHED_BY_SOURCE
  SINGLE_STRING_INTERVAL
  INTERVAL_ALLOWS_PLURAL_FORM
  TABLESAMPLE_WITH_METHOD
  TABLESAMPLE_SIZE_IS_PERCENT
  LIMIT_FETCH
  RENAME_TABLE_WITH_DB
  GROUPINGS_SEP
  INDEX_ON
  QUERY_HINT_SEP
  IS_BOOL_ALLOWED
  DUPLICATE_KEY_UPDATE_WITH_SET
  LIMIT_IS_TOP
  RETURNING_END
  COLUMN_JOIN_MARKS_SUPPORTED
  EXTRACT_ALLOWS_QUOTES
  TZ_TO_WITH_TIME_ZONE
  NVL2_SUPPORTED
  VALUES_AS_TABLE
  ALTER_TABLE_ADD_COLUMN_KEYWORD
  UNNEST_WITH_ORDINALITY
  AGGREGATE_FILTER_SUPPORTED
  SEMI_ANTI_JOIN_WITH_SIDE
  SUPPORTS_PARAMETERS
  COMPUTED_COLUMN_WITH_TYPE
  SUPPORTS_TABLE_COPY
  TABLESAMPLE_REQUIRES_PARENS
  COLLATE_IS_FUNC
  DATA_TYPE_SPECIFIERS_ALLOWED
  STAR_MAPPING
  TIME_PART_SINGULARS
  TOKEN_MAPPING
  STRUCT_DELIMITER
  PARAMETER_TOKEN
  RESERVED_KEYWORDS
  WITH_SEPARATED_COMMENTS
  UNWRAPPED_INTERVAL_VALUES
  SENTINEL_LINE_BREAK
  INDEX_OFFSET
  UNNEST_COLUMN_ONLY
  ALIAS_POST_TABLESAMPLE
  IDENTIFIERS_CAN_START_WITH_DIGIT
  STRICT_STRING_CONCAT
  NORMALIZE_FUNCTIONS
  NULL_ORDERING
  pretty
  identify
  normalize
  pad
  unsupported_level
  max_unsupported
  leading_comma
  max_text_width
  comments
  normalize_functions
  unsupported_messages
  generate
  unsupported
  sep
  seg
  pad_comment
  maybe_comment
  wrap
  no_identify
  normalize_func
  indent
  sql
  uncache_sql
  cache_sql
  characterset_sql
  column_sql
  columnposition_sql
  columndef_sql
  columnconstraint_sql
  computedcolumnconstraint_sql
  autoincrementcolumnconstraint_sql
  compresscolumnconstraint_sql
  generatedasidentitycolumnconstraint_sql
  notnullcolumnconstraint_sql
  primarykeycolumnconstraint_sql
  uniquecolumnconstraint_sql
  create_sql
  clone_sql
  describe_sql
  prepend_ctes
  with_sql
  cte_sql
  tablealias_sql
  bitstring_sql
  hexstring_sql
  bytestring_sql
  rawstring_sql
  datatypeparam_sql
  directory_sql
  delete_sql
  drop_sql
  except_sql
  except_op
  fetch_sql
  filter_sql
  hint_sql
  index_sql
  identifier_sql
  inputoutputformat_sql
  national_sql
  partition_sql
  properties_sql
  root_properties
  properties
  with_properties
  locate_properties
  property_name
  property_sql
  likeproperty_sql
  fallbackproperty_sql
  journalproperty_sql
  freespaceproperty_sql
  checksumproperty_sql
  mergeblockratioproperty_sql
  datablocksizeproperty_sql
  blockcompressionproperty_sql
  isolatedloadingproperty_sql
  lockingproperty_sql
  withdataproperty_sql
  insert_sql
  intersect_sql
  intersect_op
  introducer_sql
  kill_sql
  pseudotype_sql
  objectidentifier_sql
  onconflict_sql
  returning_sql
  rowformatdelimitedproperty_sql
  withtablehint_sql
  indextablehint_sql
  table_sql
  pivot_sql
  version_sql
  tuple_sql
  values_sql
  var_sql
  into_sql
  from_sql
  group_sql
  having_sql
  connect_sql
  prior_sql
  join_sql
  lambda_sql
  lateral_sql
  limit_sql
  offset_sql
  setitem_sql
  set_sql
  pragma_sql
  lock_sql
  literal_sql
  escape_str
  loaddata_sql
  null_sql
  boolean_sql
  order_sql
  cluster_sql
  distribute_sql
  sort_sql
  ordered_sql
  matchrecognize_sql
  query_modifiers
  offset_limit_modifiers
  after_having_modifiers
  after_limit_modifiers
  select_sql
  schema_sql
  schema_columns_sql
  star_sql
  parameter_sql
  sessionparameter_sql
  placeholder_sql
  subquery_sql
  qualify_sql
  union_sql
  union_op
  unnest_sql
  where_sql
  window_sql
  partition_by_sql
  windowspec_sql
  withingroup_sql
  between_sql
  bracket_sql
  safebracket_sql
  all_sql
  any_sql
  exists_sql
  case_sql
  constraint_sql
  nextvaluefor_sql
  extract_sql
  trim_sql
  safeconcat_sql
  check_sql
  foreignkey_sql
  primarykey_sql
  if_sql
  matchagainst_sql
  jsonkeyvalue_sql
  formatjson_sql
  jsonobject_sql
  jsonarray_sql
  jsonarrayagg_sql
  jsoncolumndef_sql
  jsontable_sql
  openjsoncolumndef_sql
  openjson_sql
  in_sql
  in_unnest_op
  interval_sql
  return_sql
  reference_sql
  anonymous_sql
  paren_sql
  neg_sql
  not_sql
  alias_sql
  aliases_sql
  attimezone_sql
  add_sql
  and_sql
  xor_sql
  connector_sql
  bitwiseand_sql
  bitwiseleftshift_sql
  bitwisenot_sql
  bitwiseor_sql
  bitwiserightshift_sql
  bitwisexor_sql
  cast_sql
  currentdate_sql
  collate_sql
  command_sql
  comment_sql
  mergetreettlaction_sql
  mergetreettl_sql
  transaction_sql
  commit_sql
  rollback_sql
  altercolumn_sql
  renametable_sql
  altertable_sql
  droppartition_sql
  addconstraint_sql
  distinct_sql
  ignorenulls_sql
  respectnulls_sql
  intdiv_sql
  dpipe_sql
  safedpipe_sql
  div_sql
  overlaps_sql
  distance_sql
  dot_sql
  eq_sql
  escape_sql
  glob_sql
  gt_sql
  gte_sql
  ilike_sql
  ilikeany_sql
  is_sql
  like_sql
  likeany_sql
  similarto_sql
  lt_sql
  lte_sql
  mul_sql
  neq_sql
  nullsafeeq_sql
  nullsafeneq_sql
  or_sql
  slice_sql
  sub_sql
  trycast_sql
  log_sql
  use_sql
  binary
  function_fallback_sql
  func
  format_args
  text_width
  format_time
  expressions
  op_expressions
  naked_property
  set_operation
  tag_sql
  token_sql
  userdefinedfunction_sql
  joinhint_sql
  kwarg_sql
  when_sql
  merge_sql
  tochar_sql
  dictproperty_sql
  dictrange_sql
  dictsubproperty_sql
  oncluster_sql
  clusteredbyproperty_sql
  anyvalue_sql
  querytransform_sql
  indexconstraintoption_sql
  indexcolumnconstraint_sql
  nvl2_sql
  comprehension_sql
  columnprefix_sql
  opclass_sql