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

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        }
     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        }
    124
    125        def query_modifiers(self, expression: exp.Expression, *sqls: str) -> str:
    126            return csv(
    127                *sqls,
    128                *[self.sql(sql) for sql in expression.args.get("joins") or []],
    129                self.sql(expression, "match"),
    130                *[self.sql(sql) for sql in expression.args.get("laterals") or []],
    131                self.sql(expression, "where"),
    132                self.sql(expression, "group"),
    133                self.sql(expression, "having"),
    134                self.sql(expression, "qualify"),
    135                self.seg("WINDOW ") + self.expressions(expression, "windows", flat=True)
    136                if expression.args.get("windows")
    137                else "",
    138                self.sql(expression, "distribute"),
    139                self.sql(expression, "sort"),
    140                self.sql(expression, "cluster"),
    141                self.sql(expression, "order"),
    142                self.sql(expression, "offset"),  # offset before limit in oracle
    143                self.sql(expression, "limit"),
    144                self.sql(expression, "lock"),
    145                sep="",
    146            )
    147
    148        def offset_sql(self, expression: exp.Offset) -> str:
    149            return f"{super().offset_sql(expression)} ROWS"
    150
    151        def column_sql(self, expression: exp.Column) -> str:
    152            column = super().column_sql(expression)
    153            return f"{column} (+)" if expression.args.get("join_mark") else column
    154
    155        def xmltable_sql(self, expression: exp.XMLTable) -> str:
    156            this = self.sql(expression, "this")
    157            passing = self.expressions(expression, "passing")
    158            passing = f"{self.sep()}PASSING{self.seg(passing)}" if passing else ""
    159            columns = self.expressions(expression, "columns")
    160            columns = f"{self.sep()}COLUMNS{self.seg(columns)}" if columns else ""
    161            by_ref = (
    162                f"{self.sep()}RETURNING SEQUENCE BY REF" if expression.args.get("by_ref") else ""
    163            )
    164            return f"XMLTABLE({self.sep('')}{self.indent(this + passing + by_ref + columns)}{self.seg(')', sep='')}"
    165
    166    class Tokenizer(tokens.Tokenizer):
    167        KEYWORDS = {
    168            **tokens.Tokenizer.KEYWORDS,
    169            "(+)": TokenType.JOIN_MARKER,
    170            "COLUMNS": TokenType.COLUMN,
    171            "MATCH_RECOGNIZE": TokenType.MATCH_RECOGNIZE,
    172            "MINUS": TokenType.EXCEPT,
    173            "NVARCHAR2": TokenType.NVARCHAR,
    174            "RETURNING": TokenType.RETURNING,
    175            "START": TokenType.BEGIN,
    176            "TOP": TokenType.TOP,
    177            "VARCHAR2": TokenType.VARCHAR,
    178        }

##### Inherited Members

sqlglot.dialects.dialect.Dialect
  get_or_raise
  format_time
  parse
  parse_into
  generate
  transpile
  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        }
    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

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

     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        }
    124
    125        def query_modifiers(self, expression: exp.Expression, *sqls: str) -> str:
    126            return csv(
    127                *sqls,
    128                *[self.sql(sql) for sql in expression.args.get("joins") or []],
    129                self.sql(expression, "match"),
    130                *[self.sql(sql) for sql in expression.args.get("laterals") or []],
    131                self.sql(expression, "where"),
    132                self.sql(expression, "group"),
    133                self.sql(expression, "having"),
    134                self.sql(expression, "qualify"),
    135                self.seg("WINDOW ") + self.expressions(expression, "windows", flat=True)
    136                if expression.args.get("windows")
    137                else "",
    138                self.sql(expression, "distribute"),
    139                self.sql(expression, "sort"),
    140                self.sql(expression, "cluster"),
    141                self.sql(expression, "order"),
    142                self.sql(expression, "offset"),  # offset before limit in oracle
    143                self.sql(expression, "limit"),
    144                self.sql(expression, "lock"),
    145                sep="",
    146            )
    147
    148        def offset_sql(self, expression: exp.Offset) -> str:
    149            return f"{super().offset_sql(expression)} ROWS"
    150
    151        def column_sql(self, expression: exp.Column) -> str:
    152            column = super().column_sql(expression)
    153            return f"{column} (+)" if expression.args.get("join_mark") else column
    154
    155        def xmltable_sql(self, expression: exp.XMLTable) -> str:
    156            this = self.sql(expression, "this")
    157            passing = self.expressions(expression, "passing")
    158            passing = f"{self.sep()}PASSING{self.seg(passing)}" if passing else ""
    159            columns = self.expressions(expression, "columns")
    160            columns = f"{self.sep()}COLUMNS{self.seg(columns)}" if columns else ""
    161            by_ref = (
    162                f"{self.sep()}RETURNING SEQUENCE BY REF" if expression.args.get("by_ref") else ""
    163            )
    164            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): if set to True all identifiers will be delimited by the corresponding character.
- 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

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

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

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

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

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

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

    155        def xmltable_sql(self, expression: exp.XMLTable) -> str:
    156            this = self.sql(expression, "this")
    157            passing = self.expressions(expression, "passing")
    158            passing = f"{self.sep()}PASSING{self.seg(passing)}" if passing else ""
    159            columns = self.expressions(expression, "columns")
    160            columns = f"{self.sep()}COLUMNS{self.seg(columns)}" if columns else ""
    161            by_ref = (
    162                f"{self.sep()}RETURNING SEQUENCE BY REF" if expression.args.get("by_ref") else ""
    163            )
    164            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
  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
  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

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

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

##### Inherited Members

sqlglot.tokens.Tokenizer
  reset
  tokenize