sqlglot.dialects.oracle API documentation

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

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

     48class Oracle(Dialect):
     49    # https://docs.oracle.com/database/121/SQLRF/sql_elements004.htm#SQLRF00212
     50    # https://docs.python.org/3/library/datetime.html#strftime-and-strptime-format-codes
     51    time_mapping = {
     52        "AM": "%p",  # Meridian indicator with or without periods
     53        "A.M.": "%p",  # Meridian indicator with or without periods
     54        "PM": "%p",  # Meridian indicator with or without periods
     55        "P.M.": "%p",  # Meridian indicator with or without periods
     56        "D": "%u",  # Day of week (1-7)
     57        "DAY": "%A",  # name of day
     58        "DD": "%d",  # day of month (1-31)
     59        "DDD": "%j",  # day of year (1-366)
     60        "DY": "%a",  # abbreviated name of day
     61        "HH": "%I",  # Hour of day (1-12)
     62        "HH12": "%I",  # alias for HH
     63        "HH24": "%H",  # Hour of day (0-23)
     64        "IW": "%V",  # Calendar week of year (1-52 or 1-53), as defined by the ISO 8601 standard
     65        "MI": "%M",  # Minute (0-59)
     66        "MM": "%m",  # Month (01-12; January = 01)
     67        "MON": "%b",  # Abbreviated name of month
     68        "MONTH": "%B",  # Name of month
     69        "SS": "%S",  # Second (0-59)
     70        "WW": "%W",  # Week of year (1-53)
     71        "YY": "%y",  # 15
     72        "YYYY": "%Y",  # 2015
     73    }
     74
     75    class Parser(parser.Parser):
     76        FUNCTIONS = {
     77            **parser.Parser.FUNCTIONS,  # type: ignore
     78            "DECODE": exp.Matches.from_arg_list,
     79            "SQUARE": lambda args: exp.Pow(this=seq_get(args, 0), expression=exp.Literal.number(2)),
     80        }
     81
     82        FUNCTION_PARSERS: t.Dict[str, t.Callable] = {
     83            **parser.Parser.FUNCTION_PARSERS,
     84            "XMLTABLE": _parse_xml_table,
     85        }
     86
     87        def _parse_column(self) -> t.Optional[exp.Expression]:
     88            column = super()._parse_column()
     89            if column:
     90                column.set("join_mark", self._match(TokenType.JOIN_MARKER))
     91            return column
     92
     93    class Generator(generator.Generator):
     94        LOCKING_READS_SUPPORTED = True
     95
     96        TYPE_MAPPING = {
     97            **generator.Generator.TYPE_MAPPING,  # type: ignore
     98            exp.DataType.Type.TINYINT: "NUMBER",
     99            exp.DataType.Type.SMALLINT: "NUMBER",
    100            exp.DataType.Type.INT: "NUMBER",
    101            exp.DataType.Type.BIGINT: "NUMBER",
    102            exp.DataType.Type.DECIMAL: "NUMBER",
    103            exp.DataType.Type.DOUBLE: "DOUBLE PRECISION",
    104            exp.DataType.Type.VARCHAR: "VARCHAR2",
    105            exp.DataType.Type.NVARCHAR: "NVARCHAR2",
    106            exp.DataType.Type.TEXT: "CLOB",
    107            exp.DataType.Type.BINARY: "BLOB",
    108            exp.DataType.Type.VARBINARY: "BLOB",
    109        }
    110
    111        TRANSFORMS = {
    112            **generator.Generator.TRANSFORMS,  # type: ignore
    113            **transforms.UNALIAS_GROUP,  # type: ignore
    114            exp.ILike: no_ilike_sql,
    115            exp.Limit: _limit_sql,
    116            exp.Trim: trim_sql,
    117            exp.Matches: rename_func("DECODE"),
    118            exp.StrToTime: lambda self, e: f"TO_TIMESTAMP({self.sql(e, 'this')}, {self.format_time(e)})",
    119            exp.Subquery: lambda self, e: self.subquery_sql(e, sep=" "),
    120            exp.Table: lambda self, e: self.table_sql(e, sep=" "),
    121            exp.TimeToStr: lambda self, e: f"TO_CHAR({self.sql(e, 'this')}, {self.format_time(e)})",
    122            exp.UnixToTime: lambda self, e: f"TO_DATE('1970-01-01','YYYY-MM-DD') + ({self.sql(e, 'this')} / 86400)",
    123            exp.Substring: rename_func("SUBSTR"),
    124            exp.ToChar: lambda self, e: self.function_fallback_sql(e),
    125        }
    126
    127        def query_modifiers(self, expression: exp.Expression, *sqls: str) -> str:
    128            return csv(
    129                *sqls,
    130                *[self.sql(sql) for sql in expression.args.get("joins") or []],
    131                self.sql(expression, "match"),
    132                *[self.sql(sql) for sql in expression.args.get("laterals") or []],
    133                self.sql(expression, "where"),
    134                self.sql(expression, "group"),
    135                self.sql(expression, "having"),
    136                self.sql(expression, "qualify"),
    137                self.seg("WINDOW ") + self.expressions(expression, "windows", flat=True)
    138                if expression.args.get("windows")
    139                else "",
    140                self.sql(expression, "distribute"),
    141                self.sql(expression, "sort"),
    142                self.sql(expression, "cluster"),
    143                self.sql(expression, "order"),
    144                self.sql(expression, "offset"),  # offset before limit in oracle
    145                self.sql(expression, "limit"),
    146                self.sql(expression, "lock"),
    147                sep="",
    148            )
    149
    150        def offset_sql(self, expression: exp.Offset) -> str:
    151            return f"{super().offset_sql(expression)} ROWS"
    152
    153        def column_sql(self, expression: exp.Column) -> str:
    154            column = super().column_sql(expression)
    155            return f"{column} (+)" if expression.args.get("join_mark") else column
    156
    157        def xmltable_sql(self, expression: exp.XMLTable) -> str:
    158            this = self.sql(expression, "this")
    159            passing = self.expressions(expression, "passing")
    160            passing = f"{self.sep()}PASSING{self.seg(passing)}" if passing else ""
    161            columns = self.expressions(expression, "columns")
    162            columns = f"{self.sep()}COLUMNS{self.seg(columns)}" if columns else ""
    163            by_ref = (
    164                f"{self.sep()}RETURNING SEQUENCE BY REF" if expression.args.get("by_ref") else ""
    165            )
    166            return f"XMLTABLE({self.sep('')}{self.indent(this + passing + by_ref + columns)}{self.seg(')', sep='')}"
    167
    168    class Tokenizer(tokens.Tokenizer):
    169        KEYWORDS = {
    170            **tokens.Tokenizer.KEYWORDS,
    171            "(+)": TokenType.JOIN_MARKER,
    172            "COLUMNS": TokenType.COLUMN,
    173            "MATCH_RECOGNIZE": TokenType.MATCH_RECOGNIZE,
    174            "MINUS": TokenType.EXCEPT,
    175            "NVARCHAR2": TokenType.NVARCHAR,
    176            "RETURNING": TokenType.RETURNING,
    177            "START": TokenType.BEGIN,
    178            "TOP": TokenType.TOP,
    179            "VARCHAR2": TokenType.VARCHAR,
    180        }

##### 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

    75    class Parser(parser.Parser):
    76        FUNCTIONS = {
    77            **parser.Parser.FUNCTIONS,  # type: ignore
    78            "DECODE": exp.Matches.from_arg_list,
    79            "SQUARE": lambda args: exp.Pow(this=seq_get(args, 0), expression=exp.Literal.number(2)),
    80        }
    81
    82        FUNCTION_PARSERS: t.Dict[str, t.Callable] = {
    83            **parser.Parser.FUNCTION_PARSERS,
    84            "XMLTABLE": _parse_xml_table,
    85        }
    86
    87        def _parse_column(self) -> t.Optional[exp.Expression]:
    88            column = super()._parse_column()
    89            if column:
    90                column.set("join_mark", self._match(TokenType.JOIN_MARKER))
    91            return column

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

     93    class Generator(generator.Generator):
     94        LOCKING_READS_SUPPORTED = True
     95
     96        TYPE_MAPPING = {
     97            **generator.Generator.TYPE_MAPPING,  # type: ignore
     98            exp.DataType.Type.TINYINT: "NUMBER",
     99            exp.DataType.Type.SMALLINT: "NUMBER",
    100            exp.DataType.Type.INT: "NUMBER",
    101            exp.DataType.Type.BIGINT: "NUMBER",
    102            exp.DataType.Type.DECIMAL: "NUMBER",
    103            exp.DataType.Type.DOUBLE: "DOUBLE PRECISION",
    104            exp.DataType.Type.VARCHAR: "VARCHAR2",
    105            exp.DataType.Type.NVARCHAR: "NVARCHAR2",
    106            exp.DataType.Type.TEXT: "CLOB",
    107            exp.DataType.Type.BINARY: "BLOB",
    108            exp.DataType.Type.VARBINARY: "BLOB",
    109        }
    110
    111        TRANSFORMS = {
    112            **generator.Generator.TRANSFORMS,  # type: ignore
    113            **transforms.UNALIAS_GROUP,  # type: ignore
    114            exp.ILike: no_ilike_sql,
    115            exp.Limit: _limit_sql,
    116            exp.Trim: trim_sql,
    117            exp.Matches: rename_func("DECODE"),
    118            exp.StrToTime: lambda self, e: f"TO_TIMESTAMP({self.sql(e, 'this')}, {self.format_time(e)})",
    119            exp.Subquery: lambda self, e: self.subquery_sql(e, sep=" "),
    120            exp.Table: lambda self, e: self.table_sql(e, sep=" "),
    121            exp.TimeToStr: lambda self, e: f"TO_CHAR({self.sql(e, 'this')}, {self.format_time(e)})",
    122            exp.UnixToTime: lambda self, e: f"TO_DATE('1970-01-01','YYYY-MM-DD') + ({self.sql(e, 'this')} / 86400)",
    123            exp.Substring: rename_func("SUBSTR"),
    124            exp.ToChar: lambda self, e: self.function_fallback_sql(e),
    125        }
    126
    127        def query_modifiers(self, expression: exp.Expression, *sqls: str) -> str:
    128            return csv(
    129                *sqls,
    130                *[self.sql(sql) for sql in expression.args.get("joins") or []],
    131                self.sql(expression, "match"),
    132                *[self.sql(sql) for sql in expression.args.get("laterals") or []],
    133                self.sql(expression, "where"),
    134                self.sql(expression, "group"),
    135                self.sql(expression, "having"),
    136                self.sql(expression, "qualify"),
    137                self.seg("WINDOW ") + self.expressions(expression, "windows", flat=True)
    138                if expression.args.get("windows")
    139                else "",
    140                self.sql(expression, "distribute"),
    141                self.sql(expression, "sort"),
    142                self.sql(expression, "cluster"),
    143                self.sql(expression, "order"),
    144                self.sql(expression, "offset"),  # offset before limit in oracle
    145                self.sql(expression, "limit"),
    146                self.sql(expression, "lock"),
    147                sep="",
    148            )
    149
    150        def offset_sql(self, expression: exp.Offset) -> str:
    151            return f"{super().offset_sql(expression)} ROWS"
    152
    153        def column_sql(self, expression: exp.Column) -> str:
    154            column = super().column_sql(expression)
    155            return f"{column} (+)" if expression.args.get("join_mark") else column
    156
    157        def xmltable_sql(self, expression: exp.XMLTable) -> str:
    158            this = self.sql(expression, "this")
    159            passing = self.expressions(expression, "passing")
    160            passing = f"{self.sep()}PASSING{self.seg(passing)}" if passing else ""
    161            columns = self.expressions(expression, "columns")
    162            columns = f"{self.sep()}COLUMNS{self.seg(columns)}" if columns else ""
    163            by_ref = (
    164                f"{self.sep()}RETURNING SEQUENCE BY REF" if expression.args.get("by_ref") else ""
    165            )
    166            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 query_modifiers(self, expression: sqlglot.expressions.Expression, *sqls: str) -> str: View Source

    127        def query_modifiers(self, expression: exp.Expression, *sqls: str) -> str:
    128            return csv(
    129                *sqls,
    130                *[self.sql(sql) for sql in expression.args.get("joins") or []],
    131                self.sql(expression, "match"),
    132                *[self.sql(sql) for sql in expression.args.get("laterals") or []],
    133                self.sql(expression, "where"),
    134                self.sql(expression, "group"),
    135                self.sql(expression, "having"),
    136                self.sql(expression, "qualify"),
    137                self.seg("WINDOW ") + self.expressions(expression, "windows", flat=True)
    138                if expression.args.get("windows")
    139                else "",
    140                self.sql(expression, "distribute"),
    141                self.sql(expression, "sort"),
    142                self.sql(expression, "cluster"),
    143                self.sql(expression, "order"),
    144                self.sql(expression, "offset"),  # offset before limit in oracle
    145                self.sql(expression, "limit"),
    146                self.sql(expression, "lock"),
    147                sep="",
    148            )

def offset_sql(self, expression: sqlglot.expressions.Offset) -> str: View Source

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

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

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

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

    157        def xmltable_sql(self, expression: exp.XMLTable) -> str:
    158            this = self.sql(expression, "this")
    159            passing = self.expressions(expression, "passing")
    160            passing = f"{self.sep()}PASSING{self.seg(passing)}" if passing else ""
    161            columns = self.expressions(expression, "columns")
    162            columns = f"{self.sep()}COLUMNS{self.seg(columns)}" if columns else ""
    163            by_ref = (
    164                f"{self.sep()}RETURNING SEQUENCE BY REF" if expression.args.get("by_ref") else ""
    165            )
    166            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
  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
  datatype_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
  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
  lock_sql
  literal_sql
  loaddata_sql
  null_sql
  boolean_sql
  order_sql
  cluster_sql
  distribute_sql
  sort_sql
  ordered_sql
  matchrecognize_sql
  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
  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

    168    class Tokenizer(tokens.Tokenizer):
    169        KEYWORDS = {
    170            **tokens.Tokenizer.KEYWORDS,
    171            "(+)": TokenType.JOIN_MARKER,
    172            "COLUMNS": TokenType.COLUMN,
    173            "MATCH_RECOGNIZE": TokenType.MATCH_RECOGNIZE,
    174            "MINUS": TokenType.EXCEPT,
    175            "NVARCHAR2": TokenType.NVARCHAR,
    176            "RETURNING": TokenType.RETURNING,
    177            "START": TokenType.BEGIN,
    178            "TOP": TokenType.TOP,
    179            "VARCHAR2": TokenType.VARCHAR,
    180        }

##### Inherited Members

sqlglot.tokens.Tokenizer
  reset
  tokenize