Edit on GitHub

# sqlglot.dialects.mysql

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 (
      7    Dialect,
      8    arrow_json_extract_scalar_sql,
      9    datestrtodate_sql,
     10    format_time_lambda,
     11    locate_to_strposition,
     12    max_or_greatest,
     13    min_or_least,
     14    no_ilike_sql,
     15    no_paren_current_date_sql,
     16    no_pivot_sql,
     17    no_tablesample_sql,
     18    no_trycast_sql,
     19    parse_date_delta_with_interval,
     20    rename_func,
     21    strposition_to_locate_sql,
     22)
     23from sqlglot.helper import seq_get
     24from sqlglot.tokens import TokenType
     25
     26
     27def _show_parser(*args: t.Any, **kwargs: t.Any) -> t.Callable[[MySQL.Parser], exp.Show]:
     28    def _parse(self: MySQL.Parser) -> exp.Show:
     29        return self._parse_show_mysql(*args, **kwargs)
     30
     31    return _parse
     32
     33
     34def _date_trunc_sql(self: generator.Generator, expression: exp.DateTrunc) -> str:
     35    expr = self.sql(expression, "this")
     36    unit = expression.text("unit")
     37
     38    if unit == "day":
     39        return f"DATE({expr})"
     40
     41    if unit == "week":
     42        concat = f"CONCAT(YEAR({expr}), ' ', WEEK({expr}, 1), ' 1')"
     43        date_format = "%Y %u %w"
     44    elif unit == "month":
     45        concat = f"CONCAT(YEAR({expr}), ' ', MONTH({expr}), ' 1')"
     46        date_format = "%Y %c %e"
     47    elif unit == "quarter":
     48        concat = f"CONCAT(YEAR({expr}), ' ', QUARTER({expr}) * 3 - 2, ' 1')"
     49        date_format = "%Y %c %e"
     50    elif unit == "year":
     51        concat = f"CONCAT(YEAR({expr}), ' 1 1')"
     52        date_format = "%Y %c %e"
     53    else:
     54        self.unsupported(f"Unexpected interval unit: {unit}")
     55        return f"DATE({expr})"
     56
     57    return f"STR_TO_DATE({concat}, '{date_format}')"
     58
     59
     60def _str_to_date(args: t.List) -> exp.StrToDate:
     61    date_format = MySQL.format_time(seq_get(args, 1))
     62    return exp.StrToDate(this=seq_get(args, 0), format=date_format)
     63
     64
     65def _str_to_date_sql(self: generator.Generator, expression: exp.StrToDate | exp.StrToTime) -> str:
     66    date_format = self.format_time(expression)
     67    return f"STR_TO_DATE({self.sql(expression.this)}, {date_format})"
     68
     69
     70def _trim_sql(self: generator.Generator, expression: exp.Trim) -> str:
     71    target = self.sql(expression, "this")
     72    trim_type = self.sql(expression, "position")
     73    remove_chars = self.sql(expression, "expression")
     74
     75    # Use TRIM/LTRIM/RTRIM syntax if the expression isn't mysql-specific
     76    if not remove_chars:
     77        return self.trim_sql(expression)
     78
     79    trim_type = f"{trim_type} " if trim_type else ""
     80    remove_chars = f"{remove_chars} " if remove_chars else ""
     81    from_part = "FROM " if trim_type or remove_chars else ""
     82    return f"TRIM({trim_type}{remove_chars}{from_part}{target})"
     83
     84
     85def _date_add_sql(kind: str) -> t.Callable[[generator.Generator, exp.DateAdd | exp.DateSub], str]:
     86    def func(self: generator.Generator, expression: exp.DateAdd | exp.DateSub) -> str:
     87        this = self.sql(expression, "this")
     88        unit = expression.text("unit").upper() or "DAY"
     89        return (
     90            f"DATE_{kind}({this}, {self.sql(exp.Interval(this=expression.expression, unit=unit))})"
     91        )
     92
     93    return func
     94
     95
     96class MySQL(Dialect):
     97    TIME_FORMAT = "'%Y-%m-%d %T'"
     98
     99    # https://prestodb.io/docs/current/functions/datetime.html#mysql-date-functions
    100    TIME_MAPPING = {
    101        "%M": "%B",
    102        "%c": "%-m",
    103        "%e": "%-d",
    104        "%h": "%I",
    105        "%i": "%M",
    106        "%s": "%S",
    107        "%S": "%S",
    108        "%u": "%W",
    109        "%k": "%-H",
    110        "%l": "%-I",
    111        "%T": "%H:%M:%S",
    112        "%W": "%a",
    113    }
    114
    115    class Tokenizer(tokens.Tokenizer):
    116        QUOTES = ["'", '"']
    117        COMMENTS = ["--", "#", ("/*", "*/")]
    118        IDENTIFIERS = ["`"]
    119        STRING_ESCAPES = ["'", "\\"]
    120        BIT_STRINGS = [("b'", "'"), ("B'", "'"), ("0b", "")]
    121        HEX_STRINGS = [("x'", "'"), ("X'", "'"), ("0x", "")]
    122
    123        KEYWORDS = {
    124            **tokens.Tokenizer.KEYWORDS,
    125            "CHARSET": TokenType.CHARACTER_SET,
    126            "ENUM": TokenType.ENUM,
    127            "FORCE": TokenType.FORCE,
    128            "IGNORE": TokenType.IGNORE,
    129            "LONGBLOB": TokenType.LONGBLOB,
    130            "LONGTEXT": TokenType.LONGTEXT,
    131            "MEDIUMBLOB": TokenType.MEDIUMBLOB,
    132            "MEDIUMTEXT": TokenType.MEDIUMTEXT,
    133            "MEMBER OF": TokenType.MEMBER_OF,
    134            "SEPARATOR": TokenType.SEPARATOR,
    135            "START": TokenType.BEGIN,
    136            "SIGNED": TokenType.BIGINT,
    137            "SIGNED INTEGER": TokenType.BIGINT,
    138            "UNSIGNED": TokenType.UBIGINT,
    139            "UNSIGNED INTEGER": TokenType.UBIGINT,
    140            "_ARMSCII8": TokenType.INTRODUCER,
    141            "_ASCII": TokenType.INTRODUCER,
    142            "_BIG5": TokenType.INTRODUCER,
    143            "_BINARY": TokenType.INTRODUCER,
    144            "_CP1250": TokenType.INTRODUCER,
    145            "_CP1251": TokenType.INTRODUCER,
    146            "_CP1256": TokenType.INTRODUCER,
    147            "_CP1257": TokenType.INTRODUCER,
    148            "_CP850": TokenType.INTRODUCER,
    149            "_CP852": TokenType.INTRODUCER,
    150            "_CP866": TokenType.INTRODUCER,
    151            "_CP932": TokenType.INTRODUCER,
    152            "_DEC8": TokenType.INTRODUCER,
    153            "_EUCJPMS": TokenType.INTRODUCER,
    154            "_EUCKR": TokenType.INTRODUCER,
    155            "_GB18030": TokenType.INTRODUCER,
    156            "_GB2312": TokenType.INTRODUCER,
    157            "_GBK": TokenType.INTRODUCER,
    158            "_GEOSTD8": TokenType.INTRODUCER,
    159            "_GREEK": TokenType.INTRODUCER,
    160            "_HEBREW": TokenType.INTRODUCER,
    161            "_HP8": TokenType.INTRODUCER,
    162            "_KEYBCS2": TokenType.INTRODUCER,
    163            "_KOI8R": TokenType.INTRODUCER,
    164            "_KOI8U": TokenType.INTRODUCER,
    165            "_LATIN1": TokenType.INTRODUCER,
    166            "_LATIN2": TokenType.INTRODUCER,
    167            "_LATIN5": TokenType.INTRODUCER,
    168            "_LATIN7": TokenType.INTRODUCER,
    169            "_MACCE": TokenType.INTRODUCER,
    170            "_MACROMAN": TokenType.INTRODUCER,
    171            "_SJIS": TokenType.INTRODUCER,
    172            "_SWE7": TokenType.INTRODUCER,
    173            "_TIS620": TokenType.INTRODUCER,
    174            "_UCS2": TokenType.INTRODUCER,
    175            "_UJIS": TokenType.INTRODUCER,
    176            # https://dev.mysql.com/doc/refman/8.0/en/string-literals.html
    177            "_UTF8": TokenType.INTRODUCER,
    178            "_UTF16": TokenType.INTRODUCER,
    179            "_UTF16LE": TokenType.INTRODUCER,
    180            "_UTF32": TokenType.INTRODUCER,
    181            "_UTF8MB3": TokenType.INTRODUCER,
    182            "_UTF8MB4": TokenType.INTRODUCER,
    183            "@@": TokenType.SESSION_PARAMETER,
    184        }
    185
    186        COMMANDS = tokens.Tokenizer.COMMANDS - {TokenType.SHOW}
    187
    188    class Parser(parser.Parser):
    189        FUNC_TOKENS = {
    190            *parser.Parser.FUNC_TOKENS,
    191            TokenType.DATABASE,
    192            TokenType.SCHEMA,
    193            TokenType.VALUES,
    194        }
    195
    196        CONJUNCTION = {
    197            **parser.Parser.CONJUNCTION,
    198            TokenType.DAMP: exp.And,
    199            TokenType.XOR: exp.Xor,
    200        }
    201
    202        TABLE_ALIAS_TOKENS = (
    203            parser.Parser.TABLE_ALIAS_TOKENS - parser.Parser.TABLE_INDEX_HINT_TOKENS
    204        )
    205
    206        RANGE_PARSERS = {
    207            **parser.Parser.RANGE_PARSERS,
    208            TokenType.MEMBER_OF: lambda self, this: self.expression(
    209                exp.JSONArrayContains,
    210                this=this,
    211                expression=self._parse_wrapped(self._parse_expression),
    212            ),
    213        }
    214
    215        FUNCTIONS = {
    216            **parser.Parser.FUNCTIONS,
    217            "DATE_ADD": parse_date_delta_with_interval(exp.DateAdd),
    218            "DATE_FORMAT": format_time_lambda(exp.TimeToStr, "mysql"),
    219            "DATE_SUB": parse_date_delta_with_interval(exp.DateSub),
    220            "INSTR": lambda args: exp.StrPosition(substr=seq_get(args, 1), this=seq_get(args, 0)),
    221            "LOCATE": locate_to_strposition,
    222            "STR_TO_DATE": _str_to_date,
    223        }
    224
    225        FUNCTION_PARSERS = {
    226            **parser.Parser.FUNCTION_PARSERS,
    227            "GROUP_CONCAT": lambda self: self.expression(
    228                exp.GroupConcat,
    229                this=self._parse_lambda(),
    230                separator=self._match(TokenType.SEPARATOR) and self._parse_field(),
    231            ),
    232            # https://dev.mysql.com/doc/refman/5.7/en/miscellaneous-functions.html#function_values
    233            "VALUES": lambda self: self.expression(
    234                exp.Anonymous, this="VALUES", expressions=[self._parse_id_var()]
    235            ),
    236        }
    237
    238        STATEMENT_PARSERS = {
    239            **parser.Parser.STATEMENT_PARSERS,
    240            TokenType.SHOW: lambda self: self._parse_show(),
    241        }
    242
    243        SHOW_PARSERS = {
    244            "BINARY LOGS": _show_parser("BINARY LOGS"),
    245            "MASTER LOGS": _show_parser("BINARY LOGS"),
    246            "BINLOG EVENTS": _show_parser("BINLOG EVENTS"),
    247            "CHARACTER SET": _show_parser("CHARACTER SET"),
    248            "CHARSET": _show_parser("CHARACTER SET"),
    249            "COLLATION": _show_parser("COLLATION"),
    250            "FULL COLUMNS": _show_parser("COLUMNS", target="FROM", full=True),
    251            "COLUMNS": _show_parser("COLUMNS", target="FROM"),
    252            "CREATE DATABASE": _show_parser("CREATE DATABASE", target=True),
    253            "CREATE EVENT": _show_parser("CREATE EVENT", target=True),
    254            "CREATE FUNCTION": _show_parser("CREATE FUNCTION", target=True),
    255            "CREATE PROCEDURE": _show_parser("CREATE PROCEDURE", target=True),
    256            "CREATE TABLE": _show_parser("CREATE TABLE", target=True),
    257            "CREATE TRIGGER": _show_parser("CREATE TRIGGER", target=True),
    258            "CREATE VIEW": _show_parser("CREATE VIEW", target=True),
    259            "DATABASES": _show_parser("DATABASES"),
    260            "ENGINE": _show_parser("ENGINE", target=True),
    261            "STORAGE ENGINES": _show_parser("ENGINES"),
    262            "ENGINES": _show_parser("ENGINES"),
    263            "ERRORS": _show_parser("ERRORS"),
    264            "EVENTS": _show_parser("EVENTS"),
    265            "FUNCTION CODE": _show_parser("FUNCTION CODE", target=True),
    266            "FUNCTION STATUS": _show_parser("FUNCTION STATUS"),
    267            "GRANTS": _show_parser("GRANTS", target="FOR"),
    268            "INDEX": _show_parser("INDEX", target="FROM"),
    269            "MASTER STATUS": _show_parser("MASTER STATUS"),
    270            "OPEN TABLES": _show_parser("OPEN TABLES"),
    271            "PLUGINS": _show_parser("PLUGINS"),
    272            "PROCEDURE CODE": _show_parser("PROCEDURE CODE", target=True),
    273            "PROCEDURE STATUS": _show_parser("PROCEDURE STATUS"),
    274            "PRIVILEGES": _show_parser("PRIVILEGES"),
    275            "FULL PROCESSLIST": _show_parser("PROCESSLIST", full=True),
    276            "PROCESSLIST": _show_parser("PROCESSLIST"),
    277            "PROFILE": _show_parser("PROFILE"),
    278            "PROFILES": _show_parser("PROFILES"),
    279            "RELAYLOG EVENTS": _show_parser("RELAYLOG EVENTS"),
    280            "REPLICAS": _show_parser("REPLICAS"),
    281            "SLAVE HOSTS": _show_parser("REPLICAS"),
    282            "REPLICA STATUS": _show_parser("REPLICA STATUS"),
    283            "SLAVE STATUS": _show_parser("REPLICA STATUS"),
    284            "GLOBAL STATUS": _show_parser("STATUS", global_=True),
    285            "SESSION STATUS": _show_parser("STATUS"),
    286            "STATUS": _show_parser("STATUS"),
    287            "TABLE STATUS": _show_parser("TABLE STATUS"),
    288            "FULL TABLES": _show_parser("TABLES", full=True),
    289            "TABLES": _show_parser("TABLES"),
    290            "TRIGGERS": _show_parser("TRIGGERS"),
    291            "GLOBAL VARIABLES": _show_parser("VARIABLES", global_=True),
    292            "SESSION VARIABLES": _show_parser("VARIABLES"),
    293            "VARIABLES": _show_parser("VARIABLES"),
    294            "WARNINGS": _show_parser("WARNINGS"),
    295        }
    296
    297        SET_PARSERS = {
    298            **parser.Parser.SET_PARSERS,
    299            "PERSIST": lambda self: self._parse_set_item_assignment("PERSIST"),
    300            "PERSIST_ONLY": lambda self: self._parse_set_item_assignment("PERSIST_ONLY"),
    301            "CHARACTER SET": lambda self: self._parse_set_item_charset("CHARACTER SET"),
    302            "CHARSET": lambda self: self._parse_set_item_charset("CHARACTER SET"),
    303            "NAMES": lambda self: self._parse_set_item_names(),
    304        }
    305
    306        PROFILE_TYPES = {
    307            "ALL",
    308            "BLOCK IO",
    309            "CONTEXT SWITCHES",
    310            "CPU",
    311            "IPC",
    312            "MEMORY",
    313            "PAGE FAULTS",
    314            "SOURCE",
    315            "SWAPS",
    316        }
    317
    318        TYPE_TOKENS = {
    319            *parser.Parser.TYPE_TOKENS,
    320            TokenType.SET,
    321        }
    322
    323        ENUM_TYPE_TOKENS = {
    324            *parser.Parser.ENUM_TYPE_TOKENS,
    325            TokenType.SET,
    326        }
    327
    328        LOG_DEFAULTS_TO_LN = True
    329
    330        def _parse_show_mysql(
    331            self,
    332            this: str,
    333            target: bool | str = False,
    334            full: t.Optional[bool] = None,
    335            global_: t.Optional[bool] = None,
    336        ) -> exp.Show:
    337            if target:
    338                if isinstance(target, str):
    339                    self._match_text_seq(target)
    340                target_id = self._parse_id_var()
    341            else:
    342                target_id = None
    343
    344            log = self._parse_string() if self._match_text_seq("IN") else None
    345
    346            if this in {"BINLOG EVENTS", "RELAYLOG EVENTS"}:
    347                position = self._parse_number() if self._match_text_seq("FROM") else None
    348                db = None
    349            else:
    350                position = None
    351                db = None
    352
    353                if self._match(TokenType.FROM):
    354                    db = self._parse_id_var()
    355                elif self._match(TokenType.DOT):
    356                    db = target_id
    357                    target_id = self._parse_id_var()
    358
    359            channel = self._parse_id_var() if self._match_text_seq("FOR", "CHANNEL") else None
    360
    361            like = self._parse_string() if self._match_text_seq("LIKE") else None
    362            where = self._parse_where()
    363
    364            if this == "PROFILE":
    365                types = self._parse_csv(lambda: self._parse_var_from_options(self.PROFILE_TYPES))
    366                query = self._parse_number() if self._match_text_seq("FOR", "QUERY") else None
    367                offset = self._parse_number() if self._match_text_seq("OFFSET") else None
    368                limit = self._parse_number() if self._match_text_seq("LIMIT") else None
    369            else:
    370                types, query = None, None
    371                offset, limit = self._parse_oldstyle_limit()
    372
    373            mutex = True if self._match_text_seq("MUTEX") else None
    374            mutex = False if self._match_text_seq("STATUS") else mutex
    375
    376            return self.expression(
    377                exp.Show,
    378                this=this,
    379                target=target_id,
    380                full=full,
    381                log=log,
    382                position=position,
    383                db=db,
    384                channel=channel,
    385                like=like,
    386                where=where,
    387                types=types,
    388                query=query,
    389                offset=offset,
    390                limit=limit,
    391                mutex=mutex,
    392                **{"global": global_},  # type: ignore
    393            )
    394
    395        def _parse_oldstyle_limit(
    396            self,
    397        ) -> t.Tuple[t.Optional[exp.Expression], t.Optional[exp.Expression]]:
    398            limit = None
    399            offset = None
    400            if self._match_text_seq("LIMIT"):
    401                parts = self._parse_csv(self._parse_number)
    402                if len(parts) == 1:
    403                    limit = parts[0]
    404                elif len(parts) == 2:
    405                    limit = parts[1]
    406                    offset = parts[0]
    407
    408            return offset, limit
    409
    410        def _parse_set_item_charset(self, kind: str) -> exp.Expression:
    411            this = self._parse_string() or self._parse_id_var()
    412            return self.expression(exp.SetItem, this=this, kind=kind)
    413
    414        def _parse_set_item_names(self) -> exp.Expression:
    415            charset = self._parse_string() or self._parse_id_var()
    416            if self._match_text_seq("COLLATE"):
    417                collate = self._parse_string() or self._parse_id_var()
    418            else:
    419                collate = None
    420
    421            return self.expression(exp.SetItem, this=charset, collate=collate, kind="NAMES")
    422
    423    class Generator(generator.Generator):
    424        LOCKING_READS_SUPPORTED = True
    425        NULL_ORDERING_SUPPORTED = False
    426        JOIN_HINTS = False
    427        TABLE_HINTS = True
    428        DUPLICATE_KEY_UPDATE_WITH_SET = False
    429        QUERY_HINT_SEP = " "
    430
    431        TRANSFORMS = {
    432            **generator.Generator.TRANSFORMS,
    433            exp.CurrentDate: no_paren_current_date_sql,
    434            exp.DateDiff: lambda self, e: self.func("DATEDIFF", e.this, e.expression),
    435            exp.DateAdd: _date_add_sql("ADD"),
    436            exp.DateStrToDate: datestrtodate_sql,
    437            exp.DateSub: _date_add_sql("SUB"),
    438            exp.DateTrunc: _date_trunc_sql,
    439            exp.DayOfMonth: rename_func("DAYOFMONTH"),
    440            exp.DayOfWeek: rename_func("DAYOFWEEK"),
    441            exp.DayOfYear: rename_func("DAYOFYEAR"),
    442            exp.GroupConcat: lambda self, e: f"""GROUP_CONCAT({self.sql(e, "this")} SEPARATOR {self.sql(e, "separator") or "','"})""",
    443            exp.ILike: no_ilike_sql,
    444            exp.JSONExtractScalar: arrow_json_extract_scalar_sql,
    445            exp.Max: max_or_greatest,
    446            exp.Min: min_or_least,
    447            exp.NullSafeEQ: lambda self, e: self.binary(e, "<=>"),
    448            exp.NullSafeNEQ: lambda self, e: self.not_sql(self.binary(e, "<=>")),
    449            exp.Pivot: no_pivot_sql,
    450            exp.Select: transforms.preprocess([transforms.eliminate_distinct_on]),
    451            exp.StrPosition: strposition_to_locate_sql,
    452            exp.StrToDate: _str_to_date_sql,
    453            exp.StrToTime: _str_to_date_sql,
    454            exp.TableSample: no_tablesample_sql,
    455            exp.TimeStrToUnix: rename_func("UNIX_TIMESTAMP"),
    456            exp.TimeToStr: lambda self, e: self.func("DATE_FORMAT", e.this, self.format_time(e)),
    457            exp.Trim: _trim_sql,
    458            exp.TryCast: no_trycast_sql,
    459            exp.WeekOfYear: rename_func("WEEKOFYEAR"),
    460        }
    461
    462        TYPE_MAPPING = generator.Generator.TYPE_MAPPING.copy()
    463        TYPE_MAPPING.pop(exp.DataType.Type.MEDIUMTEXT)
    464        TYPE_MAPPING.pop(exp.DataType.Type.LONGTEXT)
    465        TYPE_MAPPING.pop(exp.DataType.Type.MEDIUMBLOB)
    466        TYPE_MAPPING.pop(exp.DataType.Type.LONGBLOB)
    467
    468        PROPERTIES_LOCATION = {
    469            **generator.Generator.PROPERTIES_LOCATION,
    470            exp.TransientProperty: exp.Properties.Location.UNSUPPORTED,
    471            exp.VolatileProperty: exp.Properties.Location.UNSUPPORTED,
    472        }
    473
    474        LIMIT_FETCH = "LIMIT"
    475
    476        def jsonarraycontains_sql(self, expression: exp.JSONArrayContains) -> str:
    477            return f"{self.sql(expression, 'this')} MEMBER OF({self.sql(expression, 'expression')})"
    478
    479        def cast_sql(self, expression: exp.Cast, safe_prefix: t.Optional[str] = None) -> str:
    480            """(U)BIGINT is not allowed in a CAST expression, so we use (UN)SIGNED instead."""
    481            if expression.to.this == exp.DataType.Type.BIGINT:
    482                to = "SIGNED"
    483            elif expression.to.this == exp.DataType.Type.UBIGINT:
    484                to = "UNSIGNED"
    485            else:
    486                return super().cast_sql(expression)
    487
    488            return f"CAST({self.sql(expression, 'this')} AS {to})"
    489
    490        def show_sql(self, expression: exp.Show) -> str:
    491            this = f" {expression.name}"
    492            full = " FULL" if expression.args.get("full") else ""
    493            global_ = " GLOBAL" if expression.args.get("global") else ""
    494
    495            target = self.sql(expression, "target")
    496            target = f" {target}" if target else ""
    497            if expression.name in {"COLUMNS", "INDEX"}:
    498                target = f" FROM{target}"
    499            elif expression.name == "GRANTS":
    500                target = f" FOR{target}"
    501
    502            db = self._prefixed_sql("FROM", expression, "db")
    503
    504            like = self._prefixed_sql("LIKE", expression, "like")
    505            where = self.sql(expression, "where")
    506
    507            types = self.expressions(expression, key="types")
    508            types = f" {types}" if types else types
    509            query = self._prefixed_sql("FOR QUERY", expression, "query")
    510
    511            if expression.name == "PROFILE":
    512                offset = self._prefixed_sql("OFFSET", expression, "offset")
    513                limit = self._prefixed_sql("LIMIT", expression, "limit")
    514            else:
    515                offset = ""
    516                limit = self._oldstyle_limit_sql(expression)
    517
    518            log = self._prefixed_sql("IN", expression, "log")
    519            position = self._prefixed_sql("FROM", expression, "position")
    520
    521            channel = self._prefixed_sql("FOR CHANNEL", expression, "channel")
    522
    523            if expression.name == "ENGINE":
    524                mutex_or_status = " MUTEX" if expression.args.get("mutex") else " STATUS"
    525            else:
    526                mutex_or_status = ""
    527
    528            return f"SHOW{full}{global_}{this}{target}{types}{db}{query}{log}{position}{channel}{mutex_or_status}{like}{where}{offset}{limit}"
    529
    530        def _prefixed_sql(self, prefix: str, expression: exp.Expression, arg: str) -> str:
    531            sql = self.sql(expression, arg)
    532            return f" {prefix} {sql}" if sql else ""
    533
    534        def _oldstyle_limit_sql(self, expression: exp.Show) -> str:
    535            limit = self.sql(expression, "limit")
    536            offset = self.sql(expression, "offset")
    537            if limit:
    538                limit_offset = f"{offset}, {limit}" if offset else limit
    539                return f" LIMIT {limit_offset}"
    540            return ""

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

     97class MySQL(Dialect):
     98    TIME_FORMAT = "'%Y-%m-%d %T'"
     99
    100    # https://prestodb.io/docs/current/functions/datetime.html#mysql-date-functions
    101    TIME_MAPPING = {
    102        "%M": "%B",
    103        "%c": "%-m",
    104        "%e": "%-d",
    105        "%h": "%I",
    106        "%i": "%M",
    107        "%s": "%S",
    108        "%S": "%S",
    109        "%u": "%W",
    110        "%k": "%-H",
    111        "%l": "%-I",
    112        "%T": "%H:%M:%S",
    113        "%W": "%a",
    114    }
    115
    116    class Tokenizer(tokens.Tokenizer):
    117        QUOTES = ["'", '"']
    118        COMMENTS = ["--", "#", ("/*", "*/")]
    119        IDENTIFIERS = ["`"]
    120        STRING_ESCAPES = ["'", "\\"]
    121        BIT_STRINGS = [("b'", "'"), ("B'", "'"), ("0b", "")]
    122        HEX_STRINGS = [("x'", "'"), ("X'", "'"), ("0x", "")]
    123
    124        KEYWORDS = {
    125            **tokens.Tokenizer.KEYWORDS,
    126            "CHARSET": TokenType.CHARACTER_SET,
    127            "ENUM": TokenType.ENUM,
    128            "FORCE": TokenType.FORCE,
    129            "IGNORE": TokenType.IGNORE,
    130            "LONGBLOB": TokenType.LONGBLOB,
    131            "LONGTEXT": TokenType.LONGTEXT,
    132            "MEDIUMBLOB": TokenType.MEDIUMBLOB,
    133            "MEDIUMTEXT": TokenType.MEDIUMTEXT,
    134            "MEMBER OF": TokenType.MEMBER_OF,
    135            "SEPARATOR": TokenType.SEPARATOR,
    136            "START": TokenType.BEGIN,
    137            "SIGNED": TokenType.BIGINT,
    138            "SIGNED INTEGER": TokenType.BIGINT,
    139            "UNSIGNED": TokenType.UBIGINT,
    140            "UNSIGNED INTEGER": TokenType.UBIGINT,
    141            "_ARMSCII8": TokenType.INTRODUCER,
    142            "_ASCII": TokenType.INTRODUCER,
    143            "_BIG5": TokenType.INTRODUCER,
    144            "_BINARY": TokenType.INTRODUCER,
    145            "_CP1250": TokenType.INTRODUCER,
    146            "_CP1251": TokenType.INTRODUCER,
    147            "_CP1256": TokenType.INTRODUCER,
    148            "_CP1257": TokenType.INTRODUCER,
    149            "_CP850": TokenType.INTRODUCER,
    150            "_CP852": TokenType.INTRODUCER,
    151            "_CP866": TokenType.INTRODUCER,
    152            "_CP932": TokenType.INTRODUCER,
    153            "_DEC8": TokenType.INTRODUCER,
    154            "_EUCJPMS": TokenType.INTRODUCER,
    155            "_EUCKR": TokenType.INTRODUCER,
    156            "_GB18030": TokenType.INTRODUCER,
    157            "_GB2312": TokenType.INTRODUCER,
    158            "_GBK": TokenType.INTRODUCER,
    159            "_GEOSTD8": TokenType.INTRODUCER,
    160            "_GREEK": TokenType.INTRODUCER,
    161            "_HEBREW": TokenType.INTRODUCER,
    162            "_HP8": TokenType.INTRODUCER,
    163            "_KEYBCS2": TokenType.INTRODUCER,
    164            "_KOI8R": TokenType.INTRODUCER,
    165            "_KOI8U": TokenType.INTRODUCER,
    166            "_LATIN1": TokenType.INTRODUCER,
    167            "_LATIN2": TokenType.INTRODUCER,
    168            "_LATIN5": TokenType.INTRODUCER,
    169            "_LATIN7": TokenType.INTRODUCER,
    170            "_MACCE": TokenType.INTRODUCER,
    171            "_MACROMAN": TokenType.INTRODUCER,
    172            "_SJIS": TokenType.INTRODUCER,
    173            "_SWE7": TokenType.INTRODUCER,
    174            "_TIS620": TokenType.INTRODUCER,
    175            "_UCS2": TokenType.INTRODUCER,
    176            "_UJIS": TokenType.INTRODUCER,
    177            # https://dev.mysql.com/doc/refman/8.0/en/string-literals.html
    178            "_UTF8": TokenType.INTRODUCER,
    179            "_UTF16": TokenType.INTRODUCER,
    180            "_UTF16LE": TokenType.INTRODUCER,
    181            "_UTF32": TokenType.INTRODUCER,
    182            "_UTF8MB3": TokenType.INTRODUCER,
    183            "_UTF8MB4": TokenType.INTRODUCER,
    184            "@@": TokenType.SESSION_PARAMETER,
    185        }
    186
    187        COMMANDS = tokens.Tokenizer.COMMANDS - {TokenType.SHOW}
    188
    189    class Parser(parser.Parser):
    190        FUNC_TOKENS = {
    191            *parser.Parser.FUNC_TOKENS,
    192            TokenType.DATABASE,
    193            TokenType.SCHEMA,
    194            TokenType.VALUES,
    195        }
    196
    197        CONJUNCTION = {
    198            **parser.Parser.CONJUNCTION,
    199            TokenType.DAMP: exp.And,
    200            TokenType.XOR: exp.Xor,
    201        }
    202
    203        TABLE_ALIAS_TOKENS = (
    204            parser.Parser.TABLE_ALIAS_TOKENS - parser.Parser.TABLE_INDEX_HINT_TOKENS
    205        )
    206
    207        RANGE_PARSERS = {
    208            **parser.Parser.RANGE_PARSERS,
    209            TokenType.MEMBER_OF: lambda self, this: self.expression(
    210                exp.JSONArrayContains,
    211                this=this,
    212                expression=self._parse_wrapped(self._parse_expression),
    213            ),
    214        }
    215
    216        FUNCTIONS = {
    217            **parser.Parser.FUNCTIONS,
    218            "DATE_ADD": parse_date_delta_with_interval(exp.DateAdd),
    219            "DATE_FORMAT": format_time_lambda(exp.TimeToStr, "mysql"),
    220            "DATE_SUB": parse_date_delta_with_interval(exp.DateSub),
    221            "INSTR": lambda args: exp.StrPosition(substr=seq_get(args, 1), this=seq_get(args, 0)),
    222            "LOCATE": locate_to_strposition,
    223            "STR_TO_DATE": _str_to_date,
    224        }
    225
    226        FUNCTION_PARSERS = {
    227            **parser.Parser.FUNCTION_PARSERS,
    228            "GROUP_CONCAT": lambda self: self.expression(
    229                exp.GroupConcat,
    230                this=self._parse_lambda(),
    231                separator=self._match(TokenType.SEPARATOR) and self._parse_field(),
    232            ),
    233            # https://dev.mysql.com/doc/refman/5.7/en/miscellaneous-functions.html#function_values
    234            "VALUES": lambda self: self.expression(
    235                exp.Anonymous, this="VALUES", expressions=[self._parse_id_var()]
    236            ),
    237        }
    238
    239        STATEMENT_PARSERS = {
    240            **parser.Parser.STATEMENT_PARSERS,
    241            TokenType.SHOW: lambda self: self._parse_show(),
    242        }
    243
    244        SHOW_PARSERS = {
    245            "BINARY LOGS": _show_parser("BINARY LOGS"),
    246            "MASTER LOGS": _show_parser("BINARY LOGS"),
    247            "BINLOG EVENTS": _show_parser("BINLOG EVENTS"),
    248            "CHARACTER SET": _show_parser("CHARACTER SET"),
    249            "CHARSET": _show_parser("CHARACTER SET"),
    250            "COLLATION": _show_parser("COLLATION"),
    251            "FULL COLUMNS": _show_parser("COLUMNS", target="FROM", full=True),
    252            "COLUMNS": _show_parser("COLUMNS", target="FROM"),
    253            "CREATE DATABASE": _show_parser("CREATE DATABASE", target=True),
    254            "CREATE EVENT": _show_parser("CREATE EVENT", target=True),
    255            "CREATE FUNCTION": _show_parser("CREATE FUNCTION", target=True),
    256            "CREATE PROCEDURE": _show_parser("CREATE PROCEDURE", target=True),
    257            "CREATE TABLE": _show_parser("CREATE TABLE", target=True),
    258            "CREATE TRIGGER": _show_parser("CREATE TRIGGER", target=True),
    259            "CREATE VIEW": _show_parser("CREATE VIEW", target=True),
    260            "DATABASES": _show_parser("DATABASES"),
    261            "ENGINE": _show_parser("ENGINE", target=True),
    262            "STORAGE ENGINES": _show_parser("ENGINES"),
    263            "ENGINES": _show_parser("ENGINES"),
    264            "ERRORS": _show_parser("ERRORS"),
    265            "EVENTS": _show_parser("EVENTS"),
    266            "FUNCTION CODE": _show_parser("FUNCTION CODE", target=True),
    267            "FUNCTION STATUS": _show_parser("FUNCTION STATUS"),
    268            "GRANTS": _show_parser("GRANTS", target="FOR"),
    269            "INDEX": _show_parser("INDEX", target="FROM"),
    270            "MASTER STATUS": _show_parser("MASTER STATUS"),
    271            "OPEN TABLES": _show_parser("OPEN TABLES"),
    272            "PLUGINS": _show_parser("PLUGINS"),
    273            "PROCEDURE CODE": _show_parser("PROCEDURE CODE", target=True),
    274            "PROCEDURE STATUS": _show_parser("PROCEDURE STATUS"),
    275            "PRIVILEGES": _show_parser("PRIVILEGES"),
    276            "FULL PROCESSLIST": _show_parser("PROCESSLIST", full=True),
    277            "PROCESSLIST": _show_parser("PROCESSLIST"),
    278            "PROFILE": _show_parser("PROFILE"),
    279            "PROFILES": _show_parser("PROFILES"),
    280            "RELAYLOG EVENTS": _show_parser("RELAYLOG EVENTS"),
    281            "REPLICAS": _show_parser("REPLICAS"),
    282            "SLAVE HOSTS": _show_parser("REPLICAS"),
    283            "REPLICA STATUS": _show_parser("REPLICA STATUS"),
    284            "SLAVE STATUS": _show_parser("REPLICA STATUS"),
    285            "GLOBAL STATUS": _show_parser("STATUS", global_=True),
    286            "SESSION STATUS": _show_parser("STATUS"),
    287            "STATUS": _show_parser("STATUS"),
    288            "TABLE STATUS": _show_parser("TABLE STATUS"),
    289            "FULL TABLES": _show_parser("TABLES", full=True),
    290            "TABLES": _show_parser("TABLES"),
    291            "TRIGGERS": _show_parser("TRIGGERS"),
    292            "GLOBAL VARIABLES": _show_parser("VARIABLES", global_=True),
    293            "SESSION VARIABLES": _show_parser("VARIABLES"),
    294            "VARIABLES": _show_parser("VARIABLES"),
    295            "WARNINGS": _show_parser("WARNINGS"),
    296        }
    297
    298        SET_PARSERS = {
    299            **parser.Parser.SET_PARSERS,
    300            "PERSIST": lambda self: self._parse_set_item_assignment("PERSIST"),
    301            "PERSIST_ONLY": lambda self: self._parse_set_item_assignment("PERSIST_ONLY"),
    302            "CHARACTER SET": lambda self: self._parse_set_item_charset("CHARACTER SET"),
    303            "CHARSET": lambda self: self._parse_set_item_charset("CHARACTER SET"),
    304            "NAMES": lambda self: self._parse_set_item_names(),
    305        }
    306
    307        PROFILE_TYPES = {
    308            "ALL",
    309            "BLOCK IO",
    310            "CONTEXT SWITCHES",
    311            "CPU",
    312            "IPC",
    313            "MEMORY",
    314            "PAGE FAULTS",
    315            "SOURCE",
    316            "SWAPS",
    317        }
    318
    319        TYPE_TOKENS = {
    320            *parser.Parser.TYPE_TOKENS,
    321            TokenType.SET,
    322        }
    323
    324        ENUM_TYPE_TOKENS = {
    325            *parser.Parser.ENUM_TYPE_TOKENS,
    326            TokenType.SET,
    327        }
    328
    329        LOG_DEFAULTS_TO_LN = True
    330
    331        def _parse_show_mysql(
    332            self,
    333            this: str,
    334            target: bool | str = False,
    335            full: t.Optional[bool] = None,
    336            global_: t.Optional[bool] = None,
    337        ) -> exp.Show:
    338            if target:
    339                if isinstance(target, str):
    340                    self._match_text_seq(target)
    341                target_id = self._parse_id_var()
    342            else:
    343                target_id = None
    344
    345            log = self._parse_string() if self._match_text_seq("IN") else None
    346
    347            if this in {"BINLOG EVENTS", "RELAYLOG EVENTS"}:
    348                position = self._parse_number() if self._match_text_seq("FROM") else None
    349                db = None
    350            else:
    351                position = None
    352                db = None
    353
    354                if self._match(TokenType.FROM):
    355                    db = self._parse_id_var()
    356                elif self._match(TokenType.DOT):
    357                    db = target_id
    358                    target_id = self._parse_id_var()
    359
    360            channel = self._parse_id_var() if self._match_text_seq("FOR", "CHANNEL") else None
    361
    362            like = self._parse_string() if self._match_text_seq("LIKE") else None
    363            where = self._parse_where()
    364
    365            if this == "PROFILE":
    366                types = self._parse_csv(lambda: self._parse_var_from_options(self.PROFILE_TYPES))
    367                query = self._parse_number() if self._match_text_seq("FOR", "QUERY") else None
    368                offset = self._parse_number() if self._match_text_seq("OFFSET") else None
    369                limit = self._parse_number() if self._match_text_seq("LIMIT") else None
    370            else:
    371                types, query = None, None
    372                offset, limit = self._parse_oldstyle_limit()
    373
    374            mutex = True if self._match_text_seq("MUTEX") else None
    375            mutex = False if self._match_text_seq("STATUS") else mutex
    376
    377            return self.expression(
    378                exp.Show,
    379                this=this,
    380                target=target_id,
    381                full=full,
    382                log=log,
    383                position=position,
    384                db=db,
    385                channel=channel,
    386                like=like,
    387                where=where,
    388                types=types,
    389                query=query,
    390                offset=offset,
    391                limit=limit,
    392                mutex=mutex,
    393                **{"global": global_},  # type: ignore
    394            )
    395
    396        def _parse_oldstyle_limit(
    397            self,
    398        ) -> t.Tuple[t.Optional[exp.Expression], t.Optional[exp.Expression]]:
    399            limit = None
    400            offset = None
    401            if self._match_text_seq("LIMIT"):
    402                parts = self._parse_csv(self._parse_number)
    403                if len(parts) == 1:
    404                    limit = parts[0]
    405                elif len(parts) == 2:
    406                    limit = parts[1]
    407                    offset = parts[0]
    408
    409            return offset, limit
    410
    411        def _parse_set_item_charset(self, kind: str) -> exp.Expression:
    412            this = self._parse_string() or self._parse_id_var()
    413            return self.expression(exp.SetItem, this=this, kind=kind)
    414
    415        def _parse_set_item_names(self) -> exp.Expression:
    416            charset = self._parse_string() or self._parse_id_var()
    417            if self._match_text_seq("COLLATE"):
    418                collate = self._parse_string() or self._parse_id_var()
    419            else:
    420                collate = None
    421
    422            return self.expression(exp.SetItem, this=charset, collate=collate, kind="NAMES")
    423
    424    class Generator(generator.Generator):
    425        LOCKING_READS_SUPPORTED = True
    426        NULL_ORDERING_SUPPORTED = False
    427        JOIN_HINTS = False
    428        TABLE_HINTS = True
    429        DUPLICATE_KEY_UPDATE_WITH_SET = False
    430        QUERY_HINT_SEP = " "
    431
    432        TRANSFORMS = {
    433            **generator.Generator.TRANSFORMS,
    434            exp.CurrentDate: no_paren_current_date_sql,
    435            exp.DateDiff: lambda self, e: self.func("DATEDIFF", e.this, e.expression),
    436            exp.DateAdd: _date_add_sql("ADD"),
    437            exp.DateStrToDate: datestrtodate_sql,
    438            exp.DateSub: _date_add_sql("SUB"),
    439            exp.DateTrunc: _date_trunc_sql,
    440            exp.DayOfMonth: rename_func("DAYOFMONTH"),
    441            exp.DayOfWeek: rename_func("DAYOFWEEK"),
    442            exp.DayOfYear: rename_func("DAYOFYEAR"),
    443            exp.GroupConcat: lambda self, e: f"""GROUP_CONCAT({self.sql(e, "this")} SEPARATOR {self.sql(e, "separator") or "','"})""",
    444            exp.ILike: no_ilike_sql,
    445            exp.JSONExtractScalar: arrow_json_extract_scalar_sql,
    446            exp.Max: max_or_greatest,
    447            exp.Min: min_or_least,
    448            exp.NullSafeEQ: lambda self, e: self.binary(e, "<=>"),
    449            exp.NullSafeNEQ: lambda self, e: self.not_sql(self.binary(e, "<=>")),
    450            exp.Pivot: no_pivot_sql,
    451            exp.Select: transforms.preprocess([transforms.eliminate_distinct_on]),
    452            exp.StrPosition: strposition_to_locate_sql,
    453            exp.StrToDate: _str_to_date_sql,
    454            exp.StrToTime: _str_to_date_sql,
    455            exp.TableSample: no_tablesample_sql,
    456            exp.TimeStrToUnix: rename_func("UNIX_TIMESTAMP"),
    457            exp.TimeToStr: lambda self, e: self.func("DATE_FORMAT", e.this, self.format_time(e)),
    458            exp.Trim: _trim_sql,
    459            exp.TryCast: no_trycast_sql,
    460            exp.WeekOfYear: rename_func("WEEKOFYEAR"),
    461        }
    462
    463        TYPE_MAPPING = generator.Generator.TYPE_MAPPING.copy()
    464        TYPE_MAPPING.pop(exp.DataType.Type.MEDIUMTEXT)
    465        TYPE_MAPPING.pop(exp.DataType.Type.LONGTEXT)
    466        TYPE_MAPPING.pop(exp.DataType.Type.MEDIUMBLOB)
    467        TYPE_MAPPING.pop(exp.DataType.Type.LONGBLOB)
    468
    469        PROPERTIES_LOCATION = {
    470            **generator.Generator.PROPERTIES_LOCATION,
    471            exp.TransientProperty: exp.Properties.Location.UNSUPPORTED,
    472            exp.VolatileProperty: exp.Properties.Location.UNSUPPORTED,
    473        }
    474
    475        LIMIT_FETCH = "LIMIT"
    476
    477        def jsonarraycontains_sql(self, expression: exp.JSONArrayContains) -> str:
    478            return f"{self.sql(expression, 'this')} MEMBER OF({self.sql(expression, 'expression')})"
    479
    480        def cast_sql(self, expression: exp.Cast, safe_prefix: t.Optional[str] = None) -> str:
    481            """(U)BIGINT is not allowed in a CAST expression, so we use (UN)SIGNED instead."""
    482            if expression.to.this == exp.DataType.Type.BIGINT:
    483                to = "SIGNED"
    484            elif expression.to.this == exp.DataType.Type.UBIGINT:
    485                to = "UNSIGNED"
    486            else:
    487                return super().cast_sql(expression)
    488
    489            return f"CAST({self.sql(expression, 'this')} AS {to})"
    490
    491        def show_sql(self, expression: exp.Show) -> str:
    492            this = f" {expression.name}"
    493            full = " FULL" if expression.args.get("full") else ""
    494            global_ = " GLOBAL" if expression.args.get("global") else ""
    495
    496            target = self.sql(expression, "target")
    497            target = f" {target}" if target else ""
    498            if expression.name in {"COLUMNS", "INDEX"}:
    499                target = f" FROM{target}"
    500            elif expression.name == "GRANTS":
    501                target = f" FOR{target}"
    502
    503            db = self._prefixed_sql("FROM", expression, "db")
    504
    505            like = self._prefixed_sql("LIKE", expression, "like")
    506            where = self.sql(expression, "where")
    507
    508            types = self.expressions(expression, key="types")
    509            types = f" {types}" if types else types
    510            query = self._prefixed_sql("FOR QUERY", expression, "query")
    511
    512            if expression.name == "PROFILE":
    513                offset = self._prefixed_sql("OFFSET", expression, "offset")
    514                limit = self._prefixed_sql("LIMIT", expression, "limit")
    515            else:
    516                offset = ""
    517                limit = self._oldstyle_limit_sql(expression)
    518
    519            log = self._prefixed_sql("IN", expression, "log")
    520            position = self._prefixed_sql("FROM", expression, "position")
    521
    522            channel = self._prefixed_sql("FOR CHANNEL", expression, "channel")
    523
    524            if expression.name == "ENGINE":
    525                mutex_or_status = " MUTEX" if expression.args.get("mutex") else " STATUS"
    526            else:
    527                mutex_or_status = ""
    528
    529            return f"SHOW{full}{global_}{this}{target}{types}{db}{query}{log}{position}{channel}{mutex_or_status}{like}{where}{offset}{limit}"
    530
    531        def _prefixed_sql(self, prefix: str, expression: exp.Expression, arg: str) -> str:
    532            sql = self.sql(expression, arg)
    533            return f" {prefix} {sql}" if sql else ""
    534
    535        def _oldstyle_limit_sql(self, expression: exp.Show) -> str:
    536            limit = self.sql(expression, "limit")
    537            offset = self.sql(expression, "offset")
    538            if limit:
    539                limit_offset = f"{offset}, {limit}" if offset else limit
    540                return f" LIMIT {limit_offset}"
    541            return ""

TIME_FORMAT = "'%Y-%m-%d %T'"
TIME_MAPPING: Dict[str, str] = {'%M': '%B', '%c': '%-m', '%e': '%-d', '%h': '%I', '%i': '%M', '%s': '%S', '%S': '%S', '%u': '%W', '%k': '%-H', '%l': '%-I', '%T': '%H:%M:%S', '%W': '%a'}
tokenizer_class = <class 'sqlglot.dialects.mysql.MySQL.Tokenizer'>
parser_class = <class 'sqlglot.dialects.mysql.MySQL.Parser'>
generator_class = <class 'sqlglot.dialects.mysql.MySQL.Generator'>
TIME_TRIE: Dict = {'%': {'M': {0: True}, 'c': {0: True}, 'e': {0: True}, 'h': {0: True}, 'i': {0: True}, 's': {0: True}, 'S': {0: True}, 'u': {0: True}, 'k': {0: True}, 'l': {0: True}, 'T': {0: True}, 'W': {0: True}}}
FORMAT_TRIE: Dict = {'%': {'M': {0: True}, 'c': {0: True}, 'e': {0: True}, 'h': {0: True}, 'i': {0: True}, 's': {0: True}, 'S': {0: True}, 'u': {0: True}, 'k': {0: True}, 'l': {0: True}, 'T': {0: True}, 'W': {0: True}}}
INVERSE_TIME_MAPPING: Dict[str, str] = {'%B': '%M', '%-m': '%c', '%-d': '%e', '%I': '%h', '%M': '%i', '%S': '%S', '%W': '%u', '%-H': '%k', '%-I': '%l', '%H:%M:%S': '%T', '%a': '%W'}
INVERSE_TIME_TRIE: Dict = {'%': {'B': {0: True}, '-': {'m': {0: True}, 'd': {0: True}, 'H': {0: True}, 'I': {0: True}}, 'I': {0: True}, 'M': {0: True}, 'S': {0: True}, 'W': {0: True}, 'H': {':': {'%': {'M': {':': {'%': {'S': {0: True}}}}}}}, 'a': {0: True}}}
QUOTE_START = "'"
QUOTE_END = "'"
IDENTIFIER_START = '`'
IDENTIFIER_END = '`'
BIT_START = "b'"
BIT_END = "'"
HEX_START = "x'"
HEX_END = "'"
BYTE_START = None
BYTE_END = None

