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

    184    class Parser(parser.Parser):
    185        FUNC_TOKENS = {*parser.Parser.FUNC_TOKENS, TokenType.SCHEMA, TokenType.DATABASE}
    186        TABLE_ALIAS_TOKENS = (
    187            parser.Parser.TABLE_ALIAS_TOKENS - parser.Parser.TABLE_INDEX_HINT_TOKENS
    188        )
    189
    190        FUNCTIONS = {
    191            **parser.Parser.FUNCTIONS,
    192            "DATE_ADD": parse_date_delta_with_interval(exp.DateAdd),
    193            "DATE_FORMAT": format_time_lambda(exp.TimeToStr, "mysql"),
    194            "DATE_SUB": parse_date_delta_with_interval(exp.DateSub),
    195            "INSTR": lambda args: exp.StrPosition(substr=seq_get(args, 1), this=seq_get(args, 0)),
    196            "LOCATE": locate_to_strposition,
    197            "STR_TO_DATE": _str_to_date,
    198        }
    199
    200        FUNCTION_PARSERS = {
    201            **parser.Parser.FUNCTION_PARSERS,
    202            "GROUP_CONCAT": lambda self: self.expression(
    203                exp.GroupConcat,
    204                this=self._parse_lambda(),
    205                separator=self._match(TokenType.SEPARATOR) and self._parse_field(),
    206            ),
    207        }
    208
    209        STATEMENT_PARSERS = {
    210            **parser.Parser.STATEMENT_PARSERS,
    211            TokenType.SHOW: lambda self: self._parse_show(),
    212        }
    213
    214        SHOW_PARSERS = {
    215            "BINARY LOGS": _show_parser("BINARY LOGS"),
    216            "MASTER LOGS": _show_parser("BINARY LOGS"),
    217            "BINLOG EVENTS": _show_parser("BINLOG EVENTS"),
    218            "CHARACTER SET": _show_parser("CHARACTER SET"),
    219            "CHARSET": _show_parser("CHARACTER SET"),
    220            "COLLATION": _show_parser("COLLATION"),
    221            "FULL COLUMNS": _show_parser("COLUMNS", target="FROM", full=True),
    222            "COLUMNS": _show_parser("COLUMNS", target="FROM"),
    223            "CREATE DATABASE": _show_parser("CREATE DATABASE", target=True),
    224            "CREATE EVENT": _show_parser("CREATE EVENT", target=True),
    225            "CREATE FUNCTION": _show_parser("CREATE FUNCTION", target=True),
    226            "CREATE PROCEDURE": _show_parser("CREATE PROCEDURE", target=True),
    227            "CREATE TABLE": _show_parser("CREATE TABLE", target=True),
    228            "CREATE TRIGGER": _show_parser("CREATE TRIGGER", target=True),
    229            "CREATE VIEW": _show_parser("CREATE VIEW", target=True),
    230            "DATABASES": _show_parser("DATABASES"),
    231            "ENGINE": _show_parser("ENGINE", target=True),
    232            "STORAGE ENGINES": _show_parser("ENGINES"),
    233            "ENGINES": _show_parser("ENGINES"),
    234            "ERRORS": _show_parser("ERRORS"),
    235            "EVENTS": _show_parser("EVENTS"),
    236            "FUNCTION CODE": _show_parser("FUNCTION CODE", target=True),
    237            "FUNCTION STATUS": _show_parser("FUNCTION STATUS"),
    238            "GRANTS": _show_parser("GRANTS", target="FOR"),
    239            "INDEX": _show_parser("INDEX", target="FROM"),
    240            "MASTER STATUS": _show_parser("MASTER STATUS"),
    241            "OPEN TABLES": _show_parser("OPEN TABLES"),
    242            "PLUGINS": _show_parser("PLUGINS"),
    243            "PROCEDURE CODE": _show_parser("PROCEDURE CODE", target=True),
    244            "PROCEDURE STATUS": _show_parser("PROCEDURE STATUS"),
    245            "PRIVILEGES": _show_parser("PRIVILEGES"),
    246            "FULL PROCESSLIST": _show_parser("PROCESSLIST", full=True),
    247            "PROCESSLIST": _show_parser("PROCESSLIST"),
    248            "PROFILE": _show_parser("PROFILE"),
    249            "PROFILES": _show_parser("PROFILES"),
    250            "RELAYLOG EVENTS": _show_parser("RELAYLOG EVENTS"),
    251            "REPLICAS": _show_parser("REPLICAS"),
    252            "SLAVE HOSTS": _show_parser("REPLICAS"),
    253            "REPLICA STATUS": _show_parser("REPLICA STATUS"),
    254            "SLAVE STATUS": _show_parser("REPLICA STATUS"),
    255            "GLOBAL STATUS": _show_parser("STATUS", global_=True),
    256            "SESSION STATUS": _show_parser("STATUS"),
    257            "STATUS": _show_parser("STATUS"),
    258            "TABLE STATUS": _show_parser("TABLE STATUS"),
    259            "FULL TABLES": _show_parser("TABLES", full=True),
    260            "TABLES": _show_parser("TABLES"),
    261            "TRIGGERS": _show_parser("TRIGGERS"),
    262            "GLOBAL VARIABLES": _show_parser("VARIABLES", global_=True),
    263            "SESSION VARIABLES": _show_parser("VARIABLES"),
    264            "VARIABLES": _show_parser("VARIABLES"),
    265            "WARNINGS": _show_parser("WARNINGS"),
    266        }
    267
    268        SET_PARSERS = {
    269            **parser.Parser.SET_PARSERS,
    270            "PERSIST": lambda self: self._parse_set_item_assignment("PERSIST"),
    271            "PERSIST_ONLY": lambda self: self._parse_set_item_assignment("PERSIST_ONLY"),
    272            "CHARACTER SET": lambda self: self._parse_set_item_charset("CHARACTER SET"),
    273            "CHARSET": lambda self: self._parse_set_item_charset("CHARACTER SET"),
    274            "NAMES": lambda self: self._parse_set_item_names(),
    275        }
    276
    277        PROFILE_TYPES = {
    278            "ALL",
    279            "BLOCK IO",
    280            "CONTEXT SWITCHES",
    281            "CPU",
    282            "IPC",
    283            "MEMORY",
    284            "PAGE FAULTS",
    285            "SOURCE",
    286            "SWAPS",
    287        }
    288
    289        TYPE_TOKENS = {
    290            *parser.Parser.TYPE_TOKENS,
    291            TokenType.SET,
    292        }
    293
    294        ENUM_TYPE_TOKENS = {
    295            *parser.Parser.ENUM_TYPE_TOKENS,
    296            TokenType.SET,
    297        }
    298
    299        LOG_DEFAULTS_TO_LN = True
    300
    301        def _parse_show_mysql(
    302            self,
    303            this: str,
    304            target: bool | str = False,
    305            full: t.Optional[bool] = None,
    306            global_: t.Optional[bool] = None,
    307        ) -> exp.Show:
    308            if target:
    309                if isinstance(target, str):
    310                    self._match_text_seq(target)
    311                target_id = self._parse_id_var()
    312            else:
    313                target_id = None
    314
    315            log = self._parse_string() if self._match_text_seq("IN") else None
    316
    317            if this in {"BINLOG EVENTS", "RELAYLOG EVENTS"}:
    318                position = self._parse_number() if self._match_text_seq("FROM") else None
    319                db = None
    320            else:
    321                position = None
    322                db = None
    323
    324                if self._match(TokenType.FROM):
    325                    db = self._parse_id_var()
    326                elif self._match(TokenType.DOT):
    327                    db = target_id
    328                    target_id = self._parse_id_var()
    329
    330            channel = self._parse_id_var() if self._match_text_seq("FOR", "CHANNEL") else None
    331
    332            like = self._parse_string() if self._match_text_seq("LIKE") else None
    333            where = self._parse_where()
    334
    335            if this == "PROFILE":
    336                types = self._parse_csv(lambda: self._parse_var_from_options(self.PROFILE_TYPES))
    337                query = self._parse_number() if self._match_text_seq("FOR", "QUERY") else None
    338                offset = self._parse_number() if self._match_text_seq("OFFSET") else None
    339                limit = self._parse_number() if self._match_text_seq("LIMIT") else None
    340            else:
    341                types, query = None, None
    342                offset, limit = self._parse_oldstyle_limit()
    343
    344            mutex = True if self._match_text_seq("MUTEX") else None
    345            mutex = False if self._match_text_seq("STATUS") else mutex
    346
    347            return self.expression(
    348                exp.Show,
    349                this=this,
    350                target=target_id,
    351                full=full,
    352                log=log,
    353                position=position,
    354                db=db,
    355                channel=channel,
    356                like=like,
    357                where=where,
    358                types=types,
    359                query=query,
    360                offset=offset,
    361                limit=limit,
    362                mutex=mutex,
    363                **{"global": global_},  # type: ignore
    364            )
    365
    366        def _parse_oldstyle_limit(
    367            self,
    368        ) -> t.Tuple[t.Optional[exp.Expression], t.Optional[exp.Expression]]:
    369            limit = None
    370            offset = None
    371            if self._match_text_seq("LIMIT"):
    372                parts = self._parse_csv(self._parse_number)
    373                if len(parts) == 1:
    374                    limit = parts[0]
    375                elif len(parts) == 2:
    376                    limit = parts[1]
    377                    offset = parts[0]
    378
    379            return offset, limit
    380
    381        def _parse_set_item_charset(self, kind: str) -> exp.Expression:
    382            this = self._parse_string() or self._parse_id_var()
    383            return self.expression(exp.SetItem, this=this, kind=kind)
    384
    385        def _parse_set_item_names(self) -> exp.Expression:
    386            charset = self._parse_string() or self._parse_id_var()
    387            if self._match_text_seq("COLLATE"):
    388                collate = self._parse_string() or self._parse_id_var()
    389            else:
    390                collate = None
    391
    392            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.MEDIUMBLOB: 'MEDIUMBLOB'>, <TokenType.GEOMETRY: 'GEOMETRY'>, <TokenType.INT8RANGE: 'INT8RANGE'>, <TokenType.MONEY: 'MONEY'>, <TokenType.OFFSET: 'OFFSET'>, <TokenType.LONGBLOB: 'LONGBLOB'>, <TokenType.INT128: 'INT128'>, <TokenType.SCHEMA: 'SCHEMA'>, <TokenType.IDENTIFIER: 'IDENTIFIER'>, <TokenType.TIMESTAMPTZ: 'TIMESTAMPTZ'>, <TokenType.BIGSERIAL: 'BIGSERIAL'>, <TokenType.RANGE: 'RANGE'>, <TokenType.UNIQUEIDENTIFIER: 'UNIQUEIDENTIFIER'>, <TokenType.FLOAT: 'FLOAT'>, <TokenType.TIMESTAMPLTZ: 'TIMESTAMPLTZ'>, <TokenType.CURRENT_DATE: 'CURRENT_DATE'>, <TokenType.REPLACE: 'REPLACE'>, <TokenType.MEDIUMTEXT: 'MEDIUMTEXT'>, <TokenType.HLLSKETCH: 'HLLSKETCH'>, <TokenType.STRUCT: 'STRUCT'>, <TokenType.PRIMARY_KEY: 'PRIMARY_KEY'>, <TokenType.INT: 'INT'>, <TokenType.DATETIME64: 'DATETIME64'>, <TokenType.VARCHAR: 'VARCHAR'>, <TokenType.CURRENT_USER: 'CURRENT_USER'>, <TokenType.TSTZRANGE: 'TSTZRANGE'>, <TokenType.CURRENT_DATETIME: 'CURRENT_DATETIME'>, <TokenType.FORMAT: 'FORMAT'>, <TokenType.SMALLMONEY: 'SMALLMONEY'>, <TokenType.NVARCHAR: 'NVARCHAR'>, <TokenType.NUMMULTIRANGE: 'NUMMULTIRANGE'>, <TokenType.INDEX: 'INDEX'>, <TokenType.TSRANGE: 'TSRANGE'>, <TokenType.BIGINT: 'BIGINT'>, <TokenType.CURRENT_TIME: 'CURRENT_TIME'>, <TokenType.GEOGRAPHY: 'GEOGRAPHY'>, <TokenType.CHAR: 'CHAR'>, <TokenType.USERDEFINED: 'USERDEFINED'>, <TokenType.DATABASE: 'DATABASE'>, <TokenType.ISNULL: 'ISNULL'>, <TokenType.IMAGE: 'IMAGE'>, <TokenType.LIKE: 'LIKE'>, <TokenType.TABLE: 'TABLE'>, <TokenType.USMALLINT: 'USMALLINT'>, <TokenType.SMALLINT: 'SMALLINT'>, <TokenType.VAR: 'VAR'>, <TokenType.SMALLSERIAL: 'SMALLSERIAL'>, <TokenType.MERGE: 'MERGE'>, <TokenType.ROWVERSION: 'ROWVERSION'>, <TokenType.JSONB: 'JSONB'>, <TokenType.LONGTEXT: 'LONGTEXT'>, <TokenType.ARRAY: 'ARRAY'>, <TokenType.TIMESTAMP: 'TIMESTAMP'>, <TokenType.VARIANT: 'VARIANT'>, <TokenType.FILTER: 'FILTER'>, <TokenType.BIGDECIMAL: 'BIGDECIMAL'>, <TokenType.UBIGINT: 'UBIGINT'>, <TokenType.TSTZMULTIRANGE: 'TSTZMULTIRANGE'>, <TokenType.XML: 'XML'>, <TokenType.UNNEST: 'UNNEST'>, <TokenType.INTERVAL: 'INTERVAL'>, <TokenType.NCHAR: 'NCHAR'>, <TokenType.FIRST: 'FIRST'>, <TokenType.WINDOW: 'WINDOW'>, <TokenType.BINARY: 'BINARY'>, <TokenType.DATERANGE: 'DATERANGE'>, <TokenType.MAP: 'MAP'>, <TokenType.TIME: 'TIME'>, <TokenType.CURRENT_TIMESTAMP: 'CURRENT_TIMESTAMP'>, <TokenType.DECIMAL: 'DECIMAL'>, <TokenType.COMMAND: 'COMMAND'>, <TokenType.GLOB: 'GLOB'>, <TokenType.SERIAL: 'SERIAL'>, <TokenType.ALL: 'ALL'>, <TokenType.BIT: 'BIT'>, <TokenType.TEXT: 'TEXT'>, <TokenType.TSMULTIRANGE: 'TSMULTIRANGE'>, <TokenType.ANY: 'ANY'>, <TokenType.UINT128: 'UINT128'>, <TokenType.PSEUDO_TYPE: 'PSEUDO_TYPE'>, <TokenType.UINT256: 'UINT256'>, <TokenType.SUPER: 'SUPER'>, <TokenType.JSON: 'JSON'>, <TokenType.ILIKE: 'ILIKE'>, <TokenType.LEFT: 'LEFT'>, <TokenType.UUID: 'UUID'>, <TokenType.HSTORE: 'HSTORE'>, <TokenType.VARBINARY: 'VARBINARY'>, <TokenType.EXISTS: 'EXISTS'>, <TokenType.DATETIME: 'DATETIME'>, <TokenType.DOUBLE: 'DOUBLE'>, <TokenType.DATE: 'DATE'>, <TokenType.NUMRANGE: 'NUMRANGE'>, <TokenType.INET: 'INET'>, <TokenType.NULLABLE: 'NULLABLE'>, <TokenType.SOME: 'SOME'>, <TokenType.OBJECT: 'OBJECT'>, <TokenType.DATEMULTIRANGE: 'DATEMULTIRANGE'>, <TokenType.TINYINT: 'TINYINT'>, <TokenType.ROW: 'ROW'>, <TokenType.INT256: 'INT256'>, <TokenType.INT4MULTIRANGE: 'INT4MULTIRANGE'>, <TokenType.UTINYINT: 'UTINYINT'>, <TokenType.ENUM: 'ENUM'>, <TokenType.UINT: 'UINT'>, <TokenType.BOOLEAN: 'BOOLEAN'>, <TokenType.INT8MULTIRANGE: 'INT8MULTIRANGE'>, <TokenType.INT4RANGE: 'INT4RANGE'>, <TokenType.RIGHT: 'RIGHT'>}
TABLE_ALIAS_TOKENS = {<TokenType.SHOW: 'SHOW'>, <TokenType.MEDIUMBLOB: 'MEDIUMBLOB'>, <TokenType.GEOMETRY: 'GEOMETRY'>, <TokenType.ASC: 'ASC'>, <TokenType.MONEY: 'MONEY'>, <TokenType.SETTINGS: 'SETTINGS'>, <TokenType.SCHEMA: 'SCHEMA'>, <TokenType.RANGE: 'RANGE'>, <TokenType.FLOAT: 'FLOAT'>, <TokenType.STRUCT: 'STRUCT'>, <TokenType.MEDIUMTEXT: 'MEDIUMTEXT'>, <TokenType.HLLSKETCH: 'HLLSKETCH'>, <TokenType.CURRENT_DATE: 'CURRENT_DATE'>, <TokenType.INT: 'INT'>, <TokenType.TOP: 'TOP'>, <TokenType.CURRENT_USER: 'CURRENT_USER'>, <TokenType.SEMI: 'SEMI'>, <TokenType.CURRENT_DATETIME: 'CURRENT_DATETIME'>, <TokenType.FORMAT: 'FORMAT'>, <TokenType.PIVOT: 'PIVOT'>, <TokenType.NVARCHAR: 'NVARCHAR'>, <TokenType.NUMMULTIRANGE: 'NUMMULTIRANGE'>, <TokenType.INDEX: 'INDEX'>, <TokenType.TSRANGE: 'TSRANGE'>, <TokenType.ORDINALITY: 'ORDINALITY'>, <TokenType.USERDEFINED: 'USERDEFINED'>, <TokenType.CURRENT_TIME: 'CURRENT_TIME'>, <TokenType.DATABASE: 'DATABASE'>, <TokenType.LOAD: 'LOAD'>, <TokenType.TABLE: 'TABLE'>, <TokenType.USMALLINT: 'USMALLINT'>, <TokenType.SMALLSERIAL: 'SMALLSERIAL'>, <TokenType.ROWVERSION: 'ROWVERSION'>, <TokenType.JSONB: 'JSONB'>, <TokenType.LONGTEXT: 'LONGTEXT'>, <TokenType.ARRAY: 'ARRAY'>, <TokenType.VIEW: 'VIEW'>, <TokenType.FILTER: 'FILTER'>, <TokenType.BIGDECIMAL: 'BIGDECIMAL'>, <TokenType.UBIGINT: 'UBIGINT'>, <TokenType.TSTZMULTIRANGE: 'TSTZMULTIRANGE'>, <TokenType.CONSTRAINT: 'CONSTRAINT'>, <TokenType.NCHAR: 'NCHAR'>, <TokenType.REFERENCES: 'REFERENCES'>, <TokenType.DECIMAL: 'DECIMAL'>, <TokenType.SET: 'SET'>, <TokenType.DELETE: 'DELETE'>, <TokenType.COMMAND: 'COMMAND'>, <TokenType.CURRENT_TIMESTAMP: 'CURRENT_TIMESTAMP'>, <TokenType.ANTI: 'ANTI'>, <TokenType.DESCRIBE: 'DESCRIBE'>, <TokenType.DIV: 'DIV'>, <TokenType.TSMULTIRANGE: 'TSMULTIRANGE'>, <TokenType.UINT128: 'UINT128'>, <TokenType.PERCENT: 'PERCENT'>, <TokenType.COLLATE: 'COLLATE'>, <TokenType.AUTO_INCREMENT: 'AUTO_INCREMENT'>, <TokenType.CACHE: 'CACHE'>, <TokenType.VARBINARY: 'VARBINARY'>, <TokenType.DOUBLE: 'DOUBLE'>, <TokenType.DATE: 'DATE'>, <TokenType.NUMRANGE: 'NUMRANGE'>, <TokenType.NULLABLE: 'NULLABLE'>, <TokenType.SOME: 'SOME'>, <TokenType.DATEMULTIRANGE: 'DATEMULTIRANGE'>, <TokenType.EXECUTE: 'EXECUTE'>, <TokenType.UNPIVOT: 'UNPIVOT'>, <TokenType.INT256: 'INT256'>, <TokenType.INT4MULTIRANGE: 'INT4MULTIRANGE'>, <TokenType.UTINYINT: 'UTINYINT'>, <TokenType.ENUM: 'ENUM'>, <TokenType.DESC: 'DESC'>, <TokenType.VOLATILE: 'VOLATILE'>, <TokenType.BOOLEAN: 'BOOLEAN'>, <TokenType.INT4RANGE: 'INT4RANGE'>, <TokenType.CASE: 'CASE'>, <TokenType.INT8RANGE: 'INT8RANGE'>, <TokenType.LONGBLOB: 'LONGBLOB'>, <TokenType.INT128: 'INT128'>, <TokenType.UNIQUE: 'UNIQUE'>, <TokenType.TIMESTAMPTZ: 'TIMESTAMPTZ'>, <TokenType.TEMPORARY: 'TEMPORARY'>, <TokenType.BIGSERIAL: 'BIGSERIAL'>, <TokenType.UNIQUEIDENTIFIER: 'UNIQUEIDENTIFIER'>, <TokenType.TIMESTAMPLTZ: 'TIMESTAMPLTZ'>, <TokenType.BEGIN: 'BEGIN'>, <TokenType.PROCEDURE: 'PROCEDURE'>, <TokenType.ROWS: 'ROWS'>, <TokenType.DATETIME64: 'DATETIME64'>, <TokenType.VARCHAR: 'VARCHAR'>, <TokenType.NEXT: 'NEXT'>, <TokenType.TSTZRANGE: 'TSTZRANGE'>, <TokenType.FUNCTION: 'FUNCTION'>, <TokenType.END: 'END'>, <TokenType.SMALLMONEY: 'SMALLMONEY'>, <TokenType.BIGINT: 'BIGINT'>, <TokenType.GEOGRAPHY: 'GEOGRAPHY'>, <TokenType.CHAR: 'CHAR'>, <TokenType.ISNULL: 'ISNULL'>, <TokenType.IMAGE: 'IMAGE'>, <TokenType.SMALLINT: 'SMALLINT'>, <TokenType.VAR: 'VAR'>, <TokenType.FALSE: 'FALSE'>, <TokenType.MERGE: 'MERGE'>, <TokenType.TIMESTAMP: 'TIMESTAMP'>, <TokenType.VARIANT: 'VARIANT'>, <TokenType.XML: 'XML'>, <TokenType.OVERWRITE: 'OVERWRITE'>, <TokenType.IS: 'IS'>, <TokenType.INTERVAL: 'INTERVAL'>, <TokenType.FIRST: 'FIRST'>, <TokenType.COLUMN: 'COLUMN'>, <TokenType.BINARY: 'BINARY'>, <TokenType.KEEP: 'KEEP'>, <TokenType.DATERANGE: 'DATERANGE'>, <TokenType.MAP: 'MAP'>, <TokenType.TIME: 'TIME'>, <TokenType.DICTIONARY: 'DICTIONARY'>, <TokenType.SERIAL: 'SERIAL'>, <TokenType.ALL: 'ALL'>, <TokenType.BIT: 'BIT'>, <TokenType.UPDATE: 'UPDATE'>, <TokenType.TEXT: 'TEXT'>, <TokenType.COMMENT: 'COMMENT'>, <TokenType.ANY: 'ANY'>, <TokenType.PSEUDO_TYPE: 'PSEUDO_TYPE'>, <TokenType.ESCAPE: 'ESCAPE'>, <TokenType.UINT256: 'UINT256'>, <TokenType.SUPER: 'SUPER'>, <TokenType.JSON: 'JSON'>, <TokenType.IF: 'IF'>, <TokenType.TRUE: 'TRUE'>, <TokenType.UUID: 'UUID'>, <TokenType.HSTORE: 'HSTORE'>, <TokenType.EXISTS: 'EXISTS'>, <TokenType.DATETIME: 'DATETIME'>, <TokenType.PRAGMA: 'PRAGMA'>, <TokenType.INET: 'INET'>, <TokenType.COMMIT: 'COMMIT'>, <TokenType.OBJECT: 'OBJECT'>, <TokenType.PARTITION: 'PARTITION'>, <TokenType.TINYINT: 'TINYINT'>, <TokenType.ROW: 'ROW'>, <TokenType.DEFAULT: 'DEFAULT'>, <TokenType.UINT: 'UINT'>, <TokenType.INT8MULTIRANGE: 'INT8MULTIRANGE'>}
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'>>, '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'>>, 'MAP': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Map'>>, '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'>>, '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_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 = {'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>>}
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.END: 'END'>: <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 = {'CONTEXT SWITCHES', 'SOURCE', 'CPU', 'IPC', 'SWAPS', 'ALL', 'BLOCK IO', 'MEMORY', 'PAGE FAULTS'}
TYPE_TOKENS = {<TokenType.MEDIUMBLOB: 'MEDIUMBLOB'>, <TokenType.GEOMETRY: 'GEOMETRY'>, <TokenType.INT8RANGE: 'INT8RANGE'>, <TokenType.MONEY: 'MONEY'>, <TokenType.LONGBLOB: 'LONGBLOB'>, <TokenType.INT128: 'INT128'>, <TokenType.TIMESTAMPTZ: 'TIMESTAMPTZ'>, <TokenType.BIGSERIAL: 'BIGSERIAL'>, <TokenType.UNIQUEIDENTIFIER: 'UNIQUEIDENTIFIER'>, <TokenType.FLOAT: 'FLOAT'>, <TokenType.TIMESTAMPLTZ: 'TIMESTAMPLTZ'>, <TokenType.MEDIUMTEXT: 'MEDIUMTEXT'>, <TokenType.HLLSKETCH: 'HLLSKETCH'>, <TokenType.STRUCT: 'STRUCT'>, <TokenType.INT: 'INT'>, <TokenType.DATETIME64: 'DATETIME64'>, <TokenType.VARCHAR: 'VARCHAR'>, <TokenType.TSTZRANGE: 'TSTZRANGE'>, <TokenType.SMALLMONEY: 'SMALLMONEY'>, <TokenType.NVARCHAR: 'NVARCHAR'>, <TokenType.NUMMULTIRANGE: 'NUMMULTIRANGE'>, <TokenType.TSRANGE: 'TSRANGE'>, <TokenType.BIGINT: 'BIGINT'>, <TokenType.GEOGRAPHY: 'GEOGRAPHY'>, <TokenType.USERDEFINED: 'USERDEFINED'>, <TokenType.CHAR: 'CHAR'>, <TokenType.IMAGE: 'IMAGE'>, <TokenType.USMALLINT: 'USMALLINT'>, <TokenType.SMALLINT: 'SMALLINT'>, <TokenType.SMALLSERIAL: 'SMALLSERIAL'>, <TokenType.ROWVERSION: 'ROWVERSION'>, <TokenType.JSONB: 'JSONB'>, <TokenType.LONGTEXT: 'LONGTEXT'>, <TokenType.ARRAY: 'ARRAY'>, <TokenType.TIMESTAMP: 'TIMESTAMP'>, <TokenType.VARIANT: 'VARIANT'>, <TokenType.BIGDECIMAL: 'BIGDECIMAL'>, <TokenType.XML: 'XML'>, <TokenType.UBIGINT: 'UBIGINT'>, <TokenType.TSTZMULTIRANGE: 'TSTZMULTIRANGE'>, <TokenType.INTERVAL: 'INTERVAL'>, <TokenType.NCHAR: 'NCHAR'>, <TokenType.BINARY: 'BINARY'>, <TokenType.DATERANGE: 'DATERANGE'>, <TokenType.MAP: 'MAP'>, <TokenType.TIME: 'TIME'>, <TokenType.DECIMAL: 'DECIMAL'>, <TokenType.SET: 'SET'>, <TokenType.SERIAL: 'SERIAL'>, <TokenType.BIT: 'BIT'>, <TokenType.TEXT: 'TEXT'>, <TokenType.TSMULTIRANGE: 'TSMULTIRANGE'>, <TokenType.UINT128: 'UINT128'>, <TokenType.PSEUDO_TYPE: 'PSEUDO_TYPE'>, <TokenType.UINT256: 'UINT256'>, <TokenType.SUPER: 'SUPER'>, <TokenType.JSON: 'JSON'>, <TokenType.UUID: 'UUID'>, <TokenType.HSTORE: 'HSTORE'>, <TokenType.VARBINARY: 'VARBINARY'>, <TokenType.DATETIME: 'DATETIME'>, <TokenType.DOUBLE: 'DOUBLE'>, <TokenType.DATE: 'DATE'>, <TokenType.NUMRANGE: 'NUMRANGE'>, <TokenType.INET: 'INET'>, <TokenType.NULLABLE: 'NULLABLE'>, <TokenType.OBJECT: 'OBJECT'>, <TokenType.DATEMULTIRANGE: 'DATEMULTIRANGE'>, <TokenType.TINYINT: 'TINYINT'>, <TokenType.INT256: 'INT256'>, <TokenType.INT4MULTIRANGE: 'INT4MULTIRANGE'>, <TokenType.UTINYINT: 'UTINYINT'>, <TokenType.ENUM: 'ENUM'>, <TokenType.UINT: 'UINT'>, <TokenType.BOOLEAN: 'BOOLEAN'>, <TokenType.INT8MULTIRANGE: 'INT8MULTIRANGE'>, <TokenType.INT4RANGE: 'INT4RANGE'>}
ENUM_TYPE_TOKENS = {<TokenType.ENUM: 'ENUM'>, <TokenType.SET: 'SET'>}
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
  CONJUNCTION
  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
  RANGE_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
  CONVERT_TYPE_FIRST
  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

    394    class Generator(generator.Generator):
    395        LOCKING_READS_SUPPORTED = True
    396        NULL_ORDERING_SUPPORTED = False
    397        JOIN_HINTS = False
    398        TABLE_HINTS = True
    399
    400        TRANSFORMS = {
    401            **generator.Generator.TRANSFORMS,
    402            exp.CurrentDate: no_paren_current_date_sql,
    403            exp.DateDiff: lambda self, e: self.func("DATEDIFF", e.this, e.expression),
    404            exp.DateAdd: _date_add_sql("ADD"),
    405            exp.DateStrToDate: datestrtodate_sql,
    406            exp.DateSub: _date_add_sql("SUB"),
    407            exp.DateTrunc: _date_trunc_sql,
    408            exp.DayOfMonth: rename_func("DAYOFMONTH"),
    409            exp.DayOfWeek: rename_func("DAYOFWEEK"),
    410            exp.DayOfYear: rename_func("DAYOFYEAR"),
    411            exp.GroupConcat: lambda self, e: f"""GROUP_CONCAT({self.sql(e, "this")} SEPARATOR {self.sql(e, "separator") or "','"})""",
    412            exp.ILike: no_ilike_sql,
    413            exp.JSONExtractScalar: arrow_json_extract_scalar_sql,
    414            exp.Max: max_or_greatest,
    415            exp.Min: min_or_least,
    416            exp.NullSafeEQ: lambda self, e: self.binary(e, "<=>"),
    417            exp.NullSafeNEQ: lambda self, e: self.not_sql(self.binary(e, "<=>")),
    418            exp.Pivot: no_pivot_sql,
    419            exp.Select: transforms.preprocess([transforms.eliminate_distinct_on]),
    420            exp.StrPosition: strposition_to_locate_sql,
    421            exp.StrToDate: _str_to_date_sql,
    422            exp.StrToTime: _str_to_date_sql,
    423            exp.TableSample: no_tablesample_sql,
    424            exp.TimeStrToUnix: rename_func("UNIX_TIMESTAMP"),
    425            exp.TimeToStr: lambda self, e: self.func("DATE_FORMAT", e.this, self.format_time(e)),
    426            exp.Trim: _trim_sql,
    427            exp.TryCast: no_trycast_sql,
    428            exp.WeekOfYear: rename_func("WEEKOFYEAR"),
    429        }
    430
    431        TYPE_MAPPING = generator.Generator.TYPE_MAPPING.copy()
    432        TYPE_MAPPING.pop(exp.DataType.Type.MEDIUMTEXT)
    433        TYPE_MAPPING.pop(exp.DataType.Type.LONGTEXT)
    434        TYPE_MAPPING.pop(exp.DataType.Type.MEDIUMBLOB)
    435        TYPE_MAPPING.pop(exp.DataType.Type.LONGBLOB)
    436
    437        PROPERTIES_LOCATION = {
    438            **generator.Generator.PROPERTIES_LOCATION,
    439            exp.TransientProperty: exp.Properties.Location.UNSUPPORTED,
    440            exp.VolatileProperty: exp.Properties.Location.UNSUPPORTED,
    441        }
    442
    443        LIMIT_FETCH = "LIMIT"
    444
    445        def show_sql(self, expression: exp.Show) -> str:
    446            this = f" {expression.name}"
    447            full = " FULL" if expression.args.get("full") else ""
    448            global_ = " GLOBAL" if expression.args.get("global") else ""
    449
    450            target = self.sql(expression, "target")
    451            target = f" {target}" if target else ""
    452            if expression.name in {"COLUMNS", "INDEX"}:
    453                target = f" FROM{target}"
    454            elif expression.name == "GRANTS":
    455                target = f" FOR{target}"
    456
    457            db = self._prefixed_sql("FROM", expression, "db")
    458
    459            like = self._prefixed_sql("LIKE", expression, "like")
    460            where = self.sql(expression, "where")
    461
    462            types = self.expressions(expression, key="types")
    463            types = f" {types}" if types else types
    464            query = self._prefixed_sql("FOR QUERY", expression, "query")
    465
    466            if expression.name == "PROFILE":
    467                offset = self._prefixed_sql("OFFSET", expression, "offset")
    468                limit = self._prefixed_sql("LIMIT", expression, "limit")
    469            else:
    470                offset = ""
    471                limit = self._oldstyle_limit_sql(expression)
    472
    473            log = self._prefixed_sql("IN", expression, "log")
    474            position = self._prefixed_sql("FROM", expression, "position")
    475
    476            channel = self._prefixed_sql("FOR CHANNEL", expression, "channel")
    477
    478            if expression.name == "ENGINE":
    479                mutex_or_status = " MUTEX" if expression.args.get("mutex") else " STATUS"
    480            else:
    481                mutex_or_status = ""
    482
    483            return f"SHOW{full}{global_}{this}{target}{types}{db}{query}{log}{position}{channel}{mutex_or_status}{like}{where}{offset}{limit}"
    484
    485        def _prefixed_sql(self, prefix: str, expression: exp.Expression, arg: str) -> str:
    486            sql = self.sql(expression, arg)
    487            return f" {prefix} {sql}" if sql else ""
    488
    489        def _oldstyle_limit_sql(self, expression: exp.Show) -> str:
    490            limit = self.sql(expression, "limit")
    491            offset = self.sql(expression, "offset")
    492            if limit:
    493                limit_offset = f"{offset}, {limit}" if offset else limit
    494                return f" LIMIT {limit_offset}"
    495            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
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.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 show_sql(self, expression: sqlglot.expressions.Show) -> str: View Source

    445        def show_sql(self, expression: exp.Show) -> str:
    446            this = f" {expression.name}"
    447            full = " FULL" if expression.args.get("full") else ""
    448            global_ = " GLOBAL" if expression.args.get("global") else ""
    449
    450            target = self.sql(expression, "target")
    451            target = f" {target}" if target else ""
    452            if expression.name in {"COLUMNS", "INDEX"}:
    453                target = f" FROM{target}"
    454            elif expression.name == "GRANTS":
    455                target = f" FOR{target}"
    456
    457            db = self._prefixed_sql("FROM", expression, "db")
    458
    459            like = self._prefixed_sql("LIKE", expression, "like")
    460            where = self.sql(expression, "where")
    461
    462            types = self.expressions(expression, key="types")
    463            types = f" {types}" if types else types
    464            query = self._prefixed_sql("FOR QUERY", expression, "query")
    465
    466            if expression.name == "PROFILE":
    467                offset = self._prefixed_sql("OFFSET", expression, "offset")
    468                limit = self._prefixed_sql("LIMIT", expression, "limit")
    469            else:
    470                offset = ""
    471                limit = self._oldstyle_limit_sql(expression)
    472
    473            log = self._prefixed_sql("IN", expression, "log")
    474            position = self._prefixed_sql("FROM", expression, "position")
    475
    476            channel = self._prefixed_sql("FOR CHANNEL", expression, "channel")
    477
    478            if expression.name == "ENGINE":
    479                mutex_or_status = " MUTEX" if expression.args.get("mutex") else " STATUS"
    480            else:
    481                mutex_or_status = ""
    482
    483            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

    247    @classmethod
    248    def can_identify(cls, text: str, identify: str | bool = "safe") -> bool:
    249        """Checks if text can be identified given an identify option.
    250
    251        Args:
    252            text: The text to check.
    253            identify:
    254                "always" or `True`: Always returns true.
    255                "safe": True if the identifier is case-insensitive.
    256
    257        Returns:
    258            Whether or not the given text can be identified.
    259        """
    260        if identify is True or identify == "always":
    261            return True
    262
    263        if identify == "safe":
    264            return not cls.case_sensitive(text)
    265
    266        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
RAW_START: Optional[str] = None
RAW_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
  IS_BOOL_ALLOWED
  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
  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
  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
  connector_sql
  bitwiseand_sql
  bitwiseleftshift_sql
  bitwisenot_sql
  bitwiseor_sql
  bitwiserightshift_sql
  bitwisexor_sql
  cast_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