sqlglot.dialects.teradata API documentation

Edit on GitHub

# sqlglot.dialects.teradata

View Source

      1from __future__ import annotations
      2
      3from sqlglot import exp, generator, parser, tokens
      4from sqlglot.dialects.dialect import Dialect, min_or_least
      5from sqlglot.tokens import TokenType
      6
      7
      8class Teradata(Dialect):
      9    class Tokenizer(tokens.Tokenizer):
     10        # https://docs.teradata.com/r/Teradata-Database-SQL-Functions-Operators-Expressions-and-Predicates/March-2017/Comparison-Operators-and-Functions/Comparison-Operators/ANSI-Compliance
     11        KEYWORDS = {
     12            **tokens.Tokenizer.KEYWORDS,
     13            "BYTEINT": TokenType.SMALLINT,
     14            "SEL": TokenType.SELECT,
     15            "INS": TokenType.INSERT,
     16            "MOD": TokenType.MOD,
     17            "LT": TokenType.LT,
     18            "LE": TokenType.LTE,
     19            "GT": TokenType.GT,
     20            "GE": TokenType.GTE,
     21            "^=": TokenType.NEQ,
     22            "NE": TokenType.NEQ,
     23            "NOT=": TokenType.NEQ,
     24            "ST_GEOMETRY": TokenType.GEOMETRY,
     25        }
     26
     27        # teradata does not support % for modulus
     28        SINGLE_TOKENS = {**tokens.Tokenizer.SINGLE_TOKENS}
     29        SINGLE_TOKENS.pop("%")
     30
     31    class Parser(parser.Parser):
     32        CHARSET_TRANSLATORS = {
     33            "GRAPHIC_TO_KANJISJIS",
     34            "GRAPHIC_TO_LATIN",
     35            "GRAPHIC_TO_UNICODE",
     36            "GRAPHIC_TO_UNICODE_PadSpace",
     37            "KANJI1_KanjiEBCDIC_TO_UNICODE",
     38            "KANJI1_KanjiEUC_TO_UNICODE",
     39            "KANJI1_KANJISJIS_TO_UNICODE",
     40            "KANJI1_SBC_TO_UNICODE",
     41            "KANJISJIS_TO_GRAPHIC",
     42            "KANJISJIS_TO_LATIN",
     43            "KANJISJIS_TO_UNICODE",
     44            "LATIN_TO_GRAPHIC",
     45            "LATIN_TO_KANJISJIS",
     46            "LATIN_TO_UNICODE",
     47            "LOCALE_TO_UNICODE",
     48            "UNICODE_TO_GRAPHIC",
     49            "UNICODE_TO_GRAPHIC_PadGraphic",
     50            "UNICODE_TO_GRAPHIC_VarGraphic",
     51            "UNICODE_TO_KANJI1_KanjiEBCDIC",
     52            "UNICODE_TO_KANJI1_KanjiEUC",
     53            "UNICODE_TO_KANJI1_KANJISJIS",
     54            "UNICODE_TO_KANJI1_SBC",
     55            "UNICODE_TO_KANJISJIS",
     56            "UNICODE_TO_LATIN",
     57            "UNICODE_TO_LOCALE",
     58            "UNICODE_TO_UNICODE_FoldSpace",
     59            "UNICODE_TO_UNICODE_Fullwidth",
     60            "UNICODE_TO_UNICODE_Halfwidth",
     61            "UNICODE_TO_UNICODE_NFC",
     62            "UNICODE_TO_UNICODE_NFD",
     63            "UNICODE_TO_UNICODE_NFKC",
     64            "UNICODE_TO_UNICODE_NFKD",
     65        }
     66
     67        FUNC_TOKENS = {*parser.Parser.FUNC_TOKENS}
     68        FUNC_TOKENS.remove(TokenType.REPLACE)
     69
     70        STATEMENT_PARSERS = {
     71            **parser.Parser.STATEMENT_PARSERS,  # type: ignore
     72            TokenType.REPLACE: lambda self: self._parse_create(),
     73        }
     74
     75        FUNCTION_PARSERS = {
     76            **parser.Parser.FUNCTION_PARSERS,  # type: ignore
     77            "RANGE_N": lambda self: self._parse_rangen(),
     78            "TRANSLATE": lambda self: self._parse_translate(self.STRICT_CAST),
     79        }
     80
     81        def _parse_translate(self, strict: bool) -> exp.Expression:
     82            this = self._parse_conjunction()
     83
     84            if not self._match(TokenType.USING):
     85                self.raise_error("Expected USING in TRANSLATE")
     86
     87            if self._match_texts(self.CHARSET_TRANSLATORS):
     88                charset_split = self._prev.text.split("_TO_")
     89                to = self.expression(exp.CharacterSet, this=charset_split[1])
     90            else:
     91                self.raise_error("Expected a character set translator after USING in TRANSLATE")
     92
     93            return self.expression(exp.Cast if strict else exp.TryCast, this=this, to=to)
     94
     95        # FROM before SET in Teradata UPDATE syntax
     96        # 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
     97        def _parse_update(self) -> exp.Expression:
     98            return self.expression(
     99                exp.Update,
    100                **{  # type: ignore
    101                    "this": self._parse_table(alias_tokens=self.UPDATE_ALIAS_TOKENS),
    102                    "from": self._parse_from(),
    103                    "expressions": self._match(TokenType.SET)
    104                    and self._parse_csv(self._parse_equality),
    105                    "where": self._parse_where(),
    106                },
    107            )
    108
    109        def _parse_rangen(self):
    110            this = self._parse_id_var()
    111            self._match(TokenType.BETWEEN)
    112
    113            expressions = self._parse_csv(self._parse_conjunction)
    114            each = self._match_text_seq("EACH") and self._parse_conjunction()
    115
    116            return self.expression(exp.RangeN, this=this, expressions=expressions, each=each)
    117
    118    class Generator(generator.Generator):
    119        TYPE_MAPPING = {
    120            **generator.Generator.TYPE_MAPPING,  # type: ignore
    121            exp.DataType.Type.GEOMETRY: "ST_GEOMETRY",
    122        }
    123
    124        PROPERTIES_LOCATION = {
    125            **generator.Generator.PROPERTIES_LOCATION,  # type: ignore
    126            exp.PartitionedByProperty: exp.Properties.Location.POST_INDEX,
    127        }
    128
    129        TRANSFORMS = {
    130            **generator.Generator.TRANSFORMS,
    131            exp.Min: min_or_least,
    132            exp.ToChar: lambda self, e: self.function_fallback_sql(e),
    133        }
    134
    135        def partitionedbyproperty_sql(self, expression: exp.PartitionedByProperty) -> str:
    136            return f"PARTITION BY {self.sql(expression, 'this')}"
    137
    138        # FROM before SET in Teradata UPDATE syntax
    139        # 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
    140        def update_sql(self, expression: exp.Update) -> str:
    141            this = self.sql(expression, "this")
    142            from_sql = self.sql(expression, "from")
    143            set_sql = self.expressions(expression, flat=True)
    144            where_sql = self.sql(expression, "where")
    145            sql = f"UPDATE {this}{from_sql} SET {set_sql}{where_sql}"
    146            return self.prepend_ctes(expression, sql)
    147
    148        def mod_sql(self, expression: exp.Mod) -> str:
    149            return self.binary(expression, "MOD")
    150
    151        def datatype_sql(self, expression: exp.DataType) -> str:
    152            type_sql = super().datatype_sql(expression)
    153            prefix_sql = expression.args.get("prefix")
    154            return f"SYSUDTLIB.{type_sql}" if prefix_sql else type_sql
    155
    156        def rangen_sql(self, expression: exp.RangeN) -> str:
    157            this = self.sql(expression, "this")
    158            expressions_sql = self.expressions(expression)
    159            each_sql = self.sql(expression, "each")
    160            each_sql = f" EACH {each_sql}" if each_sql else ""
    161
    162            return f"RANGE_N({this} BETWEEN {expressions_sql}{each_sql})"

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

      9class Teradata(Dialect):
     10    class Tokenizer(tokens.Tokenizer):
     11        # https://docs.teradata.com/r/Teradata-Database-SQL-Functions-Operators-Expressions-and-Predicates/March-2017/Comparison-Operators-and-Functions/Comparison-Operators/ANSI-Compliance
     12        KEYWORDS = {
     13            **tokens.Tokenizer.KEYWORDS,
     14            "BYTEINT": TokenType.SMALLINT,
     15            "SEL": TokenType.SELECT,
     16            "INS": TokenType.INSERT,
     17            "MOD": TokenType.MOD,
     18            "LT": TokenType.LT,
     19            "LE": TokenType.LTE,
     20            "GT": TokenType.GT,
     21            "GE": TokenType.GTE,
     22            "^=": TokenType.NEQ,
     23            "NE": TokenType.NEQ,
     24            "NOT=": TokenType.NEQ,
     25            "ST_GEOMETRY": TokenType.GEOMETRY,
     26        }
     27
     28        # teradata does not support % for modulus
     29        SINGLE_TOKENS = {**tokens.Tokenizer.SINGLE_TOKENS}
     30        SINGLE_TOKENS.pop("%")
     31
     32    class Parser(parser.Parser):
     33        CHARSET_TRANSLATORS = {
     34            "GRAPHIC_TO_KANJISJIS",
     35            "GRAPHIC_TO_LATIN",
     36            "GRAPHIC_TO_UNICODE",
     37            "GRAPHIC_TO_UNICODE_PadSpace",
     38            "KANJI1_KanjiEBCDIC_TO_UNICODE",
     39            "KANJI1_KanjiEUC_TO_UNICODE",
     40            "KANJI1_KANJISJIS_TO_UNICODE",
     41            "KANJI1_SBC_TO_UNICODE",
     42            "KANJISJIS_TO_GRAPHIC",
     43            "KANJISJIS_TO_LATIN",
     44            "KANJISJIS_TO_UNICODE",
     45            "LATIN_TO_GRAPHIC",
     46            "LATIN_TO_KANJISJIS",
     47            "LATIN_TO_UNICODE",
     48            "LOCALE_TO_UNICODE",
     49            "UNICODE_TO_GRAPHIC",
     50            "UNICODE_TO_GRAPHIC_PadGraphic",
     51            "UNICODE_TO_GRAPHIC_VarGraphic",
     52            "UNICODE_TO_KANJI1_KanjiEBCDIC",
     53            "UNICODE_TO_KANJI1_KanjiEUC",
     54            "UNICODE_TO_KANJI1_KANJISJIS",
     55            "UNICODE_TO_KANJI1_SBC",
     56            "UNICODE_TO_KANJISJIS",
     57            "UNICODE_TO_LATIN",
     58            "UNICODE_TO_LOCALE",
     59            "UNICODE_TO_UNICODE_FoldSpace",
     60            "UNICODE_TO_UNICODE_Fullwidth",
     61            "UNICODE_TO_UNICODE_Halfwidth",
     62            "UNICODE_TO_UNICODE_NFC",
     63            "UNICODE_TO_UNICODE_NFD",
     64            "UNICODE_TO_UNICODE_NFKC",
     65            "UNICODE_TO_UNICODE_NFKD",
     66        }
     67
     68        FUNC_TOKENS = {*parser.Parser.FUNC_TOKENS}
     69        FUNC_TOKENS.remove(TokenType.REPLACE)
     70
     71        STATEMENT_PARSERS = {
     72            **parser.Parser.STATEMENT_PARSERS,  # type: ignore
     73            TokenType.REPLACE: lambda self: self._parse_create(),
     74        }
     75
     76        FUNCTION_PARSERS = {
     77            **parser.Parser.FUNCTION_PARSERS,  # type: ignore
     78            "RANGE_N": lambda self: self._parse_rangen(),
     79            "TRANSLATE": lambda self: self._parse_translate(self.STRICT_CAST),
     80        }
     81
     82        def _parse_translate(self, strict: bool) -> exp.Expression:
     83            this = self._parse_conjunction()
     84
     85            if not self._match(TokenType.USING):
     86                self.raise_error("Expected USING in TRANSLATE")
     87
     88            if self._match_texts(self.CHARSET_TRANSLATORS):
     89                charset_split = self._prev.text.split("_TO_")
     90                to = self.expression(exp.CharacterSet, this=charset_split[1])
     91            else:
     92                self.raise_error("Expected a character set translator after USING in TRANSLATE")
     93
     94            return self.expression(exp.Cast if strict else exp.TryCast, this=this, to=to)
     95
     96        # FROM before SET in Teradata UPDATE syntax
     97        # 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
     98        def _parse_update(self) -> exp.Expression:
     99            return self.expression(
    100                exp.Update,
    101                **{  # type: ignore
    102                    "this": self._parse_table(alias_tokens=self.UPDATE_ALIAS_TOKENS),
    103                    "from": self._parse_from(),
    104                    "expressions": self._match(TokenType.SET)
    105                    and self._parse_csv(self._parse_equality),
    106                    "where": self._parse_where(),
    107                },
    108            )
    109
    110        def _parse_rangen(self):
    111            this = self._parse_id_var()
    112            self._match(TokenType.BETWEEN)
    113
    114            expressions = self._parse_csv(self._parse_conjunction)
    115            each = self._match_text_seq("EACH") and self._parse_conjunction()
    116
    117            return self.expression(exp.RangeN, this=this, expressions=expressions, each=each)
    118
    119    class Generator(generator.Generator):
    120        TYPE_MAPPING = {
    121            **generator.Generator.TYPE_MAPPING,  # type: ignore
    122            exp.DataType.Type.GEOMETRY: "ST_GEOMETRY",
    123        }
    124
    125        PROPERTIES_LOCATION = {
    126            **generator.Generator.PROPERTIES_LOCATION,  # type: ignore
    127            exp.PartitionedByProperty: exp.Properties.Location.POST_INDEX,
    128        }
    129
    130        TRANSFORMS = {
    131            **generator.Generator.TRANSFORMS,
    132            exp.Min: min_or_least,
    133            exp.ToChar: lambda self, e: self.function_fallback_sql(e),
    134        }
    135
    136        def partitionedbyproperty_sql(self, expression: exp.PartitionedByProperty) -> str:
    137            return f"PARTITION BY {self.sql(expression, 'this')}"
    138
    139        # FROM before SET in Teradata UPDATE syntax
    140        # 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
    141        def update_sql(self, expression: exp.Update) -> str:
    142            this = self.sql(expression, "this")
    143            from_sql = self.sql(expression, "from")
    144            set_sql = self.expressions(expression, flat=True)
    145            where_sql = self.sql(expression, "where")
    146            sql = f"UPDATE {this}{from_sql} SET {set_sql}{where_sql}"
    147            return self.prepend_ctes(expression, sql)
    148
    149        def mod_sql(self, expression: exp.Mod) -> str:
    150            return self.binary(expression, "MOD")
    151
    152        def datatype_sql(self, expression: exp.DataType) -> str:
    153            type_sql = super().datatype_sql(expression)
    154            prefix_sql = expression.args.get("prefix")
    155            return f"SYSUDTLIB.{type_sql}" if prefix_sql else type_sql
    156
    157        def rangen_sql(self, expression: exp.RangeN) -> str:
    158            this = self.sql(expression, "this")
    159            expressions_sql = self.expressions(expression)
    160            each_sql = self.sql(expression, "each")
    161            each_sql = f" EACH {each_sql}" if each_sql else ""
    162
    163            return f"RANGE_N({this} BETWEEN {expressions_sql}{each_sql})"

##### Inherited Members

sqlglot.dialects.dialect.Dialect
  get_or_raise
  format_time
  parse
  parse_into
  generate
  transpile
  tokenize
  parser
  generator

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

    10    class Tokenizer(tokens.Tokenizer):
    11        # https://docs.teradata.com/r/Teradata-Database-SQL-Functions-Operators-Expressions-and-Predicates/March-2017/Comparison-Operators-and-Functions/Comparison-Operators/ANSI-Compliance
    12        KEYWORDS = {
    13            **tokens.Tokenizer.KEYWORDS,
    14            "BYTEINT": TokenType.SMALLINT,
    15            "SEL": TokenType.SELECT,
    16            "INS": TokenType.INSERT,
    17            "MOD": TokenType.MOD,
    18            "LT": TokenType.LT,
    19            "LE": TokenType.LTE,
    20            "GT": TokenType.GT,
    21            "GE": TokenType.GTE,
    22            "^=": TokenType.NEQ,
    23            "NE": TokenType.NEQ,
    24            "NOT=": TokenType.NEQ,
    25            "ST_GEOMETRY": TokenType.GEOMETRY,
    26        }
    27
    28        # teradata does not support % for modulus
    29        SINGLE_TOKENS = {**tokens.Tokenizer.SINGLE_TOKENS}
    30        SINGLE_TOKENS.pop("%")

##### Inherited Members

sqlglot.tokens.Tokenizer
  reset
  tokenize

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

     32    class Parser(parser.Parser):
     33        CHARSET_TRANSLATORS = {
     34            "GRAPHIC_TO_KANJISJIS",
     35            "GRAPHIC_TO_LATIN",
     36            "GRAPHIC_TO_UNICODE",
     37            "GRAPHIC_TO_UNICODE_PadSpace",
     38            "KANJI1_KanjiEBCDIC_TO_UNICODE",
     39            "KANJI1_KanjiEUC_TO_UNICODE",
     40            "KANJI1_KANJISJIS_TO_UNICODE",
     41            "KANJI1_SBC_TO_UNICODE",
     42            "KANJISJIS_TO_GRAPHIC",
     43            "KANJISJIS_TO_LATIN",
     44            "KANJISJIS_TO_UNICODE",
     45            "LATIN_TO_GRAPHIC",
     46            "LATIN_TO_KANJISJIS",
     47            "LATIN_TO_UNICODE",
     48            "LOCALE_TO_UNICODE",
     49            "UNICODE_TO_GRAPHIC",
     50            "UNICODE_TO_GRAPHIC_PadGraphic",
     51            "UNICODE_TO_GRAPHIC_VarGraphic",
     52            "UNICODE_TO_KANJI1_KanjiEBCDIC",
     53            "UNICODE_TO_KANJI1_KanjiEUC",
     54            "UNICODE_TO_KANJI1_KANJISJIS",
     55            "UNICODE_TO_KANJI1_SBC",
     56            "UNICODE_TO_KANJISJIS",
     57            "UNICODE_TO_LATIN",
     58            "UNICODE_TO_LOCALE",
     59            "UNICODE_TO_UNICODE_FoldSpace",
     60            "UNICODE_TO_UNICODE_Fullwidth",
     61            "UNICODE_TO_UNICODE_Halfwidth",
     62            "UNICODE_TO_UNICODE_NFC",
     63            "UNICODE_TO_UNICODE_NFD",
     64            "UNICODE_TO_UNICODE_NFKC",
     65            "UNICODE_TO_UNICODE_NFKD",
     66        }
     67
     68        FUNC_TOKENS = {*parser.Parser.FUNC_TOKENS}
     69        FUNC_TOKENS.remove(TokenType.REPLACE)
     70
     71        STATEMENT_PARSERS = {
     72            **parser.Parser.STATEMENT_PARSERS,  # type: ignore
     73            TokenType.REPLACE: lambda self: self._parse_create(),
     74        }
     75
     76        FUNCTION_PARSERS = {
     77            **parser.Parser.FUNCTION_PARSERS,  # type: ignore
     78            "RANGE_N": lambda self: self._parse_rangen(),
     79            "TRANSLATE": lambda self: self._parse_translate(self.STRICT_CAST),
     80        }
     81
     82        def _parse_translate(self, strict: bool) -> exp.Expression:
     83            this = self._parse_conjunction()
     84
     85            if not self._match(TokenType.USING):
     86                self.raise_error("Expected USING in TRANSLATE")
     87
     88            if self._match_texts(self.CHARSET_TRANSLATORS):
     89                charset_split = self._prev.text.split("_TO_")
     90                to = self.expression(exp.CharacterSet, this=charset_split[1])
     91            else:
     92                self.raise_error("Expected a character set translator after USING in TRANSLATE")
     93
     94            return self.expression(exp.Cast if strict else exp.TryCast, this=this, to=to)
     95
     96        # FROM before SET in Teradata UPDATE syntax
     97        # 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
     98        def _parse_update(self) -> exp.Expression:
     99            return self.expression(
    100                exp.Update,
    101                **{  # type: ignore
    102                    "this": self._parse_table(alias_tokens=self.UPDATE_ALIAS_TOKENS),
    103                    "from": self._parse_from(),
    104                    "expressions": self._match(TokenType.SET)
    105                    and self._parse_csv(self._parse_equality),
    106                    "where": self._parse_where(),
    107                },
    108            )
    109
    110        def _parse_rangen(self):
    111            this = self._parse_id_var()
    112            self._match(TokenType.BETWEEN)
    113
    114            expressions = self._parse_csv(self._parse_conjunction)
    115            each = self._match_text_seq("EACH") and self._parse_conjunction()
    116
    117            return self.expression(exp.RangeN, this=this, expressions=expressions, each=each)

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

###### Arguments:

- error_level: the desired error level. Default: ErrorLevel.RAISE
- error_message_context: determines the amount of context to capture from a query string when displaying the error message (in number of characters). Default: 50.
- index_offset: Index offset for arrays eg ARRAY[0] vs ARRAY[1] as the head of a list. Default: 0
- alias_post_tablesample: If the table alias comes after tablesample. Default: False
- 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
- null_ordering: Indicates the default null ordering method to use if not explicitly set. Options are "nulls_are_small", "nulls_are_large", "nulls_are_last". Default: "nulls_are_small"

##### Inherited Members

sqlglot.parser.Parser
  Parser
  reset
  parse
  parse_into
  check_errors
  raise_error
  expression
  validate_expression

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

    119    class Generator(generator.Generator):
    120        TYPE_MAPPING = {
    121            **generator.Generator.TYPE_MAPPING,  # type: ignore
    122            exp.DataType.Type.GEOMETRY: "ST_GEOMETRY",
    123        }
    124
    125        PROPERTIES_LOCATION = {
    126            **generator.Generator.PROPERTIES_LOCATION,  # type: ignore
    127            exp.PartitionedByProperty: exp.Properties.Location.POST_INDEX,
    128        }
    129
    130        TRANSFORMS = {
    131            **generator.Generator.TRANSFORMS,
    132            exp.Min: min_or_least,
    133            exp.ToChar: lambda self, e: self.function_fallback_sql(e),
    134        }
    135
    136        def partitionedbyproperty_sql(self, expression: exp.PartitionedByProperty) -> str:
    137            return f"PARTITION BY {self.sql(expression, 'this')}"
    138
    139        # FROM before SET in Teradata UPDATE syntax
    140        # 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
    141        def update_sql(self, expression: exp.Update) -> str:
    142            this = self.sql(expression, "this")
    143            from_sql = self.sql(expression, "from")
    144            set_sql = self.expressions(expression, flat=True)
    145            where_sql = self.sql(expression, "where")
    146            sql = f"UPDATE {this}{from_sql} SET {set_sql}{where_sql}"
    147            return self.prepend_ctes(expression, sql)
    148
    149        def mod_sql(self, expression: exp.Mod) -> str:
    150            return self.binary(expression, "MOD")
    151
    152        def datatype_sql(self, expression: exp.DataType) -> str:
    153            type_sql = super().datatype_sql(expression)
    154            prefix_sql = expression.args.get("prefix")
    155            return f"SYSUDTLIB.{type_sql}" if prefix_sql else type_sql
    156
    157        def rangen_sql(self, expression: exp.RangeN) -> str:
    158            this = self.sql(expression, "this")
    159            expressions_sql = self.expressions(expression)
    160            each_sql = self.sql(expression, "each")
    161            each_sql = f" EACH {each_sql}" if each_sql else ""
    162
    163            return f"RANGE_N({this} BETWEEN {expressions_sql}{each_sql})"

Generator interprets the given syntax tree and produces a SQL string as an output.

###### Arguments:

- time_mapping (dict): the dictionary of custom time mappings in which the key represents a python time format and the output the target time format
- time_trie (trie): a trie of the time_mapping keys
- pretty (bool): if set to True the returned string will be formatted. Default: False.
- quote_start (str): specifies which starting character to use to delimit quotes. Default: '.
- quote_end (str): specifies which ending character to use to delimit quotes. Default: '.
- identifier_start (str): specifies which starting character to use to delimit identifiers. Default: ".
- identifier_end (str): specifies which ending character to use to delimit identifiers. Default: ".
- identify (bool | str): 'always': always quote, 'safe': quote identifiers if they don't contain an upcase, True defaults to always.
- normalize (bool): if set to True all identifiers will lower cased
- string_escape (str): specifies a string escape character. Default: '.
- identifier_escape (str): specifies an identifier escape character. Default: ".
- pad (int): determines padding in a formatted string. Default: 2.
- indent (int): determines the size of indentation in a formatted string. Default: 4.
- unnest_column_only (bool): if true unnest table aliases are considered only as column aliases
- normalize_functions (str): normalize function names, "upper", "lower", or None Default: "upper"
- alias_post_tablesample (bool): if the table alias comes after tablesample Default: False
- unsupported_level (ErrorLevel): determines the generator's behavior when it encounters unsupported expressions. Default ErrorLevel.WARN.
- null_ordering (str): Indicates the default null ordering method to use if not explicitly set. Options are "nulls_are_small", "nulls_are_large", "nulls_are_last". Default: "nulls_are_small"
- max_unsupported (int): 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 (bool): if the the comma is leading or trailing in select statements 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

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

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

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

    141        def update_sql(self, expression: exp.Update) -> str:
    142            this = self.sql(expression, "this")
    143            from_sql = self.sql(expression, "from")
    144            set_sql = self.expressions(expression, flat=True)
    145            where_sql = self.sql(expression, "where")
    146            sql = f"UPDATE {this}{from_sql} SET {set_sql}{where_sql}"
    147            return self.prepend_ctes(expression, sql)

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

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

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

    152        def datatype_sql(self, expression: exp.DataType) -> str:
    153            type_sql = super().datatype_sql(expression)
    154            prefix_sql = expression.args.get("prefix")
    155            return f"SYSUDTLIB.{type_sql}" if prefix_sql else type_sql

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

    157        def rangen_sql(self, expression: exp.RangeN) -> str:
    158            this = self.sql(expression, "this")
    159            expressions_sql = self.expressions(expression)
    160            each_sql = self.sql(expression, "each")
    161            each_sql = f" EACH {each_sql}" if each_sql else ""
    162
    163            return f"RANGE_N({this} BETWEEN {expressions_sql}{each_sql})"

##### Inherited Members

sqlglot.generator.Generator
  Generator
  generate
  unsupported
  sep
  seg
  pad_comment
  maybe_comment
  wrap
  no_identify
  normalize_func
  indent
  sql
  uncache_sql
  cache_sql
  characterset_sql
  column_sql
  columndef_sql
  columnconstraint_sql
  autoincrementcolumnconstraint_sql
  compresscolumnconstraint_sql
  generatedasidentitycolumnconstraint_sql
  notnullcolumnconstraint_sql
  primarykeycolumnconstraint_sql
  uniquecolumnconstraint_sql
  create_sql
  describe_sql
  prepend_ctes
  with_sql
  cte_sql
  tablealias_sql
  bitstring_sql
  hexstring_sql
  directory_sql
  delete_sql
  drop_sql
  except_sql
  except_op
  fetch_sql
  filter_sql
  hint_sql
  index_sql
  identifier_sql
  national_sql
  partition_sql
  properties_sql
  root_properties
  properties
  with_properties
  locate_properties
  property_sql
  likeproperty_sql
  fallbackproperty_sql
  journalproperty_sql
  freespaceproperty_sql
  afterjournalproperty_sql
  checksumproperty_sql
  mergeblockratioproperty_sql
  datablocksizeproperty_sql
  blockcompressionproperty_sql
  isolatedloadingproperty_sql
  lockingproperty_sql
  withdataproperty_sql
  insert_sql
  intersect_sql
  intersect_op
  introducer_sql
  pseudotype_sql
  returning_sql
  rowformatdelimitedproperty_sql
  table_sql
  tablesample_sql
  pivot_sql
  tuple_sql
  values_sql
  var_sql
  into_sql
  from_sql
  group_sql
  having_sql
  join_sql
  lambda_sql
  lateral_sql
  limit_sql
  offset_sql
  setitem_sql
  set_sql
  lock_sql
  literal_sql
  loaddata_sql
  null_sql
  boolean_sql
  order_sql
  cluster_sql
  distribute_sql
  sort_sql
  ordered_sql
  matchrecognize_sql
  query_modifiers
  select_sql
  schema_sql
  star_sql
  structkwarg_sql
  parameter_sql
  sessionparameter_sql
  placeholder_sql
  subquery_sql
  qualify_sql
  union_sql
  union_op
  unnest_sql
  where_sql
  window_sql
  partition_by_sql
  window_spec_sql
  withingroup_sql
  between_sql
  bracket_sql
  all_sql
  any_sql
  exists_sql
  case_sql
  constraint_sql
  extract_sql
  trim_sql
  concat_sql
  check_sql
  foreignkey_sql
  primarykey_sql
  unique_sql
  if_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
  connector_sql
  bitwiseand_sql
  bitwiseleftshift_sql
  bitwisenot_sql
  bitwiseor_sql
  bitwiserightshift_sql
  bitwisexor_sql
  cast_sql
  currentdate_sql
  collate_sql
  command_sql
  comment_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
  div_sql
  overlaps_sql
  distance_sql
  dot_sql
  eq_sql
  escape_sql
  glob_sql
  gt_sql
  gte_sql
  ilike_sql
  is_sql
  like_sql
  similarto_sql
  lt_sql
  lte_sql
  mul_sql
  neq_sql
  nullsafeeq_sql
  nullsafeneq_sql
  or_sql
  slice_sql
  sub_sql
  trycast_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