##### Inherited Members

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

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

    116    class Tokenizer(tokens.Tokenizer):
    117        QUOTES = ["'", '"']
    118        COMMENTS = ["--", "#", ("/*", "*/")]
    119        IDENTIFIERS = ["`"]
    120        STRING_ESCAPES = ["'", "\\"]
    121        BIT_STRINGS = [("b'", "'"), ("B'", "'"), ("0b", "")]
    122        HEX_STRINGS = [("x'", "'"), ("X'", "'"), ("0x", "")]
    123
    124        KEYWORDS = {
    125            **tokens.Tokenizer.KEYWORDS,
    126            "CHARSET": TokenType.CHARACTER_SET,
    127            "ENUM": TokenType.ENUM,
    128            "FORCE": TokenType.FORCE,
    129            "IGNORE": TokenType.IGNORE,
    130            "LONGBLOB": TokenType.LONGBLOB,
    131            "LONGTEXT": TokenType.LONGTEXT,
    132            "MEDIUMBLOB": TokenType.MEDIUMBLOB,
    133            "MEDIUMTEXT": TokenType.MEDIUMTEXT,
    134            "MEMBER OF": TokenType.MEMBER_OF,
    135            "SEPARATOR": TokenType.SEPARATOR,
    136            "START": TokenType.BEGIN,
    137            "SIGNED": TokenType.BIGINT,
    138            "SIGNED INTEGER": TokenType.BIGINT,
    139            "UNSIGNED": TokenType.UBIGINT,
    140            "UNSIGNED INTEGER": TokenType.UBIGINT,
    141            "_ARMSCII8": TokenType.INTRODUCER,
    142            "_ASCII": TokenType.INTRODUCER,
    143            "_BIG5": TokenType.INTRODUCER,
    144            "_BINARY": TokenType.INTRODUCER,
    145            "_CP1250": TokenType.INTRODUCER,
    146            "_CP1251": TokenType.INTRODUCER,
    147            "_CP1256": TokenType.INTRODUCER,
    148            "_CP1257": TokenType.INTRODUCER,
    149            "_CP850": TokenType.INTRODUCER,
    150            "_CP852": TokenType.INTRODUCER,
    151            "_CP866": TokenType.INTRODUCER,
    152            "_CP932": TokenType.INTRODUCER,
    153            "_DEC8": TokenType.INTRODUCER,
    154            "_EUCJPMS": TokenType.INTRODUCER,
    155            "_EUCKR": TokenType.INTRODUCER,
    156            "_GB18030": TokenType.INTRODUCER,
    157            "_GB2312": TokenType.INTRODUCER,
    158            "_GBK": TokenType.INTRODUCER,
    159            "_GEOSTD8": TokenType.INTRODUCER,
    160            "_GREEK": TokenType.INTRODUCER,
    161            "_HEBREW": TokenType.INTRODUCER,
    162            "_HP8": TokenType.INTRODUCER,
    163            "_KEYBCS2": TokenType.INTRODUCER,
    164            "_KOI8R": TokenType.INTRODUCER,
    165            "_KOI8U": TokenType.INTRODUCER,
    166            "_LATIN1": TokenType.INTRODUCER,
    167            "_LATIN2": TokenType.INTRODUCER,
    168            "_LATIN5": TokenType.INTRODUCER,
    169            "_LATIN7": TokenType.INTRODUCER,
    170            "_MACCE": TokenType.INTRODUCER,
    171            "_MACROMAN": TokenType.INTRODUCER,
    172            "_SJIS": TokenType.INTRODUCER,
    173            "_SWE7": TokenType.INTRODUCER,
    174            "_TIS620": TokenType.INTRODUCER,
    175            "_UCS2": TokenType.INTRODUCER,
    176            "_UJIS": TokenType.INTRODUCER,
    177            # https://dev.mysql.com/doc/refman/8.0/en/string-literals.html
    178            "_UTF8": TokenType.INTRODUCER,
    179            "_UTF16": TokenType.INTRODUCER,
    180            "_UTF16LE": TokenType.INTRODUCER,
    181            "_UTF32": TokenType.INTRODUCER,
    182            "_UTF8MB3": TokenType.INTRODUCER,
    183            "_UTF8MB4": TokenType.INTRODUCER,
    184            "@@": TokenType.SESSION_PARAMETER,
    185        }
    186
    187        COMMANDS = tokens.Tokenizer.COMMANDS - {TokenType.SHOW}

QUOTES = ["'", '"']
COMMENTS = ['--', '#', ('/*', '*/')]
IDENTIFIERS = ['`']
STRING_ESCAPES = ["'", '\\']
BIT_STRINGS = [("b'", "'"), ("B'", "'"), ('0b', '')]
HEX_STRINGS = [("x'", "'"), ("X'", "'"), ('0x', '')]
KEYWORDS = {'{%': <TokenType.BLOCK_START: 'BLOCK_START'>, '{%+': <TokenType.BLOCK_START: 'BLOCK_START'>, '{%-': <TokenType.BLOCK_START: 'BLOCK_START'>, '%}': <TokenType.BLOCK_END: 'BLOCK_END'>, '+%}': <TokenType.BLOCK_END: 'BLOCK_END'>, '-%}': <TokenType.BLOCK_END: 'BLOCK_END'>, '{{+': <TokenType.BLOCK_START: 'BLOCK_START'>, '{{-': <TokenType.BLOCK_START: 'BLOCK_START'>, '+}}': <TokenType.BLOCK_END: 'BLOCK_END'>, '-}}': <TokenType.BLOCK_END: 'BLOCK_END'>, '/*+': <TokenType.HINT: 'HINT'>, '==': <TokenType.EQ: 'EQ'>, '::': <TokenType.DCOLON: 'DCOLON'>, '||': <TokenType.DPIPE: 'DPIPE'>, '>=': <TokenType.GTE: 'GTE'>, '<=': <TokenType.LTE: 'LTE'>, '<>': <TokenType.NEQ: 'NEQ'>, '!=': <TokenType.NEQ: 'NEQ'>, '<=>': <TokenType.NULLSAFE_EQ: 'NULLSAFE_EQ'>, '->': <TokenType.ARROW: 'ARROW'>, '->>': <TokenType.DARROW: 'DARROW'>, '=>': <TokenType.FARROW: 'FARROW'>, '#>': <TokenType.HASH_ARROW: 'HASH_ARROW'>, '#>>': <TokenType.DHASH_ARROW: 'DHASH_ARROW'>, '<->': <TokenType.LR_ARROW: 'LR_ARROW'>, '&&': <TokenType.DAMP: 'DAMP'>, 'ALL': <TokenType.ALL: 'ALL'>, 'ALWAYS': <TokenType.ALWAYS: 'ALWAYS'>, 'AND': <TokenType.AND: 'AND'>, 'ANTI': <TokenType.ANTI: 'ANTI'>, 'ANY': <TokenType.ANY: 'ANY'>, 'ASC': <TokenType.ASC: 'ASC'>, 'AS': <TokenType.ALIAS: 'ALIAS'>, 'ASOF': <TokenType.ASOF: 'ASOF'>, 'AUTOINCREMENT': <TokenType.AUTO_INCREMENT: 'AUTO_INCREMENT'>, 'AUTO_INCREMENT': <TokenType.AUTO_INCREMENT: 'AUTO_INCREMENT'>, 'BEGIN': <TokenType.BEGIN: 'BEGIN'>, 'BETWEEN': <TokenType.BETWEEN: 'BETWEEN'>, 'CACHE': <TokenType.CACHE: 'CACHE'>, 'UNCACHE': <TokenType.UNCACHE: 'UNCACHE'>, 'CASE': <TokenType.CASE: 'CASE'>, 'CHARACTER SET': <TokenType.CHARACTER_SET: 'CHARACTER_SET'>, 'CLUSTER BY': <TokenType.CLUSTER_BY: 'CLUSTER_BY'>, 'COLLATE': <TokenType.COLLATE: 'COLLATE'>, 'COLUMN': <TokenType.COLUMN: 'COLUMN'>, 'COMMIT': <TokenType.COMMIT: 'COMMIT'>, 'CONSTRAINT': <TokenType.CONSTRAINT: 'CONSTRAINT'>, 'CREATE': <TokenType.CREATE: 'CREATE'>, 'CROSS': <TokenType.CROSS: 'CROSS'>, 'CUBE': <TokenType.CUBE: 'CUBE'>, 'CURRENT_DATE': <TokenType.CURRENT_DATE: 'CURRENT_DATE'>, 'CURRENT_TIME': <TokenType.CURRENT_TIME: 'CURRENT_TIME'>, 'CURRENT_TIMESTAMP': <TokenType.CURRENT_TIMESTAMP: 'CURRENT_TIMESTAMP'>, 'CURRENT_USER': <TokenType.CURRENT_USER: 'CURRENT_USER'>, 'DATABASE': <TokenType.DATABASE: 'DATABASE'>, 'DEFAULT': <TokenType.DEFAULT: 'DEFAULT'>, 'DELETE': <TokenType.DELETE: 'DELETE'>, 'DESC': <TokenType.DESC: 'DESC'>, 'DESCRIBE': <TokenType.DESCRIBE: 'DESCRIBE'>, 'DISTINCT': <TokenType.DISTINCT: 'DISTINCT'>, 'DISTRIBUTE BY': <TokenType.DISTRIBUTE_BY: 'DISTRIBUTE_BY'>, 'DIV': <TokenType.DIV: 'DIV'>, 'DROP': <TokenType.DROP: 'DROP'>, 'ELSE': <TokenType.ELSE: 'ELSE'>, 'END': <TokenType.END: 'END'>, 'ESCAPE': <TokenType.ESCAPE: 'ESCAPE'>, 'EXCEPT': <TokenType.EXCEPT: 'EXCEPT'>, 'EXECUTE': <TokenType.EXECUTE: 'EXECUTE'>, 'EXISTS': <TokenType.EXISTS: 'EXISTS'>, 'FALSE': <TokenType.FALSE: 'FALSE'>, 'FETCH': <TokenType.FETCH: 'FETCH'>, 'FILTER': <TokenType.FILTER: 'FILTER'>, 'FIRST': <TokenType.FIRST: 'FIRST'>, 'FULL': <TokenType.FULL: 'FULL'>, 'FUNCTION': <TokenType.FUNCTION: 'FUNCTION'>, 'FOR': <TokenType.FOR: 'FOR'>, 'FOREIGN KEY': <TokenType.FOREIGN_KEY: 'FOREIGN_KEY'>, 'FORMAT': <TokenType.FORMAT: 'FORMAT'>, 'FROM': <TokenType.FROM: 'FROM'>, 'GEOGRAPHY': <TokenType.GEOGRAPHY: 'GEOGRAPHY'>, 'GEOMETRY': <TokenType.GEOMETRY: 'GEOMETRY'>, 'GLOB': <TokenType.GLOB: 'GLOB'>, 'GROUP BY': <TokenType.GROUP_BY: 'GROUP_BY'>, 'GROUPING SETS': <TokenType.GROUPING_SETS: 'GROUPING_SETS'>, 'HAVING': <TokenType.HAVING: 'HAVING'>, 'IF': <TokenType.IF: 'IF'>, 'ILIKE': <TokenType.ILIKE: 'ILIKE'>, 'IN': <TokenType.IN: 'IN'>, 'INDEX': <TokenType.INDEX: 'INDEX'>, 'INET': <TokenType.INET: 'INET'>, 'INNER': <TokenType.INNER: 'INNER'>, 'INSERT': <TokenType.INSERT: 'INSERT'>, 'INTERVAL': <TokenType.INTERVAL: 'INTERVAL'>, 'INTERSECT': <TokenType.INTERSECT: 'INTERSECT'>, 'INTO': <TokenType.INTO: 'INTO'>, 'IS': <TokenType.IS: 'IS'>, 'ISNULL': <TokenType.ISNULL: 'ISNULL'>, 'JOIN': <TokenType.JOIN: 'JOIN'>, 'KEEP': <TokenType.KEEP: 'KEEP'>, 'LATERAL': <TokenType.LATERAL: 'LATERAL'>, 'LEFT': <TokenType.LEFT: 'LEFT'>, 'LIKE': <TokenType.LIKE: 'LIKE'>, 'LIMIT': <TokenType.LIMIT: 'LIMIT'>, 'LOAD': <TokenType.LOAD: 'LOAD'>, 'LOCK': <TokenType.LOCK: 'LOCK'>, 'MERGE': <TokenType.MERGE: 'MERGE'>, 'NATURAL': <TokenType.NATURAL: 'NATURAL'>, 'NEXT': <TokenType.NEXT: 'NEXT'>, 'NEXT VALUE FOR': <TokenType.NEXT_VALUE_FOR: 'NEXT_VALUE_FOR'>, 'NOT': <TokenType.NOT: 'NOT'>, 'NOTNULL': <TokenType.NOTNULL: 'NOTNULL'>, 'NULL': <TokenType.NULL: 'NULL'>, 'OBJECT': <TokenType.OBJECT: 'OBJECT'>, 'OFFSET': <TokenType.OFFSET: 'OFFSET'>, 'ON': <TokenType.ON: 'ON'>, 'OR': <TokenType.OR: 'OR'>, 'XOR': <TokenType.XOR: 'XOR'>, 'ORDER BY': <TokenType.ORDER_BY: 'ORDER_BY'>, 'ORDINALITY': <TokenType.ORDINALITY: 'ORDINALITY'>, 'OUTER': <TokenType.OUTER: 'OUTER'>, 'OVER': <TokenType.OVER: 'OVER'>, 'OVERLAPS': <TokenType.OVERLAPS: 'OVERLAPS'>, 'OVERWRITE': <TokenType.OVERWRITE: 'OVERWRITE'>, 'PARTITION': <TokenType.PARTITION: 'PARTITION'>, 'PARTITION BY': <TokenType.PARTITION_BY: 'PARTITION_BY'>, 'PARTITIONED BY': <TokenType.PARTITION_BY: 'PARTITION_BY'>, 'PARTITIONED_BY': <TokenType.PARTITION_BY: 'PARTITION_BY'>, 'PERCENT': <TokenType.PERCENT: 'PERCENT'>, 'PIVOT': <TokenType.PIVOT: 'PIVOT'>, 'PRAGMA': <TokenType.PRAGMA: 'PRAGMA'>, 'PRIMARY KEY': <TokenType.PRIMARY_KEY: 'PRIMARY_KEY'>, 'PROCEDURE': <TokenType.PROCEDURE: 'PROCEDURE'>, 'QUALIFY': <TokenType.QUALIFY: 'QUALIFY'>, 'RANGE': <TokenType.RANGE: 'RANGE'>, 'RECURSIVE': <TokenType.RECURSIVE: 'RECURSIVE'>, 'REGEXP': <TokenType.RLIKE: 'RLIKE'>, 'REPLACE': <TokenType.REPLACE: 'REPLACE'>, 'RETURNING': <TokenType.RETURNING: 'RETURNING'>, 'REFERENCES': <TokenType.REFERENCES: 'REFERENCES'>, 'RIGHT': <TokenType.RIGHT: 'RIGHT'>, 'RLIKE': <TokenType.RLIKE: 'RLIKE'>, 'ROLLBACK': <TokenType.ROLLBACK: 'ROLLBACK'>, 'ROLLUP': <TokenType.ROLLUP: 'ROLLUP'>, 'ROW': <TokenType.ROW: 'ROW'>, 'ROWS': <TokenType.ROWS: 'ROWS'>, 'SCHEMA': <TokenType.SCHEMA: 'SCHEMA'>, 'SELECT': <TokenType.SELECT: 'SELECT'>, 'SEMI': <TokenType.SEMI: 'SEMI'>, 'SET': <TokenType.SET: 'SET'>, 'SETTINGS': <TokenType.SETTINGS: 'SETTINGS'>, 'SHOW': <TokenType.SHOW: 'SHOW'>, 'SIMILAR TO': <TokenType.SIMILAR_TO: 'SIMILAR_TO'>, 'SOME': <TokenType.SOME: 'SOME'>, 'SORT BY': <TokenType.SORT_BY: 'SORT_BY'>, 'TABLE': <TokenType.TABLE: 'TABLE'>, 'TABLESAMPLE': <TokenType.TABLE_SAMPLE: 'TABLE_SAMPLE'>, 'TEMP': <TokenType.TEMPORARY: 'TEMPORARY'>, 'TEMPORARY': <TokenType.TEMPORARY: 'TEMPORARY'>, 'THEN': <TokenType.THEN: 'THEN'>, 'TRUE': <TokenType.TRUE: 'TRUE'>, 'UNION': <TokenType.UNION: 'UNION'>, 'UNNEST': <TokenType.UNNEST: 'UNNEST'>, 'UNPIVOT': <TokenType.UNPIVOT: 'UNPIVOT'>, 'UPDATE': <TokenType.UPDATE: 'UPDATE'>, 'USE': <TokenType.USE: 'USE'>, 'USING': <TokenType.USING: 'USING'>, 'UUID': <TokenType.UUID: 'UUID'>, 'VALUES': <TokenType.VALUES: 'VALUES'>, 'VIEW': <TokenType.VIEW: 'VIEW'>, 'VOLATILE': <TokenType.VOLATILE: 'VOLATILE'>, 'WHEN': <TokenType.WHEN: 'WHEN'>, 'WHERE': <TokenType.WHERE: 'WHERE'>, 'WINDOW': <TokenType.WINDOW: 'WINDOW'>, 'WITH': <TokenType.WITH: 'WITH'>, 'APPLY': <TokenType.APPLY: 'APPLY'>, 'ARRAY': <TokenType.ARRAY: 'ARRAY'>, 'BIT': <TokenType.BIT: 'BIT'>, 'BOOL': <TokenType.BOOLEAN: 'BOOLEAN'>, 'BOOLEAN': <TokenType.BOOLEAN: 'BOOLEAN'>, 'BYTE': <TokenType.TINYINT: 'TINYINT'>, 'TINYINT': <TokenType.TINYINT: 'TINYINT'>, 'SHORT': <TokenType.SMALLINT: 'SMALLINT'>, 'SMALLINT': <TokenType.SMALLINT: 'SMALLINT'>, 'INT2': <TokenType.SMALLINT: 'SMALLINT'>, 'INTEGER': <TokenType.INT: 'INT'>, 'INT': <TokenType.INT: 'INT'>, 'INT4': <TokenType.INT: 'INT'>, 'LONG': <TokenType.BIGINT: 'BIGINT'>, 'BIGINT': <TokenType.BIGINT: 'BIGINT'>, 'INT8': <TokenType.BIGINT: 'BIGINT'>, 'DEC': <TokenType.DECIMAL: 'DECIMAL'>, 'DECIMAL': <TokenType.DECIMAL: 'DECIMAL'>, 'BIGDECIMAL': <TokenType.BIGDECIMAL: 'BIGDECIMAL'>, 'BIGNUMERIC': <TokenType.BIGDECIMAL: 'BIGDECIMAL'>, 'MAP': <TokenType.MAP: 'MAP'>, 'NULLABLE': <TokenType.NULLABLE: 'NULLABLE'>, 'NUMBER': <TokenType.DECIMAL: 'DECIMAL'>, 'NUMERIC': <TokenType.DECIMAL: 'DECIMAL'>, 'FIXED': <TokenType.DECIMAL: 'DECIMAL'>, 'REAL': <TokenType.FLOAT: 'FLOAT'>, 'FLOAT': <TokenType.FLOAT: 'FLOAT'>, 'FLOAT4': <TokenType.FLOAT: 'FLOAT'>, 'FLOAT8': <TokenType.DOUBLE: 'DOUBLE'>, 'DOUBLE': <TokenType.DOUBLE: 'DOUBLE'>, 'DOUBLE PRECISION': <TokenType.DOUBLE: 'DOUBLE'>, 'JSON': <TokenType.JSON: 'JSON'>, 'CHAR': <TokenType.CHAR: 'CHAR'>, 'CHARACTER': <TokenType.CHAR: 'CHAR'>, 'NCHAR': <TokenType.NCHAR: 'NCHAR'>, 'VARCHAR': <TokenType.VARCHAR: 'VARCHAR'>, 'VARCHAR2': <TokenType.VARCHAR: 'VARCHAR'>, 'NVARCHAR': <TokenType.NVARCHAR: 'NVARCHAR'>, 'NVARCHAR2': <TokenType.NVARCHAR: 'NVARCHAR'>, 'STR': <TokenType.TEXT: 'TEXT'>, 'STRING': <TokenType.TEXT: 'TEXT'>, 'TEXT': <TokenType.TEXT: 'TEXT'>, 'CLOB': <TokenType.TEXT: 'TEXT'>, 'LONGVARCHAR': <TokenType.TEXT: 'TEXT'>, 'BINARY': <TokenType.BINARY: 'BINARY'>, 'BLOB': <TokenType.VARBINARY: 'VARBINARY'>, 'BYTEA': <TokenType.VARBINARY: 'VARBINARY'>, 'VARBINARY': <TokenType.VARBINARY: 'VARBINARY'>, 'TIME': <TokenType.TIME: 'TIME'>, 'TIMESTAMP': <TokenType.TIMESTAMP: 'TIMESTAMP'>, 'TIMESTAMPTZ': <TokenType.TIMESTAMPTZ: 'TIMESTAMPTZ'>, 'TIMESTAMPLTZ': <TokenType.TIMESTAMPLTZ: 'TIMESTAMPLTZ'>, 'DATE': <TokenType.DATE: 'DATE'>, 'DATETIME': <TokenType.DATETIME: 'DATETIME'>, 'INT4RANGE': <TokenType.INT4RANGE: 'INT4RANGE'>, 'INT4MULTIRANGE': <TokenType.INT4MULTIRANGE: 'INT4MULTIRANGE'>, 'INT8RANGE': <TokenType.INT8RANGE: 'INT8RANGE'>, 'INT8MULTIRANGE': <TokenType.INT8MULTIRANGE: 'INT8MULTIRANGE'>, 'NUMRANGE': <TokenType.NUMRANGE: 'NUMRANGE'>, 'NUMMULTIRANGE': <TokenType.NUMMULTIRANGE: 'NUMMULTIRANGE'>, 'TSRANGE': <TokenType.TSRANGE: 'TSRANGE'>, 'TSMULTIRANGE': <TokenType.TSMULTIRANGE: 'TSMULTIRANGE'>, 'TSTZRANGE': <TokenType.TSTZRANGE: 'TSTZRANGE'>, 'TSTZMULTIRANGE': <TokenType.TSTZMULTIRANGE: 'TSTZMULTIRANGE'>, 'DATERANGE': <TokenType.DATERANGE: 'DATERANGE'>, 'DATEMULTIRANGE': <TokenType.DATEMULTIRANGE: 'DATEMULTIRANGE'>, 'UNIQUE': <TokenType.UNIQUE: 'UNIQUE'>, 'STRUCT': <TokenType.STRUCT: 'STRUCT'>, 'VARIANT': <TokenType.VARIANT: 'VARIANT'>, 'ALTER': <TokenType.ALTER: 'ALTER'>, 'ANALYZE': <TokenType.COMMAND: 'COMMAND'>, 'CALL': <TokenType.COMMAND: 'COMMAND'>, 'COMMENT': <TokenType.COMMENT: 'COMMENT'>, 'COPY': <TokenType.COMMAND: 'COMMAND'>, 'EXPLAIN': <TokenType.COMMAND: 'COMMAND'>, 'GRANT': <TokenType.COMMAND: 'COMMAND'>, 'OPTIMIZE': <TokenType.COMMAND: 'COMMAND'>, 'PREPARE': <TokenType.COMMAND: 'COMMAND'>, 'TRUNCATE': <TokenType.COMMAND: 'COMMAND'>, 'VACUUM': <TokenType.COMMAND: 'COMMAND'>, 'USER-DEFINED': <TokenType.USERDEFINED: 'USERDEFINED'>, 'CHARSET': <TokenType.CHARACTER_SET: 'CHARACTER_SET'>, 'ENUM': <TokenType.ENUM: 'ENUM'>, 'FORCE': <TokenType.FORCE: 'FORCE'>, 'IGNORE': <TokenType.IGNORE: 'IGNORE'>, 'LONGBLOB': <TokenType.LONGBLOB: 'LONGBLOB'>, 'LONGTEXT': <TokenType.LONGTEXT: 'LONGTEXT'>, 'MEDIUMBLOB': <TokenType.MEDIUMBLOB: 'MEDIUMBLOB'>, 'MEDIUMTEXT': <TokenType.MEDIUMTEXT: 'MEDIUMTEXT'>, 'MEMBER OF': <TokenType.MEMBER_OF: 'MEMBER_OF'>, 'SEPARATOR': <TokenType.SEPARATOR: 'SEPARATOR'>, 'START': <TokenType.BEGIN: 'BEGIN'>, 'SIGNED': <TokenType.BIGINT: 'BIGINT'>, 'SIGNED INTEGER': <TokenType.BIGINT: 'BIGINT'>, 'UNSIGNED': <TokenType.UBIGINT: 'UBIGINT'>, 'UNSIGNED INTEGER': <TokenType.UBIGINT: 'UBIGINT'>, '_ARMSCII8': <TokenType.INTRODUCER: 'INTRODUCER'>, '_ASCII': <TokenType.INTRODUCER: 'INTRODUCER'>, '_BIG5': <TokenType.INTRODUCER: 'INTRODUCER'>, '_BINARY': <TokenType.INTRODUCER: 'INTRODUCER'>, '_CP1250': <TokenType.INTRODUCER: 'INTRODUCER'>, '_CP1251': <TokenType.INTRODUCER: 'INTRODUCER'>, '_CP1256': <TokenType.INTRODUCER: 'INTRODUCER'>, '_CP1257': <TokenType.INTRODUCER: 'INTRODUCER'>, '_CP850': <TokenType.INTRODUCER: 'INTRODUCER'>, '_CP852': <TokenType.INTRODUCER: 'INTRODUCER'>, '_CP866': <TokenType.INTRODUCER: 'INTRODUCER'>, '_CP932': <TokenType.INTRODUCER: 'INTRODUCER'>, '_DEC8': <TokenType.INTRODUCER: 'INTRODUCER'>, '_EUCJPMS': <TokenType.INTRODUCER: 'INTRODUCER'>, '_EUCKR': <TokenType.INTRODUCER: 'INTRODUCER'>, '_GB18030': <TokenType.INTRODUCER: 'INTRODUCER'>, '_GB2312': <TokenType.INTRODUCER: 'INTRODUCER'>, '_GBK': <TokenType.INTRODUCER: 'INTRODUCER'>, '_GEOSTD8': <TokenType.INTRODUCER: 'INTRODUCER'>, '_GREEK': <TokenType.INTRODUCER: 'INTRODUCER'>, '_HEBREW': <TokenType.INTRODUCER: 'INTRODUCER'>, '_HP8': <TokenType.INTRODUCER: 'INTRODUCER'>, '_KEYBCS2': <TokenType.INTRODUCER: 'INTRODUCER'>, '_KOI8R': <TokenType.INTRODUCER: 'INTRODUCER'>, '_KOI8U': <TokenType.INTRODUCER: 'INTRODUCER'>, '_LATIN1': <TokenType.INTRODUCER: 'INTRODUCER'>, '_LATIN2': <TokenType.INTRODUCER: 'INTRODUCER'>, '_LATIN5': <TokenType.INTRODUCER: 'INTRODUCER'>, '_LATIN7': <TokenType.INTRODUCER: 'INTRODUCER'>, '_MACCE': <TokenType.INTRODUCER: 'INTRODUCER'>, '_MACROMAN': <TokenType.INTRODUCER: 'INTRODUCER'>, '_SJIS': <TokenType.INTRODUCER: 'INTRODUCER'>, '_SWE7': <TokenType.INTRODUCER: 'INTRODUCER'>, '_TIS620': <TokenType.INTRODUCER: 'INTRODUCER'>, '_UCS2': <TokenType.INTRODUCER: 'INTRODUCER'>, '_UJIS': <TokenType.INTRODUCER: 'INTRODUCER'>, '_UTF8': <TokenType.INTRODUCER: 'INTRODUCER'>, '_UTF16': <TokenType.INTRODUCER: 'INTRODUCER'>, '_UTF16LE': <TokenType.INTRODUCER: 'INTRODUCER'>, '_UTF32': <TokenType.INTRODUCER: 'INTRODUCER'>, '_UTF8MB3': <TokenType.INTRODUCER: 'INTRODUCER'>, '_UTF8MB4': <TokenType.INTRODUCER: 'INTRODUCER'>, '@@': <TokenType.SESSION_PARAMETER: 'SESSION_PARAMETER'>}
COMMANDS = {<TokenType.EXECUTE: 'EXECUTE'>, <TokenType.COMMAND: 'COMMAND'>, <TokenType.FETCH: 'FETCH'>}

##### Inherited Members

sqlglot.tokens.Tokenizer
  SINGLE_TOKENS
  BYTE_STRINGS
  RAW_STRINGS
  IDENTIFIER_ESCAPES
  VAR_SINGLE_TOKENS
  IDENTIFIERS_CAN_START_WITH_DIGIT
  WHITE_SPACE
  COMMAND_PREFIX_TOKENS
  NUMERIC_LITERALS
  ENCODE
  reset
  tokenize
  peek
  size
  sql
  tokens

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

    189    class Parser(parser.Parser):
    190        FUNC_TOKENS = {
    191            *parser.Parser.FUNC_TOKENS,
    192            TokenType.DATABASE,
    193            TokenType.SCHEMA,
    194            TokenType.VALUES,
    195        }
    196
    197        CONJUNCTION = {
    198            **parser.Parser.CONJUNCTION,
    199            TokenType.DAMP: exp.And,
    200            TokenType.XOR: exp.Xor,
    201        }
    202
    203        TABLE_ALIAS_TOKENS = (
    204            parser.Parser.TABLE_ALIAS_TOKENS - parser.Parser.TABLE_INDEX_HINT_TOKENS
    205        )
    206
    207        RANGE_PARSERS = {
    208            **parser.Parser.RANGE_PARSERS,
    209            TokenType.MEMBER_OF: lambda self, this: self.expression(
    210                exp.JSONArrayContains,
    211                this=this,
    212                expression=self._parse_wrapped(self._parse_expression),
    213            ),
    214        }
    215
    216        FUNCTIONS = {
    217            **parser.Parser.FUNCTIONS,
    218            "DATE_ADD": parse_date_delta_with_interval(exp.DateAdd),
    219            "DATE_FORMAT": format_time_lambda(exp.TimeToStr, "mysql"),
    220            "DATE_SUB": parse_date_delta_with_interval(exp.DateSub),
    221            "INSTR": lambda args: exp.StrPosition(substr=seq_get(args, 1), this=seq_get(args, 0)),
    222            "LOCATE": locate_to_strposition,
    223            "STR_TO_DATE": _str_to_date,
    224        }
    225
    226        FUNCTION_PARSERS = {
    227            **parser.Parser.FUNCTION_PARSERS,
    228            "GROUP_CONCAT": lambda self: self.expression(
    229                exp.GroupConcat,
    230                this=self._parse_lambda(),
    231                separator=self._match(TokenType.SEPARATOR) and self._parse_field(),
    232            ),
    233            # https://dev.mysql.com/doc/refman/5.7/en/miscellaneous-functions.html#function_values
    234            "VALUES": lambda self: self.expression(
    235                exp.Anonymous, this="VALUES", expressions=[self._parse_id_var()]
    236            ),
    237        }
    238
    239        STATEMENT_PARSERS = {
    240            **parser.Parser.STATEMENT_PARSERS,
    241            TokenType.SHOW: lambda self: self._parse_show(),
    242        }
    243
    244        SHOW_PARSERS = {
    245            "BINARY LOGS": _show_parser("BINARY LOGS"),
    246            "MASTER LOGS": _show_parser("BINARY LOGS"),
    247            "BINLOG EVENTS": _show_parser("BINLOG EVENTS"),
    248            "CHARACTER SET": _show_parser("CHARACTER SET"),
    249            "CHARSET": _show_parser("CHARACTER SET"),
    250            "COLLATION": _show_parser("COLLATION"),
    251            "FULL COLUMNS": _show_parser("COLUMNS", target="FROM", full=True),
    252            "COLUMNS": _show_parser("COLUMNS", target="FROM"),
    253            "CREATE DATABASE": _show_parser("CREATE DATABASE", target=True),
    254            "CREATE EVENT": _show_parser("CREATE EVENT", target=True),
    255            "CREATE FUNCTION": _show_parser("CREATE FUNCTION", target=True),
    256            "CREATE PROCEDURE": _show_parser("CREATE PROCEDURE", target=True),
    257            "CREATE TABLE": _show_parser("CREATE TABLE", target=True),
    258            "CREATE TRIGGER": _show_parser("CREATE TRIGGER", target=True),
    259            "CREATE VIEW": _show_parser("CREATE VIEW", target=True),
    260            "DATABASES": _show_parser("DATABASES"),
    261            "ENGINE": _show_parser("ENGINE", target=True),
    262            "STORAGE ENGINES": _show_parser("ENGINES"),
    263            "ENGINES": _show_parser("ENGINES"),
    264            "ERRORS": _show_parser("ERRORS"),
    265            "EVENTS": _show_parser("EVENTS"),
    266            "FUNCTION CODE": _show_parser("FUNCTION CODE", target=True),
    267            "FUNCTION STATUS": _show_parser("FUNCTION STATUS"),
    268            "GRANTS": _show_parser("GRANTS", target="FOR"),
    269            "INDEX": _show_parser("INDEX", target="FROM"),
    270            "MASTER STATUS": _show_parser("MASTER STATUS"),
    271            "OPEN TABLES": _show_parser("OPEN TABLES"),
    272            "PLUGINS": _show_parser("PLUGINS"),
    273            "PROCEDURE CODE": _show_parser("PROCEDURE CODE", target=True),
    274            "PROCEDURE STATUS": _show_parser("PROCEDURE STATUS"),
    275            "PRIVILEGES": _show_parser("PRIVILEGES"),
    276            "FULL PROCESSLIST": _show_parser("PROCESSLIST", full=True),
    277            "PROCESSLIST": _show_parser("PROCESSLIST"),
    278            "PROFILE": _show_parser("PROFILE"),
    279            "PROFILES": _show_parser("PROFILES"),
    280            "RELAYLOG EVENTS": _show_parser("RELAYLOG EVENTS"),
    281            "REPLICAS": _show_parser("REPLICAS"),
    282            "SLAVE HOSTS": _show_parser("REPLICAS"),
    283            "REPLICA STATUS": _show_parser("REPLICA STATUS"),
    284            "SLAVE STATUS": _show_parser("REPLICA STATUS"),
    285            "GLOBAL STATUS": _show_parser("STATUS", global_=True),
    286            "SESSION STATUS": _show_parser("STATUS"),
    287            "STATUS": _show_parser("STATUS"),
    288            "TABLE STATUS": _show_parser("TABLE STATUS"),
    289            "FULL TABLES": _show_parser("TABLES", full=True),
    290            "TABLES": _show_parser("TABLES"),
    291            "TRIGGERS": _show_parser("TRIGGERS"),
    292            "GLOBAL VARIABLES": _show_parser("VARIABLES", global_=True),
    293            "SESSION VARIABLES": _show_parser("VARIABLES"),
    294            "VARIABLES": _show_parser("VARIABLES"),
    295            "WARNINGS": _show_parser("WARNINGS"),
    296        }
    297
    298        SET_PARSERS = {
    299            **parser.Parser.SET_PARSERS,
    300            "PERSIST": lambda self: self._parse_set_item_assignment("PERSIST"),
    301            "PERSIST_ONLY": lambda self: self._parse_set_item_assignment("PERSIST_ONLY"),
    302            "CHARACTER SET": lambda self: self._parse_set_item_charset("CHARACTER SET"),
    303            "CHARSET": lambda self: self._parse_set_item_charset("CHARACTER SET"),
    304            "NAMES": lambda self: self._parse_set_item_names(),
    305        }
    306
    307        PROFILE_TYPES = {
    308            "ALL",
    309            "BLOCK IO",
    310            "CONTEXT SWITCHES",
    311            "CPU",
    312            "IPC",
    313            "MEMORY",
    314            "PAGE FAULTS",
    315            "SOURCE",
    316            "SWAPS",
    317        }
    318
    319        TYPE_TOKENS = {
    320            *parser.Parser.TYPE_TOKENS,
    321            TokenType.SET,
    322        }
    323
    324        ENUM_TYPE_TOKENS = {
    325            *parser.Parser.ENUM_TYPE_TOKENS,
    326            TokenType.SET,
    327        }
    328
    329        LOG_DEFAULTS_TO_LN = True
    330
    331        def _parse_show_mysql(
    332            self,
    333            this: str,
    334            target: bool | str = False,
    335            full: t.Optional[bool] = None,
    336            global_: t.Optional[bool] = None,
    337        ) -> exp.Show:
    338            if target:
    339                if isinstance(target, str):
    340                    self._match_text_seq(target)
    341                target_id = self._parse_id_var()
    342            else:
    343                target_id = None
    344
    345            log = self._parse_string() if self._match_text_seq("IN") else None
    346
    347            if this in {"BINLOG EVENTS", "RELAYLOG EVENTS"}:
    348                position = self._parse_number() if self._match_text_seq("FROM") else None
    349                db = None
    350            else:
    351                position = None
    352                db = None
    353
    354                if self._match(TokenType.FROM):
    355                    db = self._parse_id_var()
    356                elif self._match(TokenType.DOT):
    357                    db = target_id
    358                    target_id = self._parse_id_var()
    359
    360            channel = self._parse_id_var() if self._match_text_seq("FOR", "CHANNEL") else None
    361
    362            like = self._parse_string() if self._match_text_seq("LIKE") else None
    363            where = self._parse_where()
    364
    365            if this == "PROFILE":
    366                types = self._parse_csv(lambda: self._parse_var_from_options(self.PROFILE_TYPES))
    367                query = self._parse_number() if self._match_text_seq("FOR", "QUERY") else None
    368                offset = self._parse_number() if self._match_text_seq("OFFSET") else None
    369                limit = self._parse_number() if self._match_text_seq("LIMIT") else None
    370            else:
    371                types, query = None, None
    372                offset, limit = self._parse_oldstyle_limit()
    373
    374            mutex = True if self._match_text_seq("MUTEX") else None
    375            mutex = False if self._match_text_seq("STATUS") else mutex
    376
    377            return self.expression(
    378                exp.Show,
    379                this=this,
    380                target=target_id,
    381                full=full,
    382                log=log,
    383                position=position,
    384                db=db,
    385                channel=channel,
    386                like=like,
    387                where=where,
    388                types=types,
    389                query=query,
    390                offset=offset,
    391                limit=limit,
    392                mutex=mutex,
    393                **{"global": global_},  # type: ignore
    394            )
    395
    396        def _parse_oldstyle_limit(
    397            self,
    398        ) -> t.Tuple[t.Optional[exp.Expression], t.Optional[exp.Expression]]:
    399            limit = None
    400            offset = None
    401            if self._match_text_seq("LIMIT"):
    402                parts = self._parse_csv(self._parse_number)
    403                if len(parts) == 1:
    404                    limit = parts[0]
    405                elif len(parts) == 2:
    406                    limit = parts[1]
    407                    offset = parts[0]
    408
    409            return offset, limit
    410
    411        def _parse_set_item_charset(self, kind: str) -> exp.Expression:
    412            this = self._parse_string() or self._parse_id_var()
    413            return self.expression(exp.SetItem, this=this, kind=kind)
    414
    415        def _parse_set_item_names(self) -> exp.Expression:
    416            charset = self._parse_string() or self._parse_id_var()
    417            if self._match_text_seq("COLLATE"):
    418                collate = self._parse_string() or self._parse_id_var()
    419            else:
    420                collate = None
    421
    422            return self.expression(exp.SetItem, this=charset, collate=collate, kind="NAMES")

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

###### Arguments:

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

FUNC_TOKENS = {<TokenType.DATETIME: 'DATETIME'>, <TokenType.HSTORE: 'HSTORE'>, <TokenType.SMALLINT: 'SMALLINT'>, <TokenType.CURRENT_TIMESTAMP: 'CURRENT_TIMESTAMP'>, <TokenType.HLLSKETCH: 'HLLSKETCH'>, <TokenType.TSMULTIRANGE: 'TSMULTIRANGE'>, <TokenType.GEOGRAPHY: 'GEOGRAPHY'>, <TokenType.IDENTIFIER: 'IDENTIFIER'>, <TokenType.MERGE: 'MERGE'>, <TokenType.OFFSET: 'OFFSET'>, <TokenType.UUID: 'UUID'>, <TokenType.ARRAY: 'ARRAY'>, <TokenType.TIMESTAMPTZ: 'TIMESTAMPTZ'>, <TokenType.ENUM: 'ENUM'>, <TokenType.NVARCHAR: 'NVARCHAR'>, <TokenType.VAR: 'VAR'>, <TokenType.UBIGINT: 'UBIGINT'>, <TokenType.ILIKE: 'ILIKE'>, <TokenType.USMALLINT: 'USMALLINT'>, <TokenType.INTERVAL: 'INTERVAL'>, <TokenType.TEXT: 'TEXT'>, <TokenType.REPLACE: 'REPLACE'>, <TokenType.WINDOW: 'WINDOW'>, <TokenType.CURRENT_TIME: 'CURRENT_TIME'>, <TokenType.CURRENT_USER: 'CURRENT_USER'>, <TokenType.TIME: 'TIME'>, <TokenType.GEOMETRY: 'GEOMETRY'>, <TokenType.DATERANGE: 'DATERANGE'>, <TokenType.DOUBLE: 'DOUBLE'>, <TokenType.DATE: 'DATE'>, <TokenType.SOME: 'SOME'>, <TokenType.INT8MULTIRANGE: 'INT8MULTIRANGE'>, <TokenType.SMALLSERIAL: 'SMALLSERIAL'>, <TokenType.RIGHT: 'RIGHT'>, <TokenType.TSTZMULTIRANGE: 'TSTZMULTIRANGE'>, <TokenType.MONEY: 'MONEY'>, <TokenType.CHAR: 'CHAR'>, <TokenType.ALL: 'ALL'>, <TokenType.VARCHAR: 'VARCHAR'>, <TokenType.TIMESTAMP: 'TIMESTAMP'>, <TokenType.PRIMARY_KEY: 'PRIMARY_KEY'>, <TokenType.BIGINT: 'BIGINT'>, <TokenType.UNIQUEIDENTIFIER: 'UNIQUEIDENTIFIER'>, <TokenType.LONGBLOB: 'LONGBLOB'>, <TokenType.LEFT: 'LEFT'>, <TokenType.NCHAR: 'NCHAR'>, <TokenType.UINT256: 'UINT256'>, <TokenType.INT256: 'INT256'>, <TokenType.SUPER: 'SUPER'>, <TokenType.LIKE: 'LIKE'>, <TokenType.FIRST: 'FIRST'>, <TokenType.TSRANGE: 'TSRANGE'>, <TokenType.DECIMAL: 'DECIMAL'>, <TokenType.EXISTS: 'EXISTS'>, <TokenType.ROW: 'ROW'>, <TokenType.ANY: 'ANY'>, <TokenType.MEDIUMBLOB: 'MEDIUMBLOB'>, <TokenType.CURRENT_DATETIME: 'CURRENT_DATETIME'>, <TokenType.JSON: 'JSON'>, <TokenType.FILTER: 'FILTER'>, <TokenType.UINT128: 'UINT128'>, <TokenType.SERIAL: 'SERIAL'>, <TokenType.NULLABLE: 'NULLABLE'>, <TokenType.MAP: 'MAP'>, <TokenType.SCHEMA: 'SCHEMA'>, <TokenType.UTINYINT: 'UTINYINT'>, <TokenType.MEDIUMTEXT: 'MEDIUMTEXT'>, <TokenType.UINT: 'UINT'>, <TokenType.NUMMULTIRANGE: 'NUMMULTIRANGE'>, <TokenType.DATETIME64: 'DATETIME64'>, <TokenType.BIGSERIAL: 'BIGSERIAL'>, <TokenType.STRUCT: 'STRUCT'>, <TokenType.ISNULL: 'ISNULL'>, <TokenType.TINYINT: 'TINYINT'>, <TokenType.RLIKE: 'RLIKE'>, <TokenType.OBJECT: 'OBJECT'>, <TokenType.INT8RANGE: 'INT8RANGE'>, <TokenType.TSTZRANGE: 'TSTZRANGE'>, <TokenType.BIGDECIMAL: 'BIGDECIMAL'>, <TokenType.VARBINARY: 'VARBINARY'>, <TokenType.INET: 'INET'>, <TokenType.BIT: 'BIT'>, <TokenType.FLOAT: 'FLOAT'>, <TokenType.XML: 'XML'>, <TokenType.RANGE: 'RANGE'>, <TokenType.NUMRANGE: 'NUMRANGE'>, <TokenType.LONGTEXT: 'LONGTEXT'>, <TokenType.INT128: 'INT128'>, <TokenType.FORMAT: 'FORMAT'>, <TokenType.BINARY: 'BINARY'>, <TokenType.VALUES: 'VALUES'>, <TokenType.VARIANT: 'VARIANT'>, <TokenType.CURRENT_DATE: 'CURRENT_DATE'>, <TokenType.GLOB: 'GLOB'>, <TokenType.SMALLMONEY: 'SMALLMONEY'>, <TokenType.PSEUDO_TYPE: 'PSEUDO_TYPE'>, <TokenType.DATEMULTIRANGE: 'DATEMULTIRANGE'>, <TokenType.DATABASE: 'DATABASE'>, <TokenType.UNNEST: 'UNNEST'>, <TokenType.USERDEFINED: 'USERDEFINED'>, <TokenType.TABLE: 'TABLE'>, <TokenType.ROWVERSION: 'ROWVERSION'>, <TokenType.BOOLEAN: 'BOOLEAN'>, <TokenType.IMAGE: 'IMAGE'>, <TokenType.COMMAND: 'COMMAND'>, <TokenType.TIMESTAMPLTZ: 'TIMESTAMPLTZ'>, <TokenType.INDEX: 'INDEX'>, <TokenType.INT: 'INT'>, <TokenType.JSONB: 'JSONB'>, <TokenType.INT4MULTIRANGE: 'INT4MULTIRANGE'>, <TokenType.INT4RANGE: 'INT4RANGE'>}
CONJUNCTION = {<TokenType.AND: 'AND'>: <class 'sqlglot.expressions.And'>, <TokenType.OR: 'OR'>: <class 'sqlglot.expressions.Or'>, <TokenType.DAMP: 'DAMP'>: <class 'sqlglot.expressions.And'>, <TokenType.XOR: 'XOR'>: <class 'sqlglot.expressions.Xor'>}
TABLE_ALIAS_TOKENS = {<TokenType.DATETIME: 'DATETIME'>, <TokenType.PIVOT: 'PIVOT'>, <TokenType.HSTORE: 'HSTORE'>, <TokenType.CURRENT_TIMESTAMP: 'CURRENT_TIMESTAMP'>, <TokenType.HLLSKETCH: 'HLLSKETCH'>, <TokenType.COMMENT: 'COMMENT'>, <TokenType.IS: 'IS'>, <TokenType.MERGE: 'MERGE'>, <TokenType.TIMESTAMPTZ: 'TIMESTAMPTZ'>, <TokenType.COLLATE: 'COLLATE'>, <TokenType.ENUM: 'ENUM'>, <TokenType.VAR: 'VAR'>, <TokenType.UBIGINT: 'UBIGINT'>, <TokenType.INTERVAL: 'INTERVAL'>, <TokenType.TEXT: 'TEXT'>, <TokenType.TRUE: 'TRUE'>, <TokenType.AUTO_INCREMENT: 'AUTO_INCREMENT'>, <TokenType.CURRENT_TIME: 'CURRENT_TIME'>, <TokenType.TIME: 'TIME'>, <TokenType.CURRENT_USER: 'CURRENT_USER'>, <TokenType.SOME: 'SOME'>, <TokenType.SMALLSERIAL: 'SMALLSERIAL'>, <TokenType.CONSTRAINT: 'CONSTRAINT'>, <TokenType.PROCEDURE: 'PROCEDURE'>, <TokenType.TSTZMULTIRANGE: 'TSTZMULTIRANGE'>, <TokenType.NEXT: 'NEXT'>, <TokenType.CHAR: 'CHAR'>, <TokenType.VARCHAR: 'VARCHAR'>, <TokenType.IF: 'IF'>, <TokenType.BIGINT: 'BIGINT'>, <TokenType.UNIQUEIDENTIFIER: 'UNIQUEIDENTIFIER'>, <TokenType.ASC: 'ASC'>, <TokenType.NCHAR: 'NCHAR'>, <TokenType.UINT256: 'UINT256'>, <TokenType.INT256: 'INT256'>, <TokenType.SUPER: 'SUPER'>, <TokenType.TSRANGE: 'TSRANGE'>, <TokenType.FIRST: 'FIRST'>, <TokenType.SHOW: 'SHOW'>, <TokenType.DECIMAL: 'DECIMAL'>, <TokenType.FUNCTION: 'FUNCTION'>, <TokenType.ROW: 'ROW'>, <TokenType.ANY: 'ANY'>, <TokenType.MEDIUMBLOB: 'MEDIUMBLOB'>, <TokenType.SET: 'SET'>, <TokenType.DESCRIBE: 'DESCRIBE'>, <TokenType.FILTER: 'FILTER'>, <TokenType.SERIAL: 'SERIAL'>, <TokenType.MAP: 'MAP'>, <TokenType.SCHEMA: 'SCHEMA'>, <TokenType.UTINYINT: 'UTINYINT'>, <TokenType.MEDIUMTEXT: 'MEDIUMTEXT'>, <TokenType.UINT: 'UINT'>, <TokenType.ORDINALITY: 'ORDINALITY'>, <TokenType.PRAGMA: 'PRAGMA'>, <TokenType.TINYINT: 'TINYINT'>, <TokenType.OBJECT: 'OBJECT'>, <TokenType.TSTZRANGE: 'TSTZRANGE'>, <TokenType.KEEP: 'KEEP'>, <TokenType.VARBINARY: 'VARBINARY'>, <TokenType.INET: 'INET'>, <TokenType.XML: 'XML'>, <TokenType.RANGE: 'RANGE'>, <TokenType.DIV: 'DIV'>, <TokenType.INT128: 'INT128'>, <TokenType.BINARY: 'BINARY'>, <TokenType.PARTITION: 'PARTITION'>, <TokenType.COLUMN: 'COLUMN'>, <TokenType.VARIANT: 'VARIANT'>, <TokenType.SMALLMONEY: 'SMALLMONEY'>, <TokenType.PSEUDO_TYPE: 'PSEUDO_TYPE'>, <TokenType.DATEMULTIRANGE: 'DATEMULTIRANGE'>, <TokenType.EXECUTE: 'EXECUTE'>, <TokenType.UNPIVOT: 'UNPIVOT'>, <TokenType.SEMI: 'SEMI'>, <TokenType.DICTIONARY: 'DICTIONARY'>, <TokenType.OVERWRITE: 'OVERWRITE'>, <TokenType.USERDEFINED: 'USERDEFINED'>, <TokenType.IMAGE: 'IMAGE'>, <TokenType.COMMAND: 'COMMAND'>, <TokenType.CASE: 'CASE'>, <TokenType.ROWS: 'ROWS'>, <TokenType.JSONB: 'JSONB'>, <TokenType.INT4RANGE: 'INT4RANGE'>, <TokenType.PERCENT: 'PERCENT'>, <TokenType.DELETE: 'DELETE'>, <TokenType.SMALLINT: 'SMALLINT'>, <TokenType.TSMULTIRANGE: 'TSMULTIRANGE'>, <TokenType.VOLATILE: 'VOLATILE'>, <TokenType.GEOGRAPHY: 'GEOGRAPHY'>, <TokenType.COMMIT: 'COMMIT'>, <TokenType.UUID: 'UUID'>, <TokenType.ARRAY: 'ARRAY'>, <TokenType.NVARCHAR: 'NVARCHAR'>, <TokenType.USMALLINT: 'USMALLINT'>, <TokenType.CACHE: 'CACHE'>, <TokenType.GEOMETRY: 'GEOMETRY'>, <TokenType.VIEW: 'VIEW'>, <TokenType.DATERANGE: 'DATERANGE'>, <TokenType.DOUBLE: 'DOUBLE'>, <TokenType.DATE: 'DATE'>, <TokenType.INT8MULTIRANGE: 'INT8MULTIRANGE'>, <TokenType.MONEY: 'MONEY'>, <TokenType.ALL: 'ALL'>, <TokenType.BEGIN: 'BEGIN'>, <TokenType.TIMESTAMP: 'TIMESTAMP'>, <TokenType.LONGBLOB: 'LONGBLOB'>, <TokenType.ANTI: 'ANTI'>, <TokenType.EXISTS: 'EXISTS'>, <TokenType.CURRENT_DATETIME: 'CURRENT_DATETIME'>, <TokenType.JSON: 'JSON'>, <TokenType.UINT128: 'UINT128'>, <TokenType.NULLABLE: 'NULLABLE'>, <TokenType.NUMMULTIRANGE: 'NUMMULTIRANGE'>, <TokenType.BIGSERIAL: 'BIGSERIAL'>, <TokenType.DATETIME64: 'DATETIME64'>, <TokenType.REFERENCES: 'REFERENCES'>, <TokenType.FALSE: 'FALSE'>, <TokenType.STRUCT: 'STRUCT'>, <TokenType.ISNULL: 'ISNULL'>, <TokenType.INT8RANGE: 'INT8RANGE'>, <TokenType.BIGDECIMAL: 'BIGDECIMAL'>, <TokenType.END: 'END'>, <TokenType.BIT: 'BIT'>, <TokenType.FLOAT: 'FLOAT'>, <TokenType.NUMRANGE: 'NUMRANGE'>, <TokenType.LONGTEXT: 'LONGTEXT'>, <TokenType.FORMAT: 'FORMAT'>, <TokenType.UPDATE: 'UPDATE'>, <TokenType.CURRENT_DATE: 'CURRENT_DATE'>, <TokenType.LOAD: 'LOAD'>, <TokenType.DATABASE: 'DATABASE'>, <TokenType.UNIQUE: 'UNIQUE'>, <TokenType.DESC: 'DESC'>, <TokenType.SETTINGS: 'SETTINGS'>, <TokenType.ESCAPE: 'ESCAPE'>, <TokenType.TABLE: 'TABLE'>, <TokenType.ROWVERSION: 'ROWVERSION'>, <TokenType.BOOLEAN: 'BOOLEAN'>, <TokenType.TIMESTAMPLTZ: 'TIMESTAMPLTZ'>, <TokenType.INDEX: 'INDEX'>, <TokenType.TOP: 'TOP'>, <TokenType.DEFAULT: 'DEFAULT'>, <TokenType.TEMPORARY: 'TEMPORARY'>, <TokenType.INT: 'INT'>, <TokenType.INT4MULTIRANGE: 'INT4MULTIRANGE'>}
RANGE_PARSERS = {<TokenType.BETWEEN: 'BETWEEN'>: <function Parser.<lambda>>, <TokenType.GLOB: 'GLOB'>: <function binary_range_parser.<locals>.<lambda>>, <TokenType.ILIKE: 'ILIKE'>: <function binary_range_parser.<locals>.<lambda>>, <TokenType.IN: 'IN'>: <function Parser.<lambda>>, <TokenType.IRLIKE: 'IRLIKE'>: <function binary_range_parser.<locals>.<lambda>>, <TokenType.IS: 'IS'>: <function Parser.<lambda>>, <TokenType.LIKE: 'LIKE'>: <function binary_range_parser.<locals>.<lambda>>, <TokenType.OVERLAPS: 'OVERLAPS'>: <function binary_range_parser.<locals>.<lambda>>, <TokenType.RLIKE: 'RLIKE'>: <function binary_range_parser.<locals>.<lambda>>, <TokenType.SIMILAR_TO: 'SIMILAR_TO'>: <function binary_range_parser.<locals>.<lambda>>, <TokenType.MEMBER_OF: 'MEMBER_OF'>: <function MySQL.Parser.<lambda>>}
FUNCTIONS = {'ABS': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Abs'>>, 'ANY_VALUE': <bound method Func.from_arg_list of <class 'sqlglot.expressions.AnyValue'>>, 'APPROX_DISTINCT': <bound method Func.from_arg_list of <class 'sqlglot.expressions.ApproxDistinct'>>, 'APPROX_COUNT_DISTINCT': <bound method Func.from_arg_list of <class 'sqlglot.expressions.ApproxDistinct'>>, 'APPROX_QUANTILE': <bound method Func.from_arg_list of <class 'sqlglot.expressions.ApproxQuantile'>>, 'ARRAY': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Array'>>, 'ARRAY_AGG': <bound method Func.from_arg_list of <class 'sqlglot.expressions.ArrayAgg'>>, 'ARRAY_ALL': <bound method Func.from_arg_list of <class 'sqlglot.expressions.ArrayAll'>>, 'ARRAY_ANY': <bound method Func.from_arg_list of <class 'sqlglot.expressions.ArrayAny'>>, 'ARRAY_CONCAT': <bound method Func.from_arg_list of <class 'sqlglot.expressions.ArrayConcat'>>, 'ARRAY_CONTAINS': <bound method Func.from_arg_list of <class 'sqlglot.expressions.ArrayContains'>>, 'FILTER': <bound method Func.from_arg_list of <class 'sqlglot.expressions.ArrayFilter'>>, 'ARRAY_FILTER': <bound method Func.from_arg_list of <class 'sqlglot.expressions.ArrayFilter'>>, 'ARRAY_JOIN': <bound method Func.from_arg_list of <class 'sqlglot.expressions.ArrayJoin'>>, 'ARRAY_SIZE': <bound method Func.from_arg_list of <class 'sqlglot.expressions.ArraySize'>>, 'ARRAY_SORT': <bound method Func.from_arg_list of <class 'sqlglot.expressions.ArraySort'>>, 'ARRAY_SUM': <bound method Func.from_arg_list of <class 'sqlglot.expressions.ArraySum'>>, 'ARRAY_UNION_AGG': <bound method Func.from_arg_list of <class 'sqlglot.expressions.ArrayUnionAgg'>>, 'AVG': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Avg'>>, 'CASE': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Case'>>, 'CAST': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Cast'>>, 'CAST_TO_STR_TYPE': <bound method Func.from_arg_list of <class 'sqlglot.expressions.CastToStrType'>>, 'CEIL': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Ceil'>>, 'CEILING': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Ceil'>>, 'COALESCE': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Coalesce'>>, 'IFNULL': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Coalesce'>>, 'NVL': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Coalesce'>>, 'CONCAT': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Concat'>>, 'CONCAT_WS': <bound method Func.from_arg_list of <class 'sqlglot.expressions.ConcatWs'>>, 'COUNT': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Count'>>, 'COUNT_IF': <bound method Func.from_arg_list of <class 'sqlglot.expressions.CountIf'>>, 'CURRENT_DATE': <bound method Func.from_arg_list of <class 'sqlglot.expressions.CurrentDate'>>, 'CURRENT_DATETIME': <bound method Func.from_arg_list of <class 'sqlglot.expressions.CurrentDatetime'>>, 'CURRENT_TIME': <bound method Func.from_arg_list of <class 'sqlglot.expressions.CurrentTime'>>, 'CURRENT_TIMESTAMP': <bound method Func.from_arg_list of <class 'sqlglot.expressions.CurrentTimestamp'>>, 'CURRENT_USER': <bound method Func.from_arg_list of <class 'sqlglot.expressions.CurrentUser'>>, 'DATE': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Date'>>, 'DATE_ADD': <function parse_date_delta_with_interval.<locals>.func>, 'DATEDIFF': <bound method Func.from_arg_list of <class 'sqlglot.expressions.DateDiff'>>, 'DATE_DIFF': <bound method Func.from_arg_list of <class 'sqlglot.expressions.DateDiff'>>, 'DATEFROMPARTS': <bound method Func.from_arg_list of <class 'sqlglot.expressions.DateFromParts'>>, 'DATE_STR_TO_DATE': <bound method Func.from_arg_list of <class 'sqlglot.expressions.DateStrToDate'>>, 'DATE_SUB': <function parse_date_delta_with_interval.<locals>.func>, 'DATE_TO_DATE_STR': <function Parser.<lambda>>, 'DATE_TO_DI': <bound method Func.from_arg_list of <class 'sqlglot.expressions.DateToDi'>>, 'DATE_TRUNC': <bound method Func.from_arg_list of <class 'sqlglot.expressions.DateTrunc'>>, 'DATETIME_ADD': <bound method Func.from_arg_list of <class 'sqlglot.expressions.DatetimeAdd'>>, 'DATETIME_DIFF': <bound method Func.from_arg_list of <class 'sqlglot.expressions.DatetimeDiff'>>, 'DATETIME_SUB': <bound method Func.from_arg_list of <class 'sqlglot.expressions.DatetimeSub'>>, 'DATETIME_TRUNC': <bound method Func.from_arg_list of <class 'sqlglot.expressions.DatetimeTrunc'>>, 'DAY': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Day'>>, 'DAY_OF_MONTH': <bound method Func.from_arg_list of <class 'sqlglot.expressions.DayOfMonth'>>, 'DAYOFMONTH': <bound method Func.from_arg_list of <class 'sqlglot.expressions.DayOfMonth'>>, 'DAY_OF_WEEK': <bound method Func.from_arg_list of <class 'sqlglot.expressions.DayOfWeek'>>, 'DAYOFWEEK': <bound method Func.from_arg_list of <class 'sqlglot.expressions.DayOfWeek'>>, 'DAY_OF_YEAR': <bound method Func.from_arg_list of <class 'sqlglot.expressions.DayOfYear'>>, 'DAYOFYEAR': <bound method Func.from_arg_list of <class 'sqlglot.expressions.DayOfYear'>>, 'DECODE': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Decode'>>, 'DI_TO_DATE': <bound method Func.from_arg_list of <class 'sqlglot.expressions.DiToDate'>>, 'ENCODE': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Encode'>>, 'EXP': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Exp'>>, 'EXPLODE': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Explode'>>, 'EXTRACT': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Extract'>>, 'FLOOR': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Floor'>>, 'FROM_BASE': <bound method Func.from_arg_list of <class 'sqlglot.expressions.FromBase'>>, 'FROM_BASE64': <bound method Func.from_arg_list of <class 'sqlglot.expressions.FromBase64'>>, 'GENERATE_SERIES': <bound method Func.from_arg_list of <class 'sqlglot.expressions.GenerateSeries'>>, 'GREATEST': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Greatest'>>, 'GROUP_CONCAT': <bound method Func.from_arg_list of <class 'sqlglot.expressions.GroupConcat'>>, 'HEX': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Hex'>>, 'HLL': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Hll'>>, 'IF': <bound method Func.from_arg_list of <class 'sqlglot.expressions.If'>>, 'INITCAP': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Initcap'>>, 'JSON_ARRAY_CONTAINS': <bound method Func.from_arg_list of <class 'sqlglot.expressions.JSONArrayContains'>>, 'JSONB_EXTRACT': <bound method Func.from_arg_list of <class 'sqlglot.expressions.JSONBExtract'>>, 'JSONB_EXTRACT_SCALAR': <bound method Func.from_arg_list of <class 'sqlglot.expressions.JSONBExtractScalar'>>, 'JSON_EXTRACT': <bound method Func.from_arg_list of <class 'sqlglot.expressions.JSONExtract'>>, 'JSON_EXTRACT_SCALAR': <bound method Func.from_arg_list of <class 'sqlglot.expressions.JSONExtractScalar'>>, 'JSON_FORMAT': <bound method Func.from_arg_list of <class 'sqlglot.expressions.JSONFormat'>>, 'J_S_O_N_OBJECT': <bound method Func.from_arg_list of <class 'sqlglot.expressions.JSONObject'>>, 'LAST_DATE_OF_MONTH': <bound method Func.from_arg_list of <class 'sqlglot.expressions.LastDateOfMonth'>>, 'LEAST': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Least'>>, 'LEFT': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Left'>>, 'LENGTH': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Length'>>, 'LEN': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Length'>>, 'LEVENSHTEIN': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Levenshtein'>>, 'LN': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Ln'>>, 'LOG': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Log'>>, 'LOG10': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Log10'>>, 'LOG2': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Log2'>>, 'LOGICAL_AND': <bound method Func.from_arg_list of <class 'sqlglot.expressions.LogicalAnd'>>, 'BOOL_AND': <bound method Func.from_arg_list of <class 'sqlglot.expressions.LogicalAnd'>>, 'BOOLAND_AGG': <bound method Func.from_arg_list of <class 'sqlglot.expressions.LogicalAnd'>>, 'LOGICAL_OR': <bound method Func.from_arg_list of <class 'sqlglot.expressions.LogicalOr'>>, 'BOOL_OR': <bound method Func.from_arg_list of <class 'sqlglot.expressions.LogicalOr'>>, 'BOOLOR_AGG': <bound method Func.from_arg_list of <class 'sqlglot.expressions.LogicalOr'>>, 'LOWER': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Lower'>>, 'LCASE': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Lower'>>, 'MD5': <bound method Func.from_arg_list of <class 'sqlglot.expressions.MD5'>>, 'MD5_DIGEST': <bound method Func.from_arg_list of <class 'sqlglot.expressions.MD5Digest'>>, 'MAP': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Map'>>, 'MAP_FROM_ENTRIES': <bound method Func.from_arg_list of <class 'sqlglot.expressions.MapFromEntries'>>, 'MATCH_AGAINST': <bound method Func.from_arg_list of <class 'sqlglot.expressions.MatchAgainst'>>, 'MAX': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Max'>>, 'MIN': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Min'>>, 'MONTH': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Month'>>, 'MONTHS_BETWEEN': <bound method Func.from_arg_list of <class 'sqlglot.expressions.MonthsBetween'>>, 'NEXT_VALUE_FOR': <bound method Func.from_arg_list of <class 'sqlglot.expressions.NextValueFor'>>, 'NUMBER_TO_STR': <bound method Func.from_arg_list of <class 'sqlglot.expressions.NumberToStr'>>, 'NVL2': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Nvl2'>>, 'OPEN_J_S_O_N': <bound method Func.from_arg_list of <class 'sqlglot.expressions.OpenJSON'>>, 'PARAMETERIZED_AGG': <bound method Func.from_arg_list of <class 'sqlglot.expressions.ParameterizedAgg'>>, 'PERCENTILE_CONT': <bound method Func.from_arg_list of <class 'sqlglot.expressions.PercentileCont'>>, 'PERCENTILE_DISC': <bound method Func.from_arg_list of <class 'sqlglot.expressions.PercentileDisc'>>, 'POSEXPLODE': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Posexplode'>>, 'POWER': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Pow'>>, 'POW': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Pow'>>, 'QUANTILE': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Quantile'>>, 'RANGE_N': <bound method Func.from_arg_list of <class 'sqlglot.expressions.RangeN'>>, 'READ_CSV': <bound method Func.from_arg_list of <class 'sqlglot.expressions.ReadCSV'>>, 'REDUCE': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Reduce'>>, 'REGEXP_EXTRACT': <bound method Func.from_arg_list of <class 'sqlglot.expressions.RegexpExtract'>>, 'REGEXP_I_LIKE': <bound method Func.from_arg_list of <class 'sqlglot.expressions.RegexpILike'>>, 'REGEXP_LIKE': <bound method Func.from_arg_list of <class 'sqlglot.expressions.RegexpLike'>>, 'REGEXP_REPLACE': <bound method Func.from_arg_list of <class 'sqlglot.expressions.RegexpReplace'>>, 'REGEXP_SPLIT': <bound method Func.from_arg_list of <class 'sqlglot.expressions.RegexpSplit'>>, 'REPEAT': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Repeat'>>, 'RIGHT': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Right'>>, 'ROUND': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Round'>>, 'ROW_NUMBER': <bound method Func.from_arg_list of <class 'sqlglot.expressions.RowNumber'>>, 'SHA': <bound method Func.from_arg_list of <class 'sqlglot.expressions.SHA'>>, 'SHA1': <bound method Func.from_arg_list of <class 'sqlglot.expressions.SHA'>>, 'SHA2': <bound method Func.from_arg_list of <class 'sqlglot.expressions.SHA2'>>, 'SAFE_CONCAT': <bound method Func.from_arg_list of <class 'sqlglot.expressions.SafeConcat'>>, 'SAFE_DIVIDE': <bound method Func.from_arg_list of <class 'sqlglot.expressions.SafeDivide'>>, 'SET_AGG': <bound method Func.from_arg_list of <class 'sqlglot.expressions.SetAgg'>>, 'SORT_ARRAY': <bound method Func.from_arg_list of <class 'sqlglot.expressions.SortArray'>>, 'SPLIT': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Split'>>, 'SQRT': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Sqrt'>>, 'STANDARD_HASH': <bound method Func.from_arg_list of <class 'sqlglot.expressions.StandardHash'>>, 'STAR_MAP': <bound method Func.from_arg_list of <class 'sqlglot.expressions.StarMap'>>, 'STDDEV': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Stddev'>>, 'STDDEV_POP': <bound method Func.from_arg_list of <class 'sqlglot.expressions.StddevPop'>>, 'STDDEV_SAMP': <bound method Func.from_arg_list of <class 'sqlglot.expressions.StddevSamp'>>, 'STR_POSITION': <bound method Func.from_arg_list of <class 'sqlglot.expressions.StrPosition'>>, 'STR_TO_DATE': <function _str_to_date>, 'STR_TO_TIME': <bound method Func.from_arg_list of <class 'sqlglot.expressions.StrToTime'>>, 'STR_TO_UNIX': <bound method Func.from_arg_list of <class 'sqlglot.expressions.StrToUnix'>>, 'STRUCT': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Struct'>>, 'STRUCT_EXTRACT': <bound method Func.from_arg_list of <class 'sqlglot.expressions.StructExtract'>>, 'SUBSTRING': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Substring'>>, 'SUM': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Sum'>>, 'TIME_ADD': <bound method Func.from_arg_list of <class 'sqlglot.expressions.TimeAdd'>>, 'TIME_DIFF': <bound method Func.from_arg_list of <class 'sqlglot.expressions.TimeDiff'>>, 'TIME_STR_TO_DATE': <bound method Func.from_arg_list of <class 'sqlglot.expressions.TimeStrToDate'>>, 'TIME_STR_TO_TIME': <bound method Func.from_arg_list of <class 'sqlglot.expressions.TimeStrToTime'>>, 'TIME_STR_TO_UNIX': <bound method Func.from_arg_list of <class 'sqlglot.expressions.TimeStrToUnix'>>, 'TIME_SUB': <bound method Func.from_arg_list of <class 'sqlglot.expressions.TimeSub'>>, 'TIME_TO_STR': <bound method Func.from_arg_list of <class 'sqlglot.expressions.TimeToStr'>>, 'TIME_TO_TIME_STR': <function Parser.<lambda>>, 'TIME_TO_UNIX': <bound method Func.from_arg_list of <class 'sqlglot.expressions.TimeToUnix'>>, 'TIME_TRUNC': <bound method Func.from_arg_list of <class 'sqlglot.expressions.TimeTrunc'>>, 'TIMESTAMP_ADD': <bound method Func.from_arg_list of <class 'sqlglot.expressions.TimestampAdd'>>, 'TIMESTAMP_DIFF': <bound method Func.from_arg_list of <class 'sqlglot.expressions.TimestampDiff'>>, 'TIMESTAMP_SUB': <bound method Func.from_arg_list of <class 'sqlglot.expressions.TimestampSub'>>, 'TIMESTAMP_TRUNC': <bound method Func.from_arg_list of <class 'sqlglot.expressions.TimestampTrunc'>>, 'TO_BASE64': <bound method Func.from_arg_list of <class 'sqlglot.expressions.ToBase64'>>, 'TO_CHAR': <bound method Func.from_arg_list of <class 'sqlglot.expressions.ToChar'>>, 'TRIM': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Trim'>>, 'TRY_CAST': <bound method Func.from_arg_list of <class 'sqlglot.expressions.TryCast'>>, 'TS_OR_DI_TO_DI': <bound method Func.from_arg_list of <class 'sqlglot.expressions.TsOrDiToDi'>>, 'TS_OR_DS_ADD': <bound method Func.from_arg_list of <class 'sqlglot.expressions.TsOrDsAdd'>>, 'TS_OR_DS_TO_DATE': <bound method Func.from_arg_list of <class 'sqlglot.expressions.TsOrDsToDate'>>, 'TS_OR_DS_TO_DATE_STR': <function Parser.<lambda>>, 'UNHEX': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Unhex'>>, 'UNIX_TO_STR': <bound method Func.from_arg_list of <class 'sqlglot.expressions.UnixToStr'>>, 'UNIX_TO_TIME': <bound method Func.from_arg_list of <class 'sqlglot.expressions.UnixToTime'>>, 'UNIX_TO_TIME_STR': <bound method Func.from_arg_list of <class 'sqlglot.expressions.UnixToTimeStr'>>, 'UPPER': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Upper'>>, 'UCASE': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Upper'>>, 'VAR_MAP': <function parse_var_map>, 'VARIANCE': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Variance'>>, 'VARIANCE_SAMP': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Variance'>>, 'VAR_SAMP': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Variance'>>, 'VARIANCE_POP': <bound method Func.from_arg_list of <class 'sqlglot.expressions.VariancePop'>>, 'VAR_POP': <bound method Func.from_arg_list of <class 'sqlglot.expressions.VariancePop'>>, 'WEEK': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Week'>>, 'WEEK_OF_YEAR': <bound method Func.from_arg_list of <class 'sqlglot.expressions.WeekOfYear'>>, 'WEEKOFYEAR': <bound method Func.from_arg_list of <class 'sqlglot.expressions.WeekOfYear'>>, 'WHEN': <bound method Func.from_arg_list of <class 'sqlglot.expressions.When'>>, 'X_M_L_TABLE': <bound method Func.from_arg_list of <class 'sqlglot.expressions.XMLTable'>>, 'YEAR': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Year'>>, 'GLOB': <function Parser.<lambda>>, 'LIKE': <function parse_like>, 'DATE_FORMAT': <function format_time_lambda.<locals>._format_time>, 'INSTR': <function MySQL.Parser.<lambda>>, 'LOCATE': <function locate_to_strposition>}
FUNCTION_PARSERS = {'ANY_VALUE': <function Parser.<lambda>>, 'CAST': <function Parser.<lambda>>, 'CONCAT': <function Parser.<lambda>>, 'CONVERT': <function Parser.<lambda>>, 'DECODE': <function Parser.<lambda>>, 'EXTRACT': <function Parser.<lambda>>, 'JSON_OBJECT': <function Parser.<lambda>>, 'LOG': <function Parser.<lambda>>, 'MATCH': <function Parser.<lambda>>, 'OPENJSON': <function Parser.<lambda>>, 'POSITION': <function Parser.<lambda>>, 'SAFE_CAST': <function Parser.<lambda>>, 'STRING_AGG': <function Parser.<lambda>>, 'SUBSTRING': <function Parser.<lambda>>, 'TRIM': <function Parser.<lambda>>, 'TRY_CAST': <function Parser.<lambda>>, 'TRY_CONVERT': <function Parser.<lambda>>, 'GROUP_CONCAT': <function MySQL.Parser.<lambda>>, 'VALUES': <function MySQL.Parser.<lambda>>}
STATEMENT_PARSERS = {<TokenType.ALTER: 'ALTER'>: <function Parser.<lambda>>, <TokenType.BEGIN: 'BEGIN'>: <function Parser.<lambda>>, <TokenType.CACHE: 'CACHE'>: <function Parser.<lambda>>, <TokenType.COMMIT: 'COMMIT'>: <function Parser.<lambda>>, <TokenType.COMMENT: 'COMMENT'>: <function Parser.<lambda>>, <TokenType.CREATE: 'CREATE'>: <function Parser.<lambda>>, <TokenType.DELETE: 'DELETE'>: <function Parser.<lambda>>, <TokenType.DESC: 'DESC'>: <function Parser.<lambda>>, <TokenType.DESCRIBE: 'DESCRIBE'>: <function Parser.<lambda>>, <TokenType.DROP: 'DROP'>: <function Parser.<lambda>>, <TokenType.FROM: 'FROM'>: <function Parser.<lambda>>, <TokenType.INSERT: 'INSERT'>: <function Parser.<lambda>>, <TokenType.LOAD: 'LOAD'>: <function Parser.<lambda>>, <TokenType.MERGE: 'MERGE'>: <function Parser.<lambda>>, <TokenType.PIVOT: 'PIVOT'>: <function Parser.<lambda>>, <TokenType.PRAGMA: 'PRAGMA'>: <function Parser.<lambda>>, <TokenType.ROLLBACK: 'ROLLBACK'>: <function Parser.<lambda>>, <TokenType.SET: 'SET'>: <function Parser.<lambda>>, <TokenType.UNCACHE: 'UNCACHE'>: <function Parser.<lambda>>, <TokenType.UPDATE: 'UPDATE'>: <function Parser.<lambda>>, <TokenType.USE: 'USE'>: <function Parser.<lambda>>, <TokenType.SHOW: 'SHOW'>: <function MySQL.Parser.<lambda>>}
SHOW_PARSERS = {'BINARY LOGS': <function _show_parser.<locals>._parse>, 'MASTER LOGS': <function _show_parser.<locals>._parse>, 'BINLOG EVENTS': <function _show_parser.<locals>._parse>, 'CHARACTER SET': <function _show_parser.<locals>._parse>, 'CHARSET': <function _show_parser.<locals>._parse>, 'COLLATION': <function _show_parser.<locals>._parse>, 'FULL COLUMNS': <function _show_parser.<locals>._parse>, 'COLUMNS': <function _show_parser.<locals>._parse>, 'CREATE DATABASE': <function _show_parser.<locals>._parse>, 'CREATE EVENT': <function _show_parser.<locals>._parse>, 'CREATE FUNCTION': <function _show_parser.<locals>._parse>, 'CREATE PROCEDURE': <function _show_parser.<locals>._parse>, 'CREATE TABLE': <function _show_parser.<locals>._parse>, 'CREATE TRIGGER': <function _show_parser.<locals>._parse>, 'CREATE VIEW': <function _show_parser.<locals>._parse>, 'DATABASES': <function _show_parser.<locals>._parse>, 'ENGINE': <function _show_parser.<locals>._parse>, 'STORAGE ENGINES': <function _show_parser.<locals>._parse>, 'ENGINES': <function _show_parser.<locals>._parse>, 'ERRORS': <function _show_parser.<locals>._parse>, 'EVENTS': <function _show_parser.<locals>._parse>, 'FUNCTION CODE': <function _show_parser.<locals>._parse>, 'FUNCTION STATUS': <function _show_parser.<locals>._parse>, 'GRANTS': <function _show_parser.<locals>._parse>, 'INDEX': <function _show_parser.<locals>._parse>, 'MASTER STATUS': <function _show_parser.<locals>._parse>, 'OPEN TABLES': <function _show_parser.<locals>._parse>, 'PLUGINS': <function _show_parser.<locals>._parse>, 'PROCEDURE CODE': <function _show_parser.<locals>._parse>, 'PROCEDURE STATUS': <function _show_parser.<locals>._parse>, 'PRIVILEGES': <function _show_parser.<locals>._parse>, 'FULL PROCESSLIST': <function _show_parser.<locals>._parse>, 'PROCESSLIST': <function _show_parser.<locals>._parse>, 'PROFILE': <function _show_parser.<locals>._parse>, 'PROFILES': <function _show_parser.<locals>._parse>, 'RELAYLOG EVENTS': <function _show_parser.<locals>._parse>, 'REPLICAS': <function _show_parser.<locals>._parse>, 'SLAVE HOSTS': <function _show_parser.<locals>._parse>, 'REPLICA STATUS': <function _show_parser.<locals>._parse>, 'SLAVE STATUS': <function _show_parser.<locals>._parse>, 'GLOBAL STATUS': <function _show_parser.<locals>._parse>, 'SESSION STATUS': <function _show_parser.<locals>._parse>, 'STATUS': <function _show_parser.<locals>._parse>, 'TABLE STATUS': <function _show_parser.<locals>._parse>, 'FULL TABLES': <function _show_parser.<locals>._parse>, 'TABLES': <function _show_parser.<locals>._parse>, 'TRIGGERS': <function _show_parser.<locals>._parse>, 'GLOBAL VARIABLES': <function _show_parser.<locals>._parse>, 'SESSION VARIABLES': <function _show_parser.<locals>._parse>, 'VARIABLES': <function _show_parser.<locals>._parse>, 'WARNINGS': <function _show_parser.<locals>._parse>}
SET_PARSERS = {'GLOBAL': <function Parser.<lambda>>, 'LOCAL': <function Parser.<lambda>>, 'SESSION': <function Parser.<lambda>>, 'TRANSACTION': <function Parser.<lambda>>, 'PERSIST': <function MySQL.Parser.<lambda>>, 'PERSIST_ONLY': <function MySQL.Parser.<lambda>>, 'CHARACTER SET': <function MySQL.Parser.<lambda>>, 'CHARSET': <function MySQL.Parser.<lambda>>, 'NAMES': <function MySQL.Parser.<lambda>>}
PROFILE_TYPES = {'PAGE FAULTS', 'BLOCK IO', 'MEMORY', 'SWAPS', 'IPC', 'SOURCE', 'CPU', 'CONTEXT SWITCHES', 'ALL'}
TYPE_TOKENS = {<TokenType.DATETIME: 'DATETIME'>, <TokenType.HSTORE: 'HSTORE'>, <TokenType.SMALLINT: 'SMALLINT'>, <TokenType.HLLSKETCH: 'HLLSKETCH'>, <TokenType.TSMULTIRANGE: 'TSMULTIRANGE'>, <TokenType.GEOGRAPHY: 'GEOGRAPHY'>, <TokenType.UUID: 'UUID'>, <TokenType.ARRAY: 'ARRAY'>, <TokenType.TIMESTAMPTZ: 'TIMESTAMPTZ'>, <TokenType.ENUM: 'ENUM'>, <TokenType.NVARCHAR: 'NVARCHAR'>, <TokenType.UBIGINT: 'UBIGINT'>, <TokenType.USMALLINT: 'USMALLINT'>, <TokenType.INTERVAL: 'INTERVAL'>, <TokenType.TEXT: 'TEXT'>, <TokenType.TIME: 'TIME'>, <TokenType.GEOMETRY: 'GEOMETRY'>, <TokenType.DATERANGE: 'DATERANGE'>, <TokenType.DOUBLE: 'DOUBLE'>, <TokenType.DATE: 'DATE'>, <TokenType.INT8MULTIRANGE: 'INT8MULTIRANGE'>, <TokenType.SMALLSERIAL: 'SMALLSERIAL'>, <TokenType.TSTZMULTIRANGE: 'TSTZMULTIRANGE'>, <TokenType.MONEY: 'MONEY'>, <TokenType.CHAR: 'CHAR'>, <TokenType.VARCHAR: 'VARCHAR'>, <TokenType.TIMESTAMP: 'TIMESTAMP'>, <TokenType.BIGINT: 'BIGINT'>, <TokenType.UNIQUEIDENTIFIER: 'UNIQUEIDENTIFIER'>, <TokenType.LONGBLOB: 'LONGBLOB'>, <TokenType.NCHAR: 'NCHAR'>, <TokenType.UINT256: 'UINT256'>, <TokenType.INT256: 'INT256'>, <TokenType.SUPER: 'SUPER'>, <TokenType.TSRANGE: 'TSRANGE'>, <TokenType.DECIMAL: 'DECIMAL'>, <TokenType.MEDIUMBLOB: 'MEDIUMBLOB'>, <TokenType.SET: 'SET'>, <TokenType.JSON: 'JSON'>, <TokenType.UINT128: 'UINT128'>, <TokenType.SERIAL: 'SERIAL'>, <TokenType.NULLABLE: 'NULLABLE'>, <TokenType.MAP: 'MAP'>, <TokenType.UTINYINT: 'UTINYINT'>, <TokenType.MEDIUMTEXT: 'MEDIUMTEXT'>, <TokenType.UINT: 'UINT'>, <TokenType.NUMMULTIRANGE: 'NUMMULTIRANGE'>, <TokenType.DATETIME64: 'DATETIME64'>, <TokenType.BIGSERIAL: 'BIGSERIAL'>, <TokenType.STRUCT: 'STRUCT'>, <TokenType.TINYINT: 'TINYINT'>, <TokenType.OBJECT: 'OBJECT'>, <TokenType.INT8RANGE: 'INT8RANGE'>, <TokenType.TSTZRANGE: 'TSTZRANGE'>, <TokenType.BIGDECIMAL: 'BIGDECIMAL'>, <TokenType.VARBINARY: 'VARBINARY'>, <TokenType.INET: 'INET'>, <TokenType.BIT: 'BIT'>, <TokenType.FLOAT: 'FLOAT'>, <TokenType.XML: 'XML'>, <TokenType.NUMRANGE: 'NUMRANGE'>, <TokenType.LONGTEXT: 'LONGTEXT'>, <TokenType.INT128: 'INT128'>, <TokenType.BINARY: 'BINARY'>, <TokenType.VARIANT: 'VARIANT'>, <TokenType.SMALLMONEY: 'SMALLMONEY'>, <TokenType.PSEUDO_TYPE: 'PSEUDO_TYPE'>, <TokenType.DATEMULTIRANGE: 'DATEMULTIRANGE'>, <TokenType.USERDEFINED: 'USERDEFINED'>, <TokenType.ROWVERSION: 'ROWVERSION'>, <TokenType.BOOLEAN: 'BOOLEAN'>, <TokenType.IMAGE: 'IMAGE'>, <TokenType.TIMESTAMPLTZ: 'TIMESTAMPLTZ'>, <TokenType.INT: 'INT'>, <TokenType.JSONB: 'JSONB'>, <TokenType.INT4MULTIRANGE: 'INT4MULTIRANGE'>, <TokenType.INT4RANGE: 'INT4RANGE'>}
ENUM_TYPE_TOKENS = {<TokenType.SET: 'SET'>, <TokenType.ENUM: 'ENUM'>}
LOG_DEFAULTS_TO_LN = True
SHOW_TRIE: Dict = {'BINARY': {'LOGS': {0: True}}, 'MASTER': {'LOGS': {0: True}, 'STATUS': {0: True}}, 'BINLOG': {'EVENTS': {0: True}}, 'CHARACTER': {'SET': {0: True}}, 'CHARSET': {0: True}, 'COLLATION': {0: True}, 'FULL': {'COLUMNS': {0: True}, 'PROCESSLIST': {0: True}, 'TABLES': {0: True}}, 'COLUMNS': {0: True}, 'CREATE': {'DATABASE': {0: True}, 'EVENT': {0: True}, 'FUNCTION': {0: True}, 'PROCEDURE': {0: True}, 'TABLE': {0: True}, 'TRIGGER': {0: True}, 'VIEW': {0: True}}, 'DATABASES': {0: True}, 'ENGINE': {0: True}, 'STORAGE': {'ENGINES': {0: True}}, 'ENGINES': {0: True}, 'ERRORS': {0: True}, 'EVENTS': {0: True}, 'FUNCTION': {'CODE': {0: True}, 'STATUS': {0: True}}, 'GRANTS': {0: True}, 'INDEX': {0: True}, 'OPEN': {'TABLES': {0: True}}, 'PLUGINS': {0: True}, 'PROCEDURE': {'CODE': {0: True}, 'STATUS': {0: True}}, 'PRIVILEGES': {0: True}, 'PROCESSLIST': {0: True}, 'PROFILE': {0: True}, 'PROFILES': {0: True}, 'RELAYLOG': {'EVENTS': {0: True}}, 'REPLICAS': {0: True}, 'SLAVE': {'HOSTS': {0: True}, 'STATUS': {0: True}}, 'REPLICA': {'STATUS': {0: True}}, 'GLOBAL': {'STATUS': {0: True}, 'VARIABLES': {0: True}}, 'SESSION': {'STATUS': {0: True}, 'VARIABLES': {0: True}}, 'STATUS': {0: True}, 'TABLE': {'STATUS': {0: True}}, 'TABLES': {0: True}, 'TRIGGERS': {0: True}, 'VARIABLES': {0: True}, 'WARNINGS': {0: True}}
SET_TRIE: Dict = {'GLOBAL': {0: True}, 'LOCAL': {0: True}, 'SESSION': {0: True}, 'TRANSACTION': {0: True}, 'PERSIST': {0: True}, 'PERSIST_ONLY': {0: True}, 'CHARACTER': {'SET': {0: True}}, 'CHARSET': {0: True}, 'NAMES': {0: True}}
FORMAT_TRIE: Dict = {'%': {'M': {0: True}, 'c': {0: True}, 'e': {0: True}, 'h': {0: True}, 'i': {0: True}, 's': {0: True}, 'S': {0: True}, 'u': {0: True}, 'k': {0: True}, 'l': {0: True}, 'T': {0: True}, 'W': {0: True}}}
TIME_MAPPING: Dict[str, str] = {'%M': '%B', '%c': '%-m', '%e': '%-d', '%h': '%I', '%i': '%M', '%s': '%S', '%S': '%S', '%u': '%W', '%k': '%-H', '%l': '%-I', '%T': '%H:%M:%S', '%W': '%a'}
TIME_TRIE: Dict = {'%': {'M': {0: True}, 'c': {0: True}, 'e': {0: True}, 'h': {0: True}, 'i': {0: True}, 's': {0: True}, 'S': {0: True}, 'u': {0: True}, 'k': {0: True}, 'l': {0: True}, 'T': {0: True}, 'W': {0: True}}}

##### Inherited Members

sqlglot.parser.Parser
  Parser
  NO_PAREN_FUNCTIONS
  NESTED_TYPE_TOKENS
  SUBQUERY_PREDICATES
  RESERVED_KEYWORDS
  DB_CREATABLES
  CREATABLES
  ID_VAR_TOKENS
  INTERVAL_VARS
  COMMENT_TABLE_ALIAS_TOKENS
  UPDATE_ALIAS_TOKENS
  TRIM_TYPES
  EQUALITY
  COMPARISON
  BITWISE
  TERM
  FACTOR
  TIMESTAMPS
  SET_OPERATIONS
  JOIN_METHODS
  JOIN_SIDES
  JOIN_KINDS
  JOIN_HINTS
  LAMBDAS
  COLUMN_OPERATORS
  EXPRESSION_PARSERS
  UNARY_PARSERS
  PRIMARY_PARSERS
  PLACEHOLDER_PARSERS
  PROPERTY_PARSERS
  CONSTRAINT_PARSERS
  ALTER_PARSERS
  SCHEMA_UNNAMED_CONSTRAINTS
  NO_PAREN_FUNCTION_PARSERS
  FUNCTIONS_WITH_ALIASED_ARGS
  QUERY_MODIFIER_PARSERS
  TYPE_LITERAL_PARSERS
  MODIFIABLES
  DDL_SELECT_TOKENS
  PRE_VOLATILE_TOKENS
  TRANSACTION_KIND
  TRANSACTION_CHARACTERISTICS
  INSERT_ALTERNATIVES
  CLONE_KINDS
  TABLE_INDEX_HINT_TOKENS
  WINDOW_ALIAS_TOKENS
  WINDOW_BEFORE_PAREN_TOKENS
  WINDOW_SIDES
  ADD_CONSTRAINT_TOKENS
  STRICT_CAST
  CONCAT_NULL_OUTPUTS_STRING
  PREFIXED_PIVOT_COLUMNS
  IDENTIFY_PIVOT_STRINGS
  LOG_BASE_FIRST
  INDEX_OFFSET
  UNNEST_COLUMN_ONLY
  ALIAS_POST_TABLESAMPLE
  STRICT_STRING_CONCAT
  NULL_ORDERING
  FORMAT_MAPPING
  error_level
  error_message_context
  max_errors
  reset
  parse
  parse_into
  check_errors
  raise_error
  expression
  validate_expression
  errors
  sql

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

    424    class Generator(generator.Generator):
    425        LOCKING_READS_SUPPORTED = True
    426        NULL_ORDERING_SUPPORTED = False
    427        JOIN_HINTS = False
    428        TABLE_HINTS = True
    429        DUPLICATE_KEY_UPDATE_WITH_SET = False
    430        QUERY_HINT_SEP = " "
    431
    432        TRANSFORMS = {
    433            **generator.Generator.TRANSFORMS,
    434            exp.CurrentDate: no_paren_current_date_sql,
    435            exp.DateDiff: lambda self, e: self.func("DATEDIFF", e.this, e.expression),
    436            exp.DateAdd: _date_add_sql("ADD"),
    437            exp.DateStrToDate: datestrtodate_sql,
    438            exp.DateSub: _date_add_sql("SUB"),
    439            exp.DateTrunc: _date_trunc_sql,
    440            exp.DayOfMonth: rename_func("DAYOFMONTH"),
    441            exp.DayOfWeek: rename_func("DAYOFWEEK"),
    442            exp.DayOfYear: rename_func("DAYOFYEAR"),
    443            exp.GroupConcat: lambda self, e: f"""GROUP_CONCAT({self.sql(e, "this")} SEPARATOR {self.sql(e, "separator") or "','"})""",
    444            exp.ILike: no_ilike_sql,
    445            exp.JSONExtractScalar: arrow_json_extract_scalar_sql,
    446            exp.Max: max_or_greatest,
    447            exp.Min: min_or_least,
    448            exp.NullSafeEQ: lambda self, e: self.binary(e, "<=>"),
    449            exp.NullSafeNEQ: lambda self, e: self.not_sql(self.binary(e, "<=>")),
    450            exp.Pivot: no_pivot_sql,
    451            exp.Select: transforms.preprocess([transforms.eliminate_distinct_on]),
    452            exp.StrPosition: strposition_to_locate_sql,
    453            exp.StrToDate: _str_to_date_sql,
    454            exp.StrToTime: _str_to_date_sql,
    455            exp.TableSample: no_tablesample_sql,
    456            exp.TimeStrToUnix: rename_func("UNIX_TIMESTAMP"),
    457            exp.TimeToStr: lambda self, e: self.func("DATE_FORMAT", e.this, self.format_time(e)),
    458            exp.Trim: _trim_sql,
    459            exp.TryCast: no_trycast_sql,
    460            exp.WeekOfYear: rename_func("WEEKOFYEAR"),
    461        }
    462
    463        TYPE_MAPPING = generator.Generator.TYPE_MAPPING.copy()
    464        TYPE_MAPPING.pop(exp.DataType.Type.MEDIUMTEXT)
    465        TYPE_MAPPING.pop(exp.DataType.Type.LONGTEXT)
    466        TYPE_MAPPING.pop(exp.DataType.Type.MEDIUMBLOB)
    467        TYPE_MAPPING.pop(exp.DataType.Type.LONGBLOB)
    468
    469        PROPERTIES_LOCATION = {
    470            **generator.Generator.PROPERTIES_LOCATION,
    471            exp.TransientProperty: exp.Properties.Location.UNSUPPORTED,
    472            exp.VolatileProperty: exp.Properties.Location.UNSUPPORTED,
    473        }
    474
    475        LIMIT_FETCH = "LIMIT"
    476
    477        def jsonarraycontains_sql(self, expression: exp.JSONArrayContains) -> str:
    478            return f"{self.sql(expression, 'this')} MEMBER OF({self.sql(expression, 'expression')})"
    479
    480        def cast_sql(self, expression: exp.Cast, safe_prefix: t.Optional[str] = None) -> str:
    481            """(U)BIGINT is not allowed in a CAST expression, so we use (UN)SIGNED instead."""
    482            if expression.to.this == exp.DataType.Type.BIGINT:
    483                to = "SIGNED"
    484            elif expression.to.this == exp.DataType.Type.UBIGINT:
    485                to = "UNSIGNED"
    486            else:
    487                return super().cast_sql(expression)
    488
    489            return f"CAST({self.sql(expression, 'this')} AS {to})"
    490
    491        def show_sql(self, expression: exp.Show) -> str:
    492            this = f" {expression.name}"
    493            full = " FULL" if expression.args.get("full") else ""
    494            global_ = " GLOBAL" if expression.args.get("global") else ""
    495
    496            target = self.sql(expression, "target")
    497            target = f" {target}" if target else ""
    498            if expression.name in {"COLUMNS", "INDEX"}:
    499                target = f" FROM{target}"
    500            elif expression.name == "GRANTS":
    501                target = f" FOR{target}"
    502
    503            db = self._prefixed_sql("FROM", expression, "db")
    504
    505            like = self._prefixed_sql("LIKE", expression, "like")
    506            where = self.sql(expression, "where")
    507
    508            types = self.expressions(expression, key="types")
    509            types = f" {types}" if types else types
    510            query = self._prefixed_sql("FOR QUERY", expression, "query")
    511
    512            if expression.name == "PROFILE":
    513                offset = self._prefixed_sql("OFFSET", expression, "offset")
    514                limit = self._prefixed_sql("LIMIT", expression, "limit")
    515            else:
    516                offset = ""
    517                limit = self._oldstyle_limit_sql(expression)
    518
    519            log = self._prefixed_sql("IN", expression, "log")
    520            position = self._prefixed_sql("FROM", expression, "position")
    521
    522            channel = self._prefixed_sql("FOR CHANNEL", expression, "channel")
    523
    524            if expression.name == "ENGINE":
    525                mutex_or_status = " MUTEX" if expression.args.get("mutex") else " STATUS"
    526            else:
    527                mutex_or_status = ""
    528
    529            return f"SHOW{full}{global_}{this}{target}{types}{db}{query}{log}{position}{channel}{mutex_or_status}{like}{where}{offset}{limit}"
    530
    531        def _prefixed_sql(self, prefix: str, expression: exp.Expression, arg: str) -> str:
    532            sql = self.sql(expression, arg)
    533            return f" {prefix} {sql}" if sql else ""
    534
    535        def _oldstyle_limit_sql(self, expression: exp.Show) -> str:
    536            limit = self.sql(expression, "limit")
    537            offset = self.sql(expression, "offset")
    538            if limit:
    539                limit_offset = f"{offset}, {limit}" if offset else limit
    540                return f" LIMIT {limit_offset}"
    541            return ""

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

###### Arguments:

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

LOCKING_READS_SUPPORTED = True
NULL_ORDERING_SUPPORTED = False
JOIN_HINTS = False
TABLE_HINTS = True
DUPLICATE_KEY_UPDATE_WITH_SET = False
QUERY_HINT_SEP = ' '
TRANSFORMS = {<class 'sqlglot.expressions.DateAdd'>: <function _date_add_sql.<locals>.func>, <class 'sqlglot.expressions.TsOrDsAdd'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.CaseSpecificColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.CharacterSetColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.CharacterSetProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.CheckColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.CollateColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.CopyGrantsProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.CommentColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.DateFormatColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.DefaultColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.EncodeColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.ExecuteAsProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.ExternalProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.InlineLengthColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.LanguageProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.LocationProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.LogProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.MaterializedProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.NoPrimaryIndexProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.OnCommitProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.OnUpdateColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.PathColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.ReturnsProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.SetProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.SettingsProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.SqlSecurityProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.StabilityProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.TemporaryProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.ToTableProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.TransientProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.TitleColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.UppercaseColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.VarMap'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.VolatileProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.WithJournalTableProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.CurrentDate'>: <function no_paren_current_date_sql>, <class 'sqlglot.expressions.DateDiff'>: <function MySQL.Generator.<lambda>>, <class 'sqlglot.expressions.DateStrToDate'>: <function datestrtodate_sql>, <class 'sqlglot.expressions.DateSub'>: <function _date_add_sql.<locals>.func>, <class 'sqlglot.expressions.DateTrunc'>: <function _date_trunc_sql>, <class 'sqlglot.expressions.DayOfMonth'>: <function rename_func.<locals>.<lambda>>, <class 'sqlglot.expressions.DayOfWeek'>: <function rename_func.<locals>.<lambda>>, <class 'sqlglot.expressions.DayOfYear'>: <function rename_func.<locals>.<lambda>>, <class 'sqlglot.expressions.GroupConcat'>: <function MySQL.Generator.<lambda>>, <class 'sqlglot.expressions.ILike'>: <function no_ilike_sql>, <class 'sqlglot.expressions.JSONExtractScalar'>: <function arrow_json_extract_scalar_sql>, <class 'sqlglot.expressions.Max'>: <function max_or_greatest>, <class 'sqlglot.expressions.Min'>: <function min_or_least>, <class 'sqlglot.expressions.NullSafeEQ'>: <function MySQL.Generator.<lambda>>, <class 'sqlglot.expressions.NullSafeNEQ'>: <function MySQL.Generator.<lambda>>, <class 'sqlglot.expressions.Pivot'>: <function no_pivot_sql>, <class 'sqlglot.expressions.Select'>: <function preprocess.<locals>._to_sql>, <class 'sqlglot.expressions.StrPosition'>: <function strposition_to_locate_sql>, <class 'sqlglot.expressions.StrToDate'>: <function _str_to_date_sql>, <class 'sqlglot.expressions.StrToTime'>: <function _str_to_date_sql>, <class 'sqlglot.expressions.TableSample'>: <function no_tablesample_sql>, <class 'sqlglot.expressions.TimeStrToUnix'>: <function rename_func.<locals>.<lambda>>, <class 'sqlglot.expressions.TimeToStr'>: <function MySQL.Generator.<lambda>>, <class 'sqlglot.expressions.Trim'>: <function _trim_sql>, <class 'sqlglot.expressions.TryCast'>: <function no_trycast_sql>, <class 'sqlglot.expressions.WeekOfYear'>: <function rename_func.<locals>.<lambda>>}
TYPE_MAPPING = {<Type.NCHAR: 'NCHAR'>: 'CHAR', <Type.NVARCHAR: 'NVARCHAR'>: 'VARCHAR', <Type.INET: 'INET'>: 'INET'}
PROPERTIES_LOCATION = {<class 'sqlglot.expressions.AlgorithmProperty'>: <Location.POST_CREATE: 'POST_CREATE'>, <class 'sqlglot.expressions.AutoIncrementProperty'>: <Location.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.BlockCompressionProperty'>: <Location.POST_NAME: 'POST_NAME'>, <class 'sqlglot.expressions.CharacterSetProperty'>: <Location.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.ChecksumProperty'>: <Location.POST_NAME: 'POST_NAME'>, <class 'sqlglot.expressions.CollateProperty'>: <Location.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.CopyGrantsProperty'>: <Location.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.Cluster'>: <Location.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.ClusteredByProperty'>: <Location.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.DataBlocksizeProperty'>: <Location.POST_NAME: 'POST_NAME'>, <class 'sqlglot.expressions.DefinerProperty'>: <Location.POST_CREATE: 'POST_CREATE'>, <class 'sqlglot.expressions.DictRange'>: <Location.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.DictProperty'>: <Location.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.DistKeyProperty'>: <Location.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.DistStyleProperty'>: <Location.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.EngineProperty'>: <Location.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.ExecuteAsProperty'>: <Location.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.ExternalProperty'>: <Location.POST_CREATE: 'POST_CREATE'>, <class 'sqlglot.expressions.FallbackProperty'>: <Location.POST_NAME: 'POST_NAME'>, <class 'sqlglot.expressions.FileFormatProperty'>: <Location.POST_WITH: 'POST_WITH'>, <class 'sqlglot.expressions.FreespaceProperty'>: <Location.POST_NAME: 'POST_NAME'>, <class 'sqlglot.expressions.IsolatedLoadingProperty'>: <Location.POST_NAME: 'POST_NAME'>, <class 'sqlglot.expressions.JournalProperty'>: <Location.POST_NAME: 'POST_NAME'>, <class 'sqlglot.expressions.LanguageProperty'>: <Location.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.LikeProperty'>: <Location.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.LocationProperty'>: <Location.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.LockingProperty'>: <Location.POST_ALIAS: 'POST_ALIAS'>, <class 'sqlglot.expressions.LogProperty'>: <Location.POST_NAME: 'POST_NAME'>, <class 'sqlglot.expressions.MaterializedProperty'>: <Location.POST_CREATE: 'POST_CREATE'>, <class 'sqlglot.expressions.MergeBlockRatioProperty'>: <Location.POST_NAME: 'POST_NAME'>, <class 'sqlglot.expressions.NoPrimaryIndexProperty'>: <Location.POST_EXPRESSION: 'POST_EXPRESSION'>, <class 'sqlglot.expressions.OnCommitProperty'>: <Location.POST_EXPRESSION: 'POST_EXPRESSION'>, <class 'sqlglot.expressions.Order'>: <Location.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.PartitionedByProperty'>: <Location.POST_WITH: 'POST_WITH'>, <class 'sqlglot.expressions.PrimaryKey'>: <Location.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.Property'>: <Location.POST_WITH: 'POST_WITH'>, <class 'sqlglot.expressions.ReturnsProperty'>: <Location.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.RowFormatProperty'>: <Location.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.RowFormatDelimitedProperty'>: <Location.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.RowFormatSerdeProperty'>: <Location.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.SchemaCommentProperty'>: <Location.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.SerdeProperties'>: <Location.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.Set'>: <Location.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.SettingsProperty'>: <Location.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.SetProperty'>: <Location.POST_CREATE: 'POST_CREATE'>, <class 'sqlglot.expressions.SortKeyProperty'>: <Location.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.SqlSecurityProperty'>: <Location.POST_CREATE: 'POST_CREATE'>, <class 'sqlglot.expressions.StabilityProperty'>: <Location.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.TemporaryProperty'>: <Location.POST_CREATE: 'POST_CREATE'>, <class 'sqlglot.expressions.ToTableProperty'>: <Location.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.TransientProperty'>: <Location.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.MergeTreeTTL'>: <Location.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.VolatileProperty'>: <Location.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.WithDataProperty'>: <Location.POST_EXPRESSION: 'POST_EXPRESSION'>, <class 'sqlglot.expressions.WithJournalTableProperty'>: <Location.POST_NAME: 'POST_NAME'>}
LIMIT_FETCH = 'LIMIT'
def jsonarraycontains_sql(self, expression: sqlglot.expressions.JSONArrayContains) -> str: View Source

    477        def jsonarraycontains_sql(self, expression: exp.JSONArrayContains) -> str:
    478            return f"{self.sql(expression, 'this')} MEMBER OF({self.sql(expression, 'expression')})"

def cast_sql( self, expression: sqlglot.expressions.Cast, safe_prefix: Optional[str] = None) -> str: View Source

    480        def cast_sql(self, expression: exp.Cast, safe_prefix: t.Optional[str] = None) -> str:
    481            """(U)BIGINT is not allowed in a CAST expression, so we use (UN)SIGNED instead."""
    482            if expression.to.this == exp.DataType.Type.BIGINT:
    483                to = "SIGNED"
    484            elif expression.to.this == exp.DataType.Type.UBIGINT:
    485                to = "UNSIGNED"
    486            else:
    487                return super().cast_sql(expression)
    488
    489            return f"CAST({self.sql(expression, 'this')} AS {to})"

(U)BIGINT is not allowed in a CAST expression, so we use (UN)SIGNED instead.

def show_sql(self, expression: sqlglot.expressions.Show) -> str: View Source

    491        def show_sql(self, expression: exp.Show) -> str:
    492            this = f" {expression.name}"
    493            full = " FULL" if expression.args.get("full") else ""
    494            global_ = " GLOBAL" if expression.args.get("global") else ""
    495
    496            target = self.sql(expression, "target")
    497            target = f" {target}" if target else ""
    498            if expression.name in {"COLUMNS", "INDEX"}:
    499                target = f" FROM{target}"
    500            elif expression.name == "GRANTS":
    501                target = f" FOR{target}"
    502
    503            db = self._prefixed_sql("FROM", expression, "db")
    504
    505            like = self._prefixed_sql("LIKE", expression, "like")
    506            where = self.sql(expression, "where")
    507
    508            types = self.expressions(expression, key="types")
    509            types = f" {types}" if types else types
    510            query = self._prefixed_sql("FOR QUERY", expression, "query")
    511
    512            if expression.name == "PROFILE":
    513                offset = self._prefixed_sql("OFFSET", expression, "offset")
    514                limit = self._prefixed_sql("LIMIT", expression, "limit")
    515            else:
    516                offset = ""
    517                limit = self._oldstyle_limit_sql(expression)
    518
    519            log = self._prefixed_sql("IN", expression, "log")
    520            position = self._prefixed_sql("FROM", expression, "position")
    521
    522            channel = self._prefixed_sql("FOR CHANNEL", expression, "channel")
    523
    524            if expression.name == "ENGINE":
    525                mutex_or_status = " MUTEX" if expression.args.get("mutex") else " STATUS"
    526            else:
    527                mutex_or_status = ""
    528
    529            return f"SHOW{full}{global_}{this}{target}{types}{db}{query}{log}{position}{channel}{mutex_or_status}{like}{where}{offset}{limit}"

SELECT_KINDS: Tuple[str, ...] = ()
INVERSE_TIME_MAPPING: Dict[str, str] = {'%B': '%M', '%-m': '%c', '%-d': '%e', '%I': '%h', '%M': '%i', '%S': '%S', '%W': '%u', '%-H': '%k', '%-I': '%l', '%H:%M:%S': '%T', '%a': '%W'}
INVERSE_TIME_TRIE: Dict = {'%': {'B': {0: True}, '-': {'m': {0: True}, 'd': {0: True}, 'H': {0: True}, 'I': {0: True}}, 'I': {0: True}, 'M': {0: True}, 'S': {0: True}, 'W': {0: True}, 'H': {':': {'%': {'M': {':': {'%': {'S': {0: True}}}}}}}, 'a': {0: True}}}
@classmethod
def can_identify(text: str, identify: str | bool = 'safe') -> bool: View Source

    246    @classmethod
    247    def can_identify(cls, text: str, identify: str | bool = "safe") -> bool:
    248        """Checks if text can be identified given an identify option.
    249
    250        Args:
    251            text: The text to check.
    252            identify:
    253                "always" or `True`: Always returns true.
    254                "safe": True if the identifier is case-insensitive.
    255
    256        Returns:
    257            Whether or not the given text can be identified.
    258        """
    259        if identify is True or identify == "always":
    260            return True
    261
    262        if identify == "safe":
    263            return not cls.case_sensitive(text)
    264
    265        return False

Checks if text can be identified given an identify option.

###### Arguments:

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

###### Returns:

> Whether or not the given text can be identified.

QUOTE_START = "'"
QUOTE_END = "'"
IDENTIFIER_START = '`'
IDENTIFIER_END = '`'
STRING_ESCAPE = "'"
IDENTIFIER_ESCAPE = '"'
BIT_START: Optional[str] = "b'"
BIT_END: Optional[str] = "'"
HEX_START: Optional[str] = "x'"
HEX_END: Optional[str] = "'"
BYTE_START: Optional[str] = None
BYTE_END: Optional[str] = None

##### Inherited Members

sqlglot.generator.Generator
  Generator
  EXPLICIT_UNION
  WRAP_DERIVED_VALUES
  CREATE_FUNCTION_RETURN_AS
  MATCHED_BY_SOURCE
  SINGLE_STRING_INTERVAL
  INTERVAL_ALLOWS_PLURAL_FORM
  TABLESAMPLE_WITH_METHOD
  TABLESAMPLE_SIZE_IS_PERCENT
  RENAME_TABLE_WITH_DB
  GROUPINGS_SEP
  INDEX_ON
  QUERY_HINTS
  IS_BOOL_ALLOWED
  LIMIT_IS_TOP
  RETURNING_END
  COLUMN_JOIN_MARKS_SUPPORTED
  STAR_MAPPING
  TIME_PART_SINGULARS
  TOKEN_MAPPING
  STRUCT_DELIMITER
  PARAMETER_TOKEN
  RESERVED_KEYWORDS
  WITH_SEPARATED_COMMENTS
  UNWRAPPED_INTERVAL_VALUES
  SENTINEL_LINE_BREAK
  INDEX_OFFSET
  UNNEST_COLUMN_ONLY
  ALIAS_POST_TABLESAMPLE
  IDENTIFIERS_CAN_START_WITH_DIGIT
  STRICT_STRING_CONCAT
  NORMALIZE_FUNCTIONS
  NULL_ORDERING
  ESCAPE_LINE_BREAK
  pretty
  identify
  normalize
  pad
  unsupported_level
  max_unsupported
  leading_comma
  max_text_width
  comments
  normalize_functions
  unsupported_messages
  generate
  unsupported
  sep
  seg
  pad_comment
  maybe_comment
  wrap
  no_identify
  normalize_func
  indent
  sql
  uncache_sql
  cache_sql
  characterset_sql
  column_sql
  columnposition_sql
  columndef_sql
  columnconstraint_sql
  autoincrementcolumnconstraint_sql
  compresscolumnconstraint_sql
  generatedasidentitycolumnconstraint_sql
  notnullcolumnconstraint_sql
  primarykeycolumnconstraint_sql
  uniquecolumnconstraint_sql
  createable_sql
  create_sql
  clone_sql
  describe_sql
  prepend_ctes
  with_sql
  cte_sql
  tablealias_sql
  bitstring_sql
  hexstring_sql
  bytestring_sql
  rawstring_sql
  datatypesize_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
  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
  withtablehint_sql
  indextablehint_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
  offset_sql
  setitem_sql
  set_sql
  pragma_sql
  lock_sql
  literal_sql
  escape_str
  loaddata_sql
  null_sql
  boolean_sql
  order_sql
  cluster_sql
  distribute_sql
  sort_sql
  ordered_sql
  matchrecognize_sql
  query_modifiers
  offset_limit_modifiers
  after_having_modifiers
  after_limit_modifiers
  select_sql
  schema_sql
  schema_columns_sql
  star_sql
  parameter_sql
  sessionparameter_sql
  placeholder_sql
  subquery_sql
  qualify_sql
  union_sql
  union_op
  unnest_sql
  where_sql
  window_sql
  partition_by_sql
  windowspec_sql
  withingroup_sql
  between_sql
  bracket_sql
  safebracket_sql
  all_sql
  any_sql
  exists_sql
  case_sql
  constraint_sql
  nextvaluefor_sql
  extract_sql
  trim_sql
  safeconcat_sql
  check_sql
  foreignkey_sql
  primarykey_sql
  if_sql
  matchagainst_sql
  jsonkeyvalue_sql
  jsonobject_sql
  openjsoncolumndef_sql
  openjson_sql
  in_sql
  in_unnest_op
  interval_sql
  return_sql
  reference_sql
  anonymous_sql
  paren_sql
  neg_sql
  not_sql
  alias_sql
  aliases_sql
  attimezone_sql
  add_sql
  and_sql
  xor_sql
  connector_sql
  bitwiseand_sql
  bitwiseleftshift_sql
  bitwisenot_sql
  bitwiseor_sql
  bitwiserightshift_sql
  bitwisexor_sql
  currentdate_sql
  collate_sql
  command_sql
  comment_sql
  mergetreettlaction_sql
  mergetreettl_sql
  transaction_sql
  commit_sql
  rollback_sql
  altercolumn_sql
  renametable_sql
  altertable_sql
  droppartition_sql
  addconstraint_sql
  distinct_sql
  ignorenulls_sql
  respectnulls_sql
  intdiv_sql
  dpipe_sql
  safedpipe_sql
  div_sql
  overlaps_sql
  distance_sql
  dot_sql
  eq_sql
  escape_sql
  glob_sql
  gt_sql
  gte_sql
  ilike_sql
  ilikeany_sql
  is_sql
  like_sql
  likeany_sql
  similarto_sql
  lt_sql
  lte_sql
  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
  dictproperty_sql
  dictrange_sql
  dictsubproperty_sql
  oncluster_sql
  clusteredbyproperty_sql
  anyvalue_sql