Edit on GitHub

# sqlglot.dialects.oracle

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, no_ilike_sql, rename_func, trim_sql
      7from sqlglot.helper import seq_get
      8from sqlglot.tokens import TokenType
      9
     10
     11def _parse_xml_table(self) -> exp.XMLTable:
     12    this = self._parse_string()
     13
     14    passing = None
     15    columns = None
     16
     17    if self._match_text_seq("PASSING"):
     18        # The BY VALUE keywords are optional and are provided for semantic clarity
     19        self._match_text_seq("BY", "VALUE")
     20        passing = self._parse_csv(self._parse_column)
     21
     22    by_ref = self._match_text_seq("RETURNING", "SEQUENCE", "BY", "REF")
     23
     24    if self._match_text_seq("COLUMNS"):
     25        columns = self._parse_csv(lambda: self._parse_column_def(self._parse_field(any_token=True)))
     26
     27    return self.expression(
     28        exp.XMLTable,
     29        this=this,
     30        passing=passing,
     31        columns=columns,
     32        by_ref=by_ref,
     33    )
     34
     35
     36class Oracle(Dialect):
     37    alias_post_tablesample = True
     38
     39    # https://docs.oracle.com/database/121/SQLRF/sql_elements004.htm#SQLRF00212
     40    # https://docs.python.org/3/library/datetime.html#strftime-and-strptime-format-codes
     41    time_mapping = {
     42        "AM": "%p",  # Meridian indicator with or without periods
     43        "A.M.": "%p",  # Meridian indicator with or without periods
     44        "PM": "%p",  # Meridian indicator with or without periods
     45        "P.M.": "%p",  # Meridian indicator with or without periods
     46        "D": "%u",  # Day of week (1-7)
     47        "DAY": "%A",  # name of day
     48        "DD": "%d",  # day of month (1-31)
     49        "DDD": "%j",  # day of year (1-366)
     50        "DY": "%a",  # abbreviated name of day
     51        "HH": "%I",  # Hour of day (1-12)
     52        "HH12": "%I",  # alias for HH
     53        "HH24": "%H",  # Hour of day (0-23)
     54        "IW": "%V",  # Calendar week of year (1-52 or 1-53), as defined by the ISO 8601 standard
     55        "MI": "%M",  # Minute (0-59)
     56        "MM": "%m",  # Month (01-12; January = 01)
     57        "MON": "%b",  # Abbreviated name of month
     58        "MONTH": "%B",  # Name of month
     59        "SS": "%S",  # Second (0-59)
     60        "WW": "%W",  # Week of year (1-53)
     61        "YY": "%y",  # 15
     62        "YYYY": "%Y",  # 2015
     63    }
     64
     65    class Parser(parser.Parser):
     66        WINDOW_BEFORE_PAREN_TOKENS = {TokenType.OVER, TokenType.KEEP}
     67
     68        FUNCTIONS = {
     69            **parser.Parser.FUNCTIONS,  # type: ignore
     70            "SQUARE": lambda args: exp.Pow(this=seq_get(args, 0), expression=exp.Literal.number(2)),
     71        }
     72
     73        FUNCTION_PARSERS: t.Dict[str, t.Callable] = {
     74            **parser.Parser.FUNCTION_PARSERS,
     75            "XMLTABLE": _parse_xml_table,
     76        }
     77
     78        TYPE_LITERAL_PARSERS = {
     79            exp.DataType.Type.DATE: lambda self, this, _: self.expression(
     80                exp.DateStrToDate, this=this
     81            )
     82        }
     83
     84        def _parse_column(self) -> t.Optional[exp.Expression]:
     85            column = super()._parse_column()
     86            if column:
     87                column.set("join_mark", self._match(TokenType.JOIN_MARKER))
     88            return column
     89
     90        def _parse_hint(self) -> t.Optional[exp.Expression]:
     91            if self._match(TokenType.HINT):
     92                start = self._curr
     93                while self._curr and not self._match_pair(TokenType.STAR, TokenType.SLASH):
     94                    self._advance()
     95
     96                if not self._curr:
     97                    self.raise_error("Expected */ after HINT")
     98
     99                end = self._tokens[self._index - 3]
    100                return exp.Hint(expressions=[self._find_sql(start, end)])
    101
    102            return None
    103
    104    class Generator(generator.Generator):
    105        LOCKING_READS_SUPPORTED = True
    106        JOIN_HINTS = False
    107        TABLE_HINTS = False
    108
    109        TYPE_MAPPING = {
    110            **generator.Generator.TYPE_MAPPING,  # type: ignore
    111            exp.DataType.Type.TINYINT: "NUMBER",
    112            exp.DataType.Type.SMALLINT: "NUMBER",
    113            exp.DataType.Type.INT: "NUMBER",
    114            exp.DataType.Type.BIGINT: "NUMBER",
    115            exp.DataType.Type.DECIMAL: "NUMBER",
    116            exp.DataType.Type.DOUBLE: "DOUBLE PRECISION",
    117            exp.DataType.Type.VARCHAR: "VARCHAR2",
    118            exp.DataType.Type.NVARCHAR: "NVARCHAR2",
    119            exp.DataType.Type.TEXT: "CLOB",
    120            exp.DataType.Type.BINARY: "BLOB",
    121            exp.DataType.Type.VARBINARY: "BLOB",
    122        }
    123
    124        TRANSFORMS = {
    125            **generator.Generator.TRANSFORMS,  # type: ignore
    126            exp.DateStrToDate: lambda self, e: self.func(
    127                "TO_DATE", e.this, exp.Literal.string("YYYY-MM-DD")
    128            ),
    129            exp.Group: transforms.preprocess([transforms.unalias_group]),
    130            exp.Hint: lambda self, e: f" /*+ {self.expressions(e).strip()} */",
    131            exp.ILike: no_ilike_sql,
    132            exp.IfNull: rename_func("NVL"),
    133            exp.Select: transforms.preprocess([transforms.eliminate_distinct_on]),
    134            exp.StrToTime: lambda self, e: f"TO_TIMESTAMP({self.sql(e, 'this')}, {self.format_time(e)})",
    135            exp.Subquery: lambda self, e: self.subquery_sql(e, sep=" "),
    136            exp.Substring: rename_func("SUBSTR"),
    137            exp.Table: lambda self, e: self.table_sql(e, sep=" "),
    138            exp.TableSample: lambda self, e: self.tablesample_sql(e, sep=" "),
    139            exp.TimeToStr: lambda self, e: f"TO_CHAR({self.sql(e, 'this')}, {self.format_time(e)})",
    140            exp.ToChar: lambda self, e: self.function_fallback_sql(e),
    141            exp.Trim: trim_sql,
    142            exp.UnixToTime: lambda self, e: f"TO_DATE('1970-01-01','YYYY-MM-DD') + ({self.sql(e, 'this')} / 86400)",
    143        }
    144
    145        PROPERTIES_LOCATION = {
    146            **generator.Generator.PROPERTIES_LOCATION,  # type: ignore
    147            exp.VolatileProperty: exp.Properties.Location.UNSUPPORTED,
    148        }
    149
    150        LIMIT_FETCH = "FETCH"
    151
    152        def offset_sql(self, expression: exp.Offset) -> str:
    153            return f"{super().offset_sql(expression)} ROWS"
    154
    155        def column_sql(self, expression: exp.Column) -> str:
    156            column = super().column_sql(expression)
    157            return f"{column} (+)" if expression.args.get("join_mark") else column
    158
    159        def xmltable_sql(self, expression: exp.XMLTable) -> str:
    160            this = self.sql(expression, "this")
    161            passing = self.expressions(expression, key="passing")
    162            passing = f"{self.sep()}PASSING{self.seg(passing)}" if passing else ""
    163            columns = self.expressions(expression, key="columns")
    164            columns = f"{self.sep()}COLUMNS{self.seg(columns)}" if columns else ""
    165            by_ref = (
    166                f"{self.sep()}RETURNING SEQUENCE BY REF" if expression.args.get("by_ref") else ""
    167            )
    168            return f"XMLTABLE({self.sep('')}{self.indent(this + passing + by_ref + columns)}{self.seg(')', sep='')}"
    169
    170    class Tokenizer(tokens.Tokenizer):
    171        VAR_SINGLE_TOKENS = {"@"}
    172
    173        KEYWORDS = {
    174            **tokens.Tokenizer.KEYWORDS,
    175            "(+)": TokenType.JOIN_MARKER,
    176            "BINARY_DOUBLE": TokenType.DOUBLE,
    177            "BINARY_FLOAT": TokenType.FLOAT,
    178            "COLUMNS": TokenType.COLUMN,
    179            "MATCH_RECOGNIZE": TokenType.MATCH_RECOGNIZE,
    180            "MINUS": TokenType.EXCEPT,
    181            "NVARCHAR2": TokenType.NVARCHAR,
    182            "RETURNING": TokenType.RETURNING,
    183            "SAMPLE": TokenType.TABLE_SAMPLE,
    184            "START": TokenType.BEGIN,
    185            "TOP": TokenType.TOP,
    186            "VARCHAR2": TokenType.VARCHAR,
    187        }

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

     37class Oracle(Dialect):
     38    alias_post_tablesample = True
     39
     40    # https://docs.oracle.com/database/121/SQLRF/sql_elements004.htm#SQLRF00212
     41    # https://docs.python.org/3/library/datetime.html#strftime-and-strptime-format-codes
     42    time_mapping = {
     43        "AM": "%p",  # Meridian indicator with or without periods
     44        "A.M.": "%p",  # Meridian indicator with or without periods
     45        "PM": "%p",  # Meridian indicator with or without periods
     46        "P.M.": "%p",  # Meridian indicator with or without periods
     47        "D": "%u",  # Day of week (1-7)
     48        "DAY": "%A",  # name of day
     49        "DD": "%d",  # day of month (1-31)
     50        "DDD": "%j",  # day of year (1-366)
     51        "DY": "%a",  # abbreviated name of day
     52        "HH": "%I",  # Hour of day (1-12)
     53        "HH12": "%I",  # alias for HH
     54        "HH24": "%H",  # Hour of day (0-23)
     55        "IW": "%V",  # Calendar week of year (1-52 or 1-53), as defined by the ISO 8601 standard
     56        "MI": "%M",  # Minute (0-59)
     57        "MM": "%m",  # Month (01-12; January = 01)
     58        "MON": "%b",  # Abbreviated name of month
     59        "MONTH": "%B",  # Name of month
     60        "SS": "%S",  # Second (0-59)
     61        "WW": "%W",  # Week of year (1-53)
     62        "YY": "%y",  # 15
     63        "YYYY": "%Y",  # 2015
     64    }
     65
     66    class Parser(parser.Parser):
     67        WINDOW_BEFORE_PAREN_TOKENS = {TokenType.OVER, TokenType.KEEP}
     68
     69        FUNCTIONS = {
     70            **parser.Parser.FUNCTIONS,  # type: ignore
     71            "SQUARE": lambda args: exp.Pow(this=seq_get(args, 0), expression=exp.Literal.number(2)),
     72        }
     73
     74        FUNCTION_PARSERS: t.Dict[str, t.Callable] = {
     75            **parser.Parser.FUNCTION_PARSERS,
     76            "XMLTABLE": _parse_xml_table,
     77        }
     78
     79        TYPE_LITERAL_PARSERS = {
     80            exp.DataType.Type.DATE: lambda self, this, _: self.expression(
     81                exp.DateStrToDate, this=this
     82            )
     83        }
     84
     85        def _parse_column(self) -> t.Optional[exp.Expression]:
     86            column = super()._parse_column()
     87            if column:
     88                column.set("join_mark", self._match(TokenType.JOIN_MARKER))
     89            return column
     90
     91        def _parse_hint(self) -> t.Optional[exp.Expression]:
     92            if self._match(TokenType.HINT):
     93                start = self._curr
     94                while self._curr and not self._match_pair(TokenType.STAR, TokenType.SLASH):
     95                    self._advance()
     96
     97                if not self._curr:
     98                    self.raise_error("Expected */ after HINT")
     99
    100                end = self._tokens[self._index - 3]
    101                return exp.Hint(expressions=[self._find_sql(start, end)])
    102
    103            return None
    104
    105    class Generator(generator.Generator):
    106        LOCKING_READS_SUPPORTED = True
    107        JOIN_HINTS = False
    108        TABLE_HINTS = False
    109
    110        TYPE_MAPPING = {
    111            **generator.Generator.TYPE_MAPPING,  # type: ignore
    112            exp.DataType.Type.TINYINT: "NUMBER",
    113            exp.DataType.Type.SMALLINT: "NUMBER",
    114            exp.DataType.Type.INT: "NUMBER",
    115            exp.DataType.Type.BIGINT: "NUMBER",
    116            exp.DataType.Type.DECIMAL: "NUMBER",
    117            exp.DataType.Type.DOUBLE: "DOUBLE PRECISION",
    118            exp.DataType.Type.VARCHAR: "VARCHAR2",
    119            exp.DataType.Type.NVARCHAR: "NVARCHAR2",
    120            exp.DataType.Type.TEXT: "CLOB",
    121            exp.DataType.Type.BINARY: "BLOB",
    122            exp.DataType.Type.VARBINARY: "BLOB",
    123        }
    124
    125        TRANSFORMS = {
    126            **generator.Generator.TRANSFORMS,  # type: ignore
    127            exp.DateStrToDate: lambda self, e: self.func(
    128                "TO_DATE", e.this, exp.Literal.string("YYYY-MM-DD")
    129            ),
    130            exp.Group: transforms.preprocess([transforms.unalias_group]),
    131            exp.Hint: lambda self, e: f" /*+ {self.expressions(e).strip()} */",
    132            exp.ILike: no_ilike_sql,
    133            exp.IfNull: rename_func("NVL"),
    134            exp.Select: transforms.preprocess([transforms.eliminate_distinct_on]),
    135            exp.StrToTime: lambda self, e: f"TO_TIMESTAMP({self.sql(e, 'this')}, {self.format_time(e)})",
    136            exp.Subquery: lambda self, e: self.subquery_sql(e, sep=" "),
    137            exp.Substring: rename_func("SUBSTR"),
    138            exp.Table: lambda self, e: self.table_sql(e, sep=" "),
    139            exp.TableSample: lambda self, e: self.tablesample_sql(e, sep=" "),
    140            exp.TimeToStr: lambda self, e: f"TO_CHAR({self.sql(e, 'this')}, {self.format_time(e)})",
    141            exp.ToChar: lambda self, e: self.function_fallback_sql(e),
    142            exp.Trim: trim_sql,
    143            exp.UnixToTime: lambda self, e: f"TO_DATE('1970-01-01','YYYY-MM-DD') + ({self.sql(e, 'this')} / 86400)",
    144        }
    145
    146        PROPERTIES_LOCATION = {
    147            **generator.Generator.PROPERTIES_LOCATION,  # type: ignore
    148            exp.VolatileProperty: exp.Properties.Location.UNSUPPORTED,
    149        }
    150
    151        LIMIT_FETCH = "FETCH"
    152
    153        def offset_sql(self, expression: exp.Offset) -> str:
    154            return f"{super().offset_sql(expression)} ROWS"
    155
    156        def column_sql(self, expression: exp.Column) -> str:
    157            column = super().column_sql(expression)
    158            return f"{column} (+)" if expression.args.get("join_mark") else column
    159
    160        def xmltable_sql(self, expression: exp.XMLTable) -> str:
    161            this = self.sql(expression, "this")
    162            passing = self.expressions(expression, key="passing")
    163            passing = f"{self.sep()}PASSING{self.seg(passing)}" if passing else ""
    164            columns = self.expressions(expression, key="columns")
    165            columns = f"{self.sep()}COLUMNS{self.seg(columns)}" if columns else ""
    166            by_ref = (
    167                f"{self.sep()}RETURNING SEQUENCE BY REF" if expression.args.get("by_ref") else ""
    168            )
    169            return f"XMLTABLE({self.sep('')}{self.indent(this + passing + by_ref + columns)}{self.seg(')', sep='')}"
    170
    171    class Tokenizer(tokens.Tokenizer):
    172        VAR_SINGLE_TOKENS = {"@"}
    173
    174        KEYWORDS = {
    175            **tokens.Tokenizer.KEYWORDS,
    176            "(+)": TokenType.JOIN_MARKER,
    177            "BINARY_DOUBLE": TokenType.DOUBLE,
    178            "BINARY_FLOAT": TokenType.FLOAT,
    179            "COLUMNS": TokenType.COLUMN,
    180            "MATCH_RECOGNIZE": TokenType.MATCH_RECOGNIZE,
    181            "MINUS": TokenType.EXCEPT,
    182            "NVARCHAR2": TokenType.NVARCHAR,
    183            "RETURNING": TokenType.RETURNING,
    184            "SAMPLE": TokenType.TABLE_SAMPLE,
    185            "START": TokenType.BEGIN,
    186            "TOP": TokenType.TOP,
    187            "VARCHAR2": TokenType.VARCHAR,
    188        }

##### Inherited Members

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

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

     66    class Parser(parser.Parser):
     67        WINDOW_BEFORE_PAREN_TOKENS = {TokenType.OVER, TokenType.KEEP}
     68
     69        FUNCTIONS = {
     70            **parser.Parser.FUNCTIONS,  # type: ignore
     71            "SQUARE": lambda args: exp.Pow(this=seq_get(args, 0), expression=exp.Literal.number(2)),
     72        }
     73
     74        FUNCTION_PARSERS: t.Dict[str, t.Callable] = {
     75            **parser.Parser.FUNCTION_PARSERS,
     76            "XMLTABLE": _parse_xml_table,
     77        }
     78
     79        TYPE_LITERAL_PARSERS = {
     80            exp.DataType.Type.DATE: lambda self, this, _: self.expression(
     81                exp.DateStrToDate, this=this
     82            )
     83        }
     84
     85        def _parse_column(self) -> t.Optional[exp.Expression]:
     86            column = super()._parse_column()
     87            if column:
     88                column.set("join_mark", self._match(TokenType.JOIN_MARKER))
     89            return column
     90
     91        def _parse_hint(self) -> t.Optional[exp.Expression]:
     92            if self._match(TokenType.HINT):
     93                start = self._curr
     94                while self._curr and not self._match_pair(TokenType.STAR, TokenType.SLASH):
     95                    self._advance()
     96
     97                if not self._curr:
     98                    self.raise_error("Expected */ after HINT")
     99
    100                end = self._tokens[self._index - 3]
    101                return exp.Hint(expressions=[self._find_sql(start, end)])
    102
    103            return None

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 Oracle.Generator(sqlglot.generator.Generator): View Source

    105    class Generator(generator.Generator):
    106        LOCKING_READS_SUPPORTED = True
    107        JOIN_HINTS = False
    108        TABLE_HINTS = False
    109
    110        TYPE_MAPPING = {
    111            **generator.Generator.TYPE_MAPPING,  # type: ignore
    112            exp.DataType.Type.TINYINT: "NUMBER",
    113            exp.DataType.Type.SMALLINT: "NUMBER",
    114            exp.DataType.Type.INT: "NUMBER",
    115            exp.DataType.Type.BIGINT: "NUMBER",
    116            exp.DataType.Type.DECIMAL: "NUMBER",
    117            exp.DataType.Type.DOUBLE: "DOUBLE PRECISION",
    118            exp.DataType.Type.VARCHAR: "VARCHAR2",
    119            exp.DataType.Type.NVARCHAR: "NVARCHAR2",
    120            exp.DataType.Type.TEXT: "CLOB",
    121            exp.DataType.Type.BINARY: "BLOB",
    122            exp.DataType.Type.VARBINARY: "BLOB",
    123        }
    124
    125        TRANSFORMS = {
    126            **generator.Generator.TRANSFORMS,  # type: ignore
    127            exp.DateStrToDate: lambda self, e: self.func(
    128                "TO_DATE", e.this, exp.Literal.string("YYYY-MM-DD")
    129            ),
    130            exp.Group: transforms.preprocess([transforms.unalias_group]),
    131            exp.Hint: lambda self, e: f" /*+ {self.expressions(e).strip()} */",
    132            exp.ILike: no_ilike_sql,
    133            exp.IfNull: rename_func("NVL"),
    134            exp.Select: transforms.preprocess([transforms.eliminate_distinct_on]),
    135            exp.StrToTime: lambda self, e: f"TO_TIMESTAMP({self.sql(e, 'this')}, {self.format_time(e)})",
    136            exp.Subquery: lambda self, e: self.subquery_sql(e, sep=" "),
    137            exp.Substring: rename_func("SUBSTR"),
    138            exp.Table: lambda self, e: self.table_sql(e, sep=" "),
    139            exp.TableSample: lambda self, e: self.tablesample_sql(e, sep=" "),
    140            exp.TimeToStr: lambda self, e: f"TO_CHAR({self.sql(e, 'this')}, {self.format_time(e)})",
    141            exp.ToChar: lambda self, e: self.function_fallback_sql(e),
    142            exp.Trim: trim_sql,
    143            exp.UnixToTime: lambda self, e: f"TO_DATE('1970-01-01','YYYY-MM-DD') + ({self.sql(e, 'this')} / 86400)",
    144        }
    145
    146        PROPERTIES_LOCATION = {
    147            **generator.Generator.PROPERTIES_LOCATION,  # type: ignore
    148            exp.VolatileProperty: exp.Properties.Location.UNSUPPORTED,
    149        }
    150
    151        LIMIT_FETCH = "FETCH"
    152
    153        def offset_sql(self, expression: exp.Offset) -> str:
    154            return f"{super().offset_sql(expression)} ROWS"
    155
    156        def column_sql(self, expression: exp.Column) -> str:
    157            column = super().column_sql(expression)
    158            return f"{column} (+)" if expression.args.get("join_mark") else column
    159
    160        def xmltable_sql(self, expression: exp.XMLTable) -> str:
    161            this = self.sql(expression, "this")
    162            passing = self.expressions(expression, key="passing")
    163            passing = f"{self.sep()}PASSING{self.seg(passing)}" if passing else ""
    164            columns = self.expressions(expression, key="columns")
    165            columns = f"{self.sep()}COLUMNS{self.seg(columns)}" if columns else ""
    166            by_ref = (
    167                f"{self.sep()}RETURNING SEQUENCE BY REF" if expression.args.get("by_ref") else ""
    168            )
    169            return f"XMLTABLE({self.sep('')}{self.indent(this + passing + by_ref + columns)}{self.seg(')', sep='')}"

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 offset_sql(self, expression: sqlglot.expressions.Offset) -> str: View Source

    153        def offset_sql(self, expression: exp.Offset) -> str:
    154            return f"{super().offset_sql(expression)} ROWS"

def column_sql(self, expression: sqlglot.expressions.Column) -> str: View Source

    156        def column_sql(self, expression: exp.Column) -> str:
    157            column = super().column_sql(expression)
    158            return f"{column} (+)" if expression.args.get("join_mark") else column

def xmltable_sql(self, expression: sqlglot.expressions.XMLTable) -> str: View Source

    160        def xmltable_sql(self, expression: exp.XMLTable) -> str:
    161            this = self.sql(expression, "this")
    162            passing = self.expressions(expression, key="passing")
    163            passing = f"{self.sep()}PASSING{self.seg(passing)}" if passing else ""
    164            columns = self.expressions(expression, key="columns")
    165            columns = f"{self.sep()}COLUMNS{self.seg(columns)}" if columns else ""
    166            by_ref = (
    167                f"{self.sep()}RETURNING SEQUENCE BY REF" if expression.args.get("by_ref") else ""
    168            )
    169            return f"XMLTABLE({self.sep('')}{self.indent(this + passing + by_ref + columns)}{self.seg(')', sep='')}"

##### 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
  columnposition_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
  bytestring_sql
  datatype_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_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
  onconflict_sql
  returning_sql
  rowformatdelimitedproperty_sql
  table_sql
  tablesample_sql
  pivot_sql
  tuple_sql
  update_sql
  values_sql
  var_sql
  into_sql
  from_sql
  group_sql
  having_sql
  join_sql
  lambda_sql
  lateral_sql
  limit_sql
  setitem_sql
  set_sql
  pragma_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
  windowspec_sql
  withingroup_sql
  between_sql
  bracket_sql
  all_sql
  any_sql
  exists_sql
  case_sql
  constraint_sql
  nextvaluefor_sql
  extract_sql
  trim_sql
  concat_sql
  check_sql
  foreignkey_sql
  primarykey_sql
  unique_sql
  if_sql
  matchagainst_sql
  jsonkeyvalue_sql
  jsonobject_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
  ilikeany_sql
  is_sql
  like_sql
  likeany_sql
  similarto_sql
  lt_sql
  lte_sql
  mod_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

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

    171    class Tokenizer(tokens.Tokenizer):
    172        VAR_SINGLE_TOKENS = {"@"}
    173
    174        KEYWORDS = {
    175            **tokens.Tokenizer.KEYWORDS,
    176            "(+)": TokenType.JOIN_MARKER,
    177            "BINARY_DOUBLE": TokenType.DOUBLE,
    178            "BINARY_FLOAT": TokenType.FLOAT,
    179            "COLUMNS": TokenType.COLUMN,
    180            "MATCH_RECOGNIZE": TokenType.MATCH_RECOGNIZE,
    181            "MINUS": TokenType.EXCEPT,
    182            "NVARCHAR2": TokenType.NVARCHAR,
    183            "RETURNING": TokenType.RETURNING,
    184            "SAMPLE": TokenType.TABLE_SAMPLE,
    185            "START": TokenType.BEGIN,
    186            "TOP": TokenType.TOP,
    187            "VARCHAR2": TokenType.VARCHAR,
    188        }

##### Inherited Members

sqlglot.tokens.Tokenizer
  reset
  tokenize