Edit on GitHub

# sqlglot.dialects.sqlite

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    any_value_to_max_sql,
      9    arrow_json_extract_scalar_sql,
     10    arrow_json_extract_sql,
     11    concat_to_dpipe_sql,
     12    count_if_to_sum,
     13    no_ilike_sql,
     14    no_pivot_sql,
     15    no_tablesample_sql,
     16    no_trycast_sql,
     17    rename_func,
     18)
     19from sqlglot.tokens import TokenType
     20
     21
     22def _date_add_sql(self: SQLite.Generator, expression: exp.DateAdd) -> str:
     23    modifier = expression.expression
     24    modifier = modifier.name if modifier.is_string else self.sql(modifier)
     25    unit = expression.args.get("unit")
     26    modifier = f"'{modifier} {unit.name}'" if unit else f"'{modifier}'"
     27    return self.func("DATE", expression.this, modifier)
     28
     29
     30def _transform_create(expression: exp.Expression) -> exp.Expression:
     31    """Move primary key to a column and enforce auto_increment on primary keys."""
     32    schema = expression.this
     33
     34    if isinstance(expression, exp.Create) and isinstance(schema, exp.Schema):
     35        defs = {}
     36        primary_key = None
     37
     38        for e in schema.expressions:
     39            if isinstance(e, exp.ColumnDef):
     40                defs[e.name] = e
     41            elif isinstance(e, exp.PrimaryKey):
     42                primary_key = e
     43
     44        if primary_key and len(primary_key.expressions) == 1:
     45            column = defs[primary_key.expressions[0].name]
     46            column.append(
     47                "constraints", exp.ColumnConstraint(kind=exp.PrimaryKeyColumnConstraint())
     48            )
     49            schema.expressions.remove(primary_key)
     50        else:
     51            for column in defs.values():
     52                auto_increment = None
     53                for constraint in column.constraints.copy():
     54                    if isinstance(constraint.kind, exp.PrimaryKeyColumnConstraint):
     55                        break
     56                    if isinstance(constraint.kind, exp.AutoIncrementColumnConstraint):
     57                        auto_increment = constraint
     58                if auto_increment:
     59                    column.constraints.remove(auto_increment)
     60
     61    return expression
     62
     63
     64class SQLite(Dialect):
     65    # https://sqlite.org/forum/forumpost/5e575586ac5c711b?raw
     66    RESOLVES_IDENTIFIERS_AS_UPPERCASE = None
     67    SUPPORTS_SEMI_ANTI_JOIN = False
     68
     69    class Tokenizer(tokens.Tokenizer):
     70        IDENTIFIERS = ['"', ("[", "]"), "`"]
     71        HEX_STRINGS = [("x'", "'"), ("X'", "'"), ("0x", ""), ("0X", "")]
     72
     73    class Parser(parser.Parser):
     74        FUNCTIONS = {
     75            **parser.Parser.FUNCTIONS,
     76            "EDITDIST3": exp.Levenshtein.from_arg_list,
     77        }
     78
     79    class Generator(generator.Generator):
     80        JOIN_HINTS = False
     81        TABLE_HINTS = False
     82        QUERY_HINTS = False
     83        NVL2_SUPPORTED = False
     84
     85        TYPE_MAPPING = {
     86            **generator.Generator.TYPE_MAPPING,
     87            exp.DataType.Type.BOOLEAN: "INTEGER",
     88            exp.DataType.Type.TINYINT: "INTEGER",
     89            exp.DataType.Type.SMALLINT: "INTEGER",
     90            exp.DataType.Type.INT: "INTEGER",
     91            exp.DataType.Type.BIGINT: "INTEGER",
     92            exp.DataType.Type.FLOAT: "REAL",
     93            exp.DataType.Type.DOUBLE: "REAL",
     94            exp.DataType.Type.DECIMAL: "REAL",
     95            exp.DataType.Type.CHAR: "TEXT",
     96            exp.DataType.Type.NCHAR: "TEXT",
     97            exp.DataType.Type.VARCHAR: "TEXT",
     98            exp.DataType.Type.NVARCHAR: "TEXT",
     99            exp.DataType.Type.BINARY: "BLOB",
    100            exp.DataType.Type.VARBINARY: "BLOB",
    101        }
    102
    103        TOKEN_MAPPING = {
    104            TokenType.AUTO_INCREMENT: "AUTOINCREMENT",
    105        }
    106
    107        TRANSFORMS = {
    108            **generator.Generator.TRANSFORMS,
    109            exp.AnyValue: any_value_to_max_sql,
    110            exp.Concat: concat_to_dpipe_sql,
    111            exp.CountIf: count_if_to_sum,
    112            exp.Create: transforms.preprocess([_transform_create]),
    113            exp.CurrentDate: lambda *_: "CURRENT_DATE",
    114            exp.CurrentTime: lambda *_: "CURRENT_TIME",
    115            exp.CurrentTimestamp: lambda *_: "CURRENT_TIMESTAMP",
    116            exp.DateAdd: _date_add_sql,
    117            exp.DateStrToDate: lambda self, e: self.sql(e, "this"),
    118            exp.ILike: no_ilike_sql,
    119            exp.JSONExtract: arrow_json_extract_sql,
    120            exp.JSONExtractScalar: arrow_json_extract_scalar_sql,
    121            exp.JSONBExtract: arrow_json_extract_sql,
    122            exp.JSONBExtractScalar: arrow_json_extract_scalar_sql,
    123            exp.Levenshtein: rename_func("EDITDIST3"),
    124            exp.LogicalOr: rename_func("MAX"),
    125            exp.LogicalAnd: rename_func("MIN"),
    126            exp.Pivot: no_pivot_sql,
    127            exp.SafeConcat: concat_to_dpipe_sql,
    128            exp.Select: transforms.preprocess(
    129                [
    130                    transforms.eliminate_distinct_on,
    131                    transforms.eliminate_qualify,
    132                    transforms.eliminate_semi_and_anti_joins,
    133                ]
    134            ),
    135            exp.TableSample: no_tablesample_sql,
    136            exp.TimeStrToTime: lambda self, e: self.sql(e, "this"),
    137            exp.TryCast: no_trycast_sql,
    138        }
    139
    140        PROPERTIES_LOCATION = {
    141            k: exp.Properties.Location.UNSUPPORTED
    142            for k, v in generator.Generator.PROPERTIES_LOCATION.items()
    143        }
    144
    145        LIMIT_FETCH = "LIMIT"
    146
    147        def cast_sql(self, expression: exp.Cast, safe_prefix: t.Optional[str] = None) -> str:
    148            if expression.is_type("date"):
    149                return self.func("DATE", expression.this)
    150
    151            return super().cast_sql(expression)
    152
    153        def datediff_sql(self, expression: exp.DateDiff) -> str:
    154            unit = expression.args.get("unit")
    155            unit = unit.name.upper() if unit else "DAY"
    156
    157            sql = f"(JULIANDAY({self.sql(expression, 'this')}) - JULIANDAY({self.sql(expression, 'expression')}))"
    158
    159            if unit == "MONTH":
    160                sql = f"{sql} / 30.0"
    161            elif unit == "YEAR":
    162                sql = f"{sql} / 365.0"
    163            elif unit == "HOUR":
    164                sql = f"{sql} * 24.0"
    165            elif unit == "MINUTE":
    166                sql = f"{sql} * 1440.0"
    167            elif unit == "SECOND":
    168                sql = f"{sql} * 86400.0"
    169            elif unit == "MILLISECOND":
    170                sql = f"{sql} * 86400000.0"
    171            elif unit == "MICROSECOND":
    172                sql = f"{sql} * 86400000000.0"
    173            elif unit == "NANOSECOND":
    174                sql = f"{sql} * 8640000000000.0"
    175            else:
    176                self.unsupported("DATEDIFF unsupported for '{unit}'.")
    177
    178            return f"CAST({sql} AS INTEGER)"
    179
    180        # https://www.sqlite.org/lang_aggfunc.html#group_concat
    181        def groupconcat_sql(self, expression: exp.GroupConcat) -> str:
    182            this = expression.this
    183            distinct = expression.find(exp.Distinct)
    184
    185            if distinct:
    186                this = distinct.expressions[0]
    187                distinct_sql = "DISTINCT "
    188            else:
    189                distinct_sql = ""
    190
    191            if isinstance(expression.this, exp.Order):
    192                self.unsupported("SQLite GROUP_CONCAT doesn't support ORDER BY.")
    193                if expression.this.this and not distinct:
    194                    this = expression.this.this
    195
    196            separator = expression.args.get("separator")
    197            return f"GROUP_CONCAT({distinct_sql}{self.format_args(this, separator)})"
    198
    199        def least_sql(self, expression: exp.Least) -> str:
    200            if len(expression.expressions) > 1:
    201                return rename_func("MIN")(self, expression)
    202
    203            return self.sql(expression, "this")
    204
    205        def transaction_sql(self, expression: exp.Transaction) -> str:
    206            this = expression.this
    207            this = f" {this}" if this else ""
    208            return f"BEGIN{this} TRANSACTION"

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

     65class SQLite(Dialect):
     66    # https://sqlite.org/forum/forumpost/5e575586ac5c711b?raw
     67    RESOLVES_IDENTIFIERS_AS_UPPERCASE = None
     68    SUPPORTS_SEMI_ANTI_JOIN = False
     69
     70    class Tokenizer(tokens.Tokenizer):
     71        IDENTIFIERS = ['"', ("[", "]"), "`"]
     72        HEX_STRINGS = [("x'", "'"), ("X'", "'"), ("0x", ""), ("0X", "")]
     73
     74    class Parser(parser.Parser):
     75        FUNCTIONS = {
     76            **parser.Parser.FUNCTIONS,
     77            "EDITDIST3": exp.Levenshtein.from_arg_list,
     78        }
     79
     80    class Generator(generator.Generator):
     81        JOIN_HINTS = False
     82        TABLE_HINTS = False
     83        QUERY_HINTS = False
     84        NVL2_SUPPORTED = False
     85
     86        TYPE_MAPPING = {
     87            **generator.Generator.TYPE_MAPPING,
     88            exp.DataType.Type.BOOLEAN: "INTEGER",
     89            exp.DataType.Type.TINYINT: "INTEGER",
     90            exp.DataType.Type.SMALLINT: "INTEGER",
     91            exp.DataType.Type.INT: "INTEGER",
     92            exp.DataType.Type.BIGINT: "INTEGER",
     93            exp.DataType.Type.FLOAT: "REAL",
     94            exp.DataType.Type.DOUBLE: "REAL",
     95            exp.DataType.Type.DECIMAL: "REAL",
     96            exp.DataType.Type.CHAR: "TEXT",
     97            exp.DataType.Type.NCHAR: "TEXT",
     98            exp.DataType.Type.VARCHAR: "TEXT",
     99            exp.DataType.Type.NVARCHAR: "TEXT",
    100            exp.DataType.Type.BINARY: "BLOB",
    101            exp.DataType.Type.VARBINARY: "BLOB",
    102        }
    103
    104        TOKEN_MAPPING = {
    105            TokenType.AUTO_INCREMENT: "AUTOINCREMENT",
    106        }
    107
    108        TRANSFORMS = {
    109            **generator.Generator.TRANSFORMS,
    110            exp.AnyValue: any_value_to_max_sql,
    111            exp.Concat: concat_to_dpipe_sql,
    112            exp.CountIf: count_if_to_sum,
    113            exp.Create: transforms.preprocess([_transform_create]),
    114            exp.CurrentDate: lambda *_: "CURRENT_DATE",
    115            exp.CurrentTime: lambda *_: "CURRENT_TIME",
    116            exp.CurrentTimestamp: lambda *_: "CURRENT_TIMESTAMP",
    117            exp.DateAdd: _date_add_sql,
    118            exp.DateStrToDate: lambda self, e: self.sql(e, "this"),
    119            exp.ILike: no_ilike_sql,
    120            exp.JSONExtract: arrow_json_extract_sql,
    121            exp.JSONExtractScalar: arrow_json_extract_scalar_sql,
    122            exp.JSONBExtract: arrow_json_extract_sql,
    123            exp.JSONBExtractScalar: arrow_json_extract_scalar_sql,
    124            exp.Levenshtein: rename_func("EDITDIST3"),
    125            exp.LogicalOr: rename_func("MAX"),
    126            exp.LogicalAnd: rename_func("MIN"),
    127            exp.Pivot: no_pivot_sql,
    128            exp.SafeConcat: concat_to_dpipe_sql,
    129            exp.Select: transforms.preprocess(
    130                [
    131                    transforms.eliminate_distinct_on,
    132                    transforms.eliminate_qualify,
    133                    transforms.eliminate_semi_and_anti_joins,
    134                ]
    135            ),
    136            exp.TableSample: no_tablesample_sql,
    137            exp.TimeStrToTime: lambda self, e: self.sql(e, "this"),
    138            exp.TryCast: no_trycast_sql,
    139        }
    140
    141        PROPERTIES_LOCATION = {
    142            k: exp.Properties.Location.UNSUPPORTED
    143            for k, v in generator.Generator.PROPERTIES_LOCATION.items()
    144        }
    145
    146        LIMIT_FETCH = "LIMIT"
    147
    148        def cast_sql(self, expression: exp.Cast, safe_prefix: t.Optional[str] = None) -> str:
    149            if expression.is_type("date"):
    150                return self.func("DATE", expression.this)
    151
    152            return super().cast_sql(expression)
    153
    154        def datediff_sql(self, expression: exp.DateDiff) -> str:
    155            unit = expression.args.get("unit")
    156            unit = unit.name.upper() if unit else "DAY"
    157
    158            sql = f"(JULIANDAY({self.sql(expression, 'this')}) - JULIANDAY({self.sql(expression, 'expression')}))"
    159
    160            if unit == "MONTH":
    161                sql = f"{sql} / 30.0"
    162            elif unit == "YEAR":
    163                sql = f"{sql} / 365.0"
    164            elif unit == "HOUR":
    165                sql = f"{sql} * 24.0"
    166            elif unit == "MINUTE":
    167                sql = f"{sql} * 1440.0"
    168            elif unit == "SECOND":
    169                sql = f"{sql} * 86400.0"
    170            elif unit == "MILLISECOND":
    171                sql = f"{sql} * 86400000.0"
    172            elif unit == "MICROSECOND":
    173                sql = f"{sql} * 86400000000.0"
    174            elif unit == "NANOSECOND":
    175                sql = f"{sql} * 8640000000000.0"
    176            else:
    177                self.unsupported("DATEDIFF unsupported for '{unit}'.")
    178
    179            return f"CAST({sql} AS INTEGER)"
    180
    181        # https://www.sqlite.org/lang_aggfunc.html#group_concat
    182        def groupconcat_sql(self, expression: exp.GroupConcat) -> str:
    183            this = expression.this
    184            distinct = expression.find(exp.Distinct)
    185
    186            if distinct:
    187                this = distinct.expressions[0]
    188                distinct_sql = "DISTINCT "
    189            else:
    190                distinct_sql = ""
    191
    192            if isinstance(expression.this, exp.Order):
    193                self.unsupported("SQLite GROUP_CONCAT doesn't support ORDER BY.")
    194                if expression.this.this and not distinct:
    195                    this = expression.this.this
    196
    197            separator = expression.args.get("separator")
    198            return f"GROUP_CONCAT({distinct_sql}{self.format_args(this, separator)})"
    199
    200        def least_sql(self, expression: exp.Least) -> str:
    201            if len(expression.expressions) > 1:
    202                return rename_func("MIN")(self, expression)
    203
    204            return self.sql(expression, "this")
    205
    206        def transaction_sql(self, expression: exp.Transaction) -> str:
    207            this = expression.this
    208            this = f" {this}" if this else ""
    209            return f"BEGIN{this} TRANSACTION"

RESOLVES_IDENTIFIERS_AS_UPPERCASE: Optional[bool] = None
SUPPORTS_SEMI_ANTI_JOIN = False
tokenizer_class = <class 'SQLite.Tokenizer'>
parser_class = <class 'SQLite.Parser'>
generator_class = <class 'SQLite.Generator'>
TIME_TRIE: Dict = {}
FORMAT_TRIE: Dict = {}
INVERSE_TIME_MAPPING: Dict[str, str] = {}
INVERSE_TIME_TRIE: Dict = {}
INVERSE_ESCAPE_SEQUENCES: Dict[str, str] = {}
QUOTE_START = "'"
QUOTE_END = "'"
IDENTIFIER_START = '"'
IDENTIFIER_END = '"'
BIT_START = None
BIT_END = None
HEX_START = "x'"
HEX_END = "'"
BYTE_START = None
BYTE_END = None

##### Inherited Members

sqlglot.dialects.dialect.Dialect
  INDEX_OFFSET
  UNNEST_COLUMN_ONLY
  ALIAS_POST_TABLESAMPLE
  IDENTIFIERS_CAN_START_WITH_DIGIT
  DPIPE_IS_STRING_CONCAT
  STRICT_STRING_CONCAT
  SUPPORTS_USER_DEFINED_TYPES
  NORMALIZE_FUNCTIONS
  LOG_BASE_FIRST
  NULL_ORDERING
  DATE_FORMAT
  DATEINT_FORMAT
  TIME_FORMAT
  TIME_MAPPING
  FORMAT_MAPPING
  ESCAPE_SEQUENCES
  PSEUDOCOLUMNS
  get_or_raise
  format_time
  normalize_identifier
  case_sensitive
  can_identify
  quote_identifier
  parse
  parse_into
  generate
  transpile
  tokenize
  tokenizer
  parser
  generator

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

    70    class Tokenizer(tokens.Tokenizer):
    71        IDENTIFIERS = ['"', ("[", "]"), "`"]
    72        HEX_STRINGS = [("x'", "'"), ("X'", "'"), ("0x", ""), ("0X", "")]

IDENTIFIERS = ['"', ('[', ']'), '`']
HEX_STRINGS = [("x'", "'"), ("X'", "'"), ('0x', ''), ('0X', '')]

##### Inherited Members

sqlglot.tokens.Tokenizer
  SINGLE_TOKENS
  BIT_STRINGS
  BYTE_STRINGS
  RAW_STRINGS
  HEREDOC_STRINGS
  IDENTIFIER_ESCAPES
  QUOTES
  STRING_ESCAPES
  VAR_SINGLE_TOKENS
  ESCAPE_SEQUENCES
  IDENTIFIERS_CAN_START_WITH_DIGIT
  KEYWORDS
  WHITE_SPACE
  COMMANDS
  COMMAND_PREFIX_TOKENS
  NUMERIC_LITERALS
  ENCODE
  COMMENTS
  reset
  tokenize
  peek
  size
  sql
  tokens

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

    74    class Parser(parser.Parser):
    75        FUNCTIONS = {
    76            **parser.Parser.FUNCTIONS,
    77            "EDITDIST3": exp.Levenshtein.from_arg_list,
    78        }

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

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_CAT': <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'>>, 'CHR': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Chr'>>, 'CHAR': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Chr'>>, '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'>>, 'COLLATE': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Collate'>>, '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': <bound method Func.from_arg_list of <class 'sqlglot.expressions.DateAdd'>>, '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': <bound method Func.from_arg_list of <class 'sqlglot.expressions.DateSub'>>, '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'>>, 'EXPLODE_OUTER': <bound method Func.from_arg_list of <class 'sqlglot.expressions.ExplodeOuter'>>, 'EXTRACT': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Extract'>>, 'FIRST': <bound method Func.from_arg_list of <class 'sqlglot.expressions.First'>>, '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'>>, 'IS_NAN': <bound method Func.from_arg_list of <class 'sqlglot.expressions.IsNan'>>, 'ISNAN': <bound method Func.from_arg_list of <class 'sqlglot.expressions.IsNan'>>, 'J_S_O_N_ARRAY': <bound method Func.from_arg_list of <class 'sqlglot.expressions.JSONArray'>>, 'J_S_O_N_ARRAY_AGG': <bound method Func.from_arg_list of <class 'sqlglot.expressions.JSONArrayAgg'>>, 'JSON_ARRAY_CONTAINS': <bound method Func.from_arg_list of <class 'sqlglot.expressions.JSONArrayContains'>>, 'JSONB_EXTRACT': <bound method Func.from_arg_list of <class 'sqlglot.expressions.JSONBExtract'>>, 'JSONB_EXTRACT_SCALAR': <bound method Func.from_arg_list of <class 'sqlglot.expressions.JSONBExtractScalar'>>, 'JSON_EXTRACT': <bound method Func.from_arg_list of <class 'sqlglot.expressions.JSONExtract'>>, 'JSON_EXTRACT_SCALAR': <bound method Func.from_arg_list of <class 'sqlglot.expressions.JSONExtractScalar'>>, 'JSON_FORMAT': <bound method Func.from_arg_list of <class 'sqlglot.expressions.JSONFormat'>>, 'J_S_O_N_OBJECT': <bound method Func.from_arg_list of <class 'sqlglot.expressions.JSONObject'>>, 'J_S_O_N_TABLE': <bound method Func.from_arg_list of <class 'sqlglot.expressions.JSONTable'>>, 'LAST': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Last'>>, 'LAST_DATE_OF_MONTH': <bound method Func.from_arg_list of <class 'sqlglot.expressions.LastDateOfMonth'>>, 'LEAST': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Least'>>, 'LEFT': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Left'>>, 'LENGTH': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Length'>>, 'LEN': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Length'>>, 'LEVENSHTEIN': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Levenshtein'>>, 'LN': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Ln'>>, 'LOG': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Log'>>, 'LOG10': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Log10'>>, 'LOG2': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Log2'>>, 'LOGICAL_AND': <bound method Func.from_arg_list of <class 'sqlglot.expressions.LogicalAnd'>>, 'BOOL_AND': <bound method Func.from_arg_list of <class 'sqlglot.expressions.LogicalAnd'>>, 'BOOLAND_AGG': <bound method Func.from_arg_list of <class 'sqlglot.expressions.LogicalAnd'>>, 'LOGICAL_OR': <bound method Func.from_arg_list of <class 'sqlglot.expressions.LogicalOr'>>, 'BOOL_OR': <bound method Func.from_arg_list of <class 'sqlglot.expressions.LogicalOr'>>, 'BOOLOR_AGG': <bound method Func.from_arg_list of <class 'sqlglot.expressions.LogicalOr'>>, 'LOWER': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Lower'>>, 'LCASE': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Lower'>>, 'MD5': <bound method Func.from_arg_list of <class 'sqlglot.expressions.MD5'>>, 'MD5_DIGEST': <bound method Func.from_arg_list of <class 'sqlglot.expressions.MD5Digest'>>, 'MAP': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Map'>>, 'MAP_FROM_ENTRIES': <bound method Func.from_arg_list of <class 'sqlglot.expressions.MapFromEntries'>>, 'MATCH_AGAINST': <bound method Func.from_arg_list of <class 'sqlglot.expressions.MatchAgainst'>>, 'MAX': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Max'>>, 'MIN': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Min'>>, 'MONTH': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Month'>>, 'MONTHS_BETWEEN': <bound method Func.from_arg_list of <class 'sqlglot.expressions.MonthsBetween'>>, 'NEXT_VALUE_FOR': <bound method Func.from_arg_list of <class 'sqlglot.expressions.NextValueFor'>>, 'NUMBER_TO_STR': <bound method Func.from_arg_list of <class 'sqlglot.expressions.NumberToStr'>>, 'NVL2': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Nvl2'>>, 'OPEN_J_S_O_N': <bound method Func.from_arg_list of <class 'sqlglot.expressions.OpenJSON'>>, 'PARAMETERIZED_AGG': <bound method Func.from_arg_list of <class 'sqlglot.expressions.ParameterizedAgg'>>, 'PARSE_JSON': <bound method Func.from_arg_list of <class 'sqlglot.expressions.ParseJSON'>>, 'JSON_PARSE': <bound method Func.from_arg_list of <class 'sqlglot.expressions.ParseJSON'>>, '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'>>, 'POSEXPLODE_OUTER': <bound method Func.from_arg_list of <class 'sqlglot.expressions.PosexplodeOuter'>>, 'POWER': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Pow'>>, 'POW': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Pow'>>, 'PREDICT': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Predict'>>, 'QUANTILE': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Quantile'>>, 'RANGE_N': <bound method Func.from_arg_list of <class 'sqlglot.expressions.RangeN'>>, 'READ_CSV': <bound method Func.from_arg_list of <class 'sqlglot.expressions.ReadCSV'>>, 'REDUCE': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Reduce'>>, 'REGEXP_EXTRACT': <bound method Func.from_arg_list of <class 'sqlglot.expressions.RegexpExtract'>>, 'REGEXP_I_LIKE': <bound method Func.from_arg_list of <class 'sqlglot.expressions.RegexpILike'>>, 'REGEXP_LIKE': <bound method Func.from_arg_list of <class 'sqlglot.expressions.RegexpLike'>>, 'REGEXP_REPLACE': <bound method Func.from_arg_list of <class 'sqlglot.expressions.RegexpReplace'>>, 'REGEXP_SPLIT': <bound method Func.from_arg_list of <class 'sqlglot.expressions.RegexpSplit'>>, 'REPEAT': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Repeat'>>, 'RIGHT': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Right'>>, 'ROUND': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Round'>>, 'ROW_NUMBER': <bound method Func.from_arg_list of <class 'sqlglot.expressions.RowNumber'>>, 'SHA': <bound method Func.from_arg_list of <class 'sqlglot.expressions.SHA'>>, 'SHA1': <bound method Func.from_arg_list of <class 'sqlglot.expressions.SHA'>>, 'SHA2': <bound method Func.from_arg_list of <class 'sqlglot.expressions.SHA2'>>, 'SAFE_CONCAT': <bound method Func.from_arg_list of <class 'sqlglot.expressions.SafeConcat'>>, 'SAFE_DIVIDE': <bound method Func.from_arg_list of <class 'sqlglot.expressions.SafeDivide'>>, 'SET_AGG': <bound method Func.from_arg_list of <class 'sqlglot.expressions.SetAgg'>>, 'SORT_ARRAY': <bound method Func.from_arg_list of <class 'sqlglot.expressions.SortArray'>>, 'SPLIT': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Split'>>, 'SQRT': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Sqrt'>>, 'STANDARD_HASH': <bound method Func.from_arg_list of <class 'sqlglot.expressions.StandardHash'>>, 'STAR_MAP': <bound method Func.from_arg_list of <class 'sqlglot.expressions.StarMap'>>, 'STARTS_WITH': <bound method Func.from_arg_list of <class 'sqlglot.expressions.StartsWith'>>, 'STARTSWITH': <bound method Func.from_arg_list of <class 'sqlglot.expressions.StartsWith'>>, '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': <bound method Func.from_arg_list of <class 'sqlglot.expressions.StrToDate'>>, 'STR_TO_MAP': <bound method Func.from_arg_list of <class 'sqlglot.expressions.StrToMap'>>, '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'>>, 'STUFF': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Stuff'>>, 'INSERT': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Stuff'>>, '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': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Timestamp'>>, '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'>>, 'TO_DAYS': <bound method Func.from_arg_list of <class 'sqlglot.expressions.ToDays'>>, 'TRANSFORM': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Transform'>>, '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'>>, 'XOR': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Xor'>>, 'YEAR': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Year'>>, 'GLOB': <function Parser.<lambda>>, 'LIKE': <function parse_like>, 'EDITDIST3': <bound method Func.from_arg_list of <class 'sqlglot.expressions.Levenshtein'>>}
TABLE_ALIAS_TOKENS = {<TokenType.ENUM16: 'ENUM16'>, <TokenType.TSTZRANGE: 'TSTZRANGE'>, <TokenType.ASC: 'ASC'>, <TokenType.INET: 'INET'>, <TokenType.INTERVAL: 'INTERVAL'>, <TokenType.JSONB: 'JSONB'>, <TokenType.INDEX: 'INDEX'>, <TokenType.INT4MULTIRANGE: 'INT4MULTIRANGE'>, <TokenType.DOUBLE: 'DOUBLE'>, <TokenType.USMALLINT: 'USMALLINT'>, <TokenType.BIGSERIAL: 'BIGSERIAL'>, <TokenType.YEAR: 'YEAR'>, <TokenType.PRAGMA: 'PRAGMA'>, <TokenType.DICTIONARY: 'DICTIONARY'>, <TokenType.BINARY: 'BINARY'>, <TokenType.ARRAY: 'ARRAY'>, <TokenType.NVARCHAR: 'NVARCHAR'>, <TokenType.DATETIME: 'DATETIME'>, <TokenType.BIT: 'BIT'>, <TokenType.PARTITION: 'PARTITION'>, <TokenType.DESC: 'DESC'>, <TokenType.UBIGINT: 'UBIGINT'>, <TokenType.KILL: 'KILL'>, <TokenType.ORDINALITY: 'ORDINALITY'>, <TokenType.TRUE: 'TRUE'>, <TokenType.DATABASE: 'DATABASE'>, <TokenType.SMALLMONEY: 'SMALLMONEY'>, <TokenType.NEXT: 'NEXT'>, <TokenType.MERGE: 'MERGE'>, <TokenType.INT: 'INT'>, <TokenType.MONEY: 'MONEY'>, <TokenType.CURRENT_TIMESTAMP: 'CURRENT_TIMESTAMP'>, <TokenType.EXISTS: 'EXISTS'>, <TokenType.DIV: 'DIV'>, <TokenType.SMALLINT: 'SMALLINT'>, <TokenType.IPADDRESS: 'IPADDRESS'>, <TokenType.TINYBLOB: 'TINYBLOB'>, <TokenType.CONSTRAINT: 'CONSTRAINT'>, <TokenType.TINYTEXT: 'TINYTEXT'>, <TokenType.DATEMULTIRANGE: 'DATEMULTIRANGE'>, <TokenType.DESCRIBE: 'DESCRIBE'>, <TokenType.FLOAT: 'FLOAT'>, <TokenType.OBJECT: 'OBJECT'>, <TokenType.MEDIUMBLOB: 'MEDIUMBLOB'>, <TokenType.SERIAL: 'SERIAL'>, <TokenType.FIXEDSTRING: 'FIXEDSTRING'>, <TokenType.ROWS: 'ROWS'>, <TokenType.IPPREFIX: 'IPPREFIX'>, <TokenType.UTINYINT: 'UTINYINT'>, <TokenType.VIEW: 'VIEW'>, <TokenType.CACHE: 'CACHE'>, <TokenType.VARCHAR: 'VARCHAR'>, <TokenType.FORMAT: 'FORMAT'>, <TokenType.LONGBLOB: 'LONGBLOB'>, <TokenType.NESTED: 'NESTED'>, <TokenType.UINT128: 'UINT128'>, <TokenType.INT4RANGE: 'INT4RANGE'>, <TokenType.INT8RANGE: 'INT8RANGE'>, <TokenType.VARIANT: 'VARIANT'>, <TokenType.PERCENT: 'PERCENT'>, <TokenType.TOP: 'TOP'>, <TokenType.TABLE: 'TABLE'>, <TokenType.UUID: 'UUID'>, <TokenType.MEDIUMTEXT: 'MEDIUMTEXT'>, <TokenType.AUTO_INCREMENT: 'AUTO_INCREMENT'>, <TokenType.REFERENCES: 'REFERENCES'>, <TokenType.EXECUTE: 'EXECUTE'>, <TokenType.BIGINT: 'BIGINT'>, <TokenType.SHOW: 'SHOW'>, <TokenType.JSON: 'JSON'>, <TokenType.BIGDECIMAL: 'BIGDECIMAL'>, <TokenType.OBJECT_IDENTIFIER: 'OBJECT_IDENTIFIER'>, <TokenType.UPDATE: 'UPDATE'>, <TokenType.NUMMULTIRANGE: 'NUMMULTIRANGE'>, <TokenType.UNIQUEIDENTIFIER: 'UNIQUEIDENTIFIER'>, <TokenType.SOME: 'SOME'>, <TokenType.UDECIMAL: 'UDECIMAL'>, <TokenType.ANY: 'ANY'>, <TokenType.FALSE: 'FALSE'>, <TokenType.MODEL: 'MODEL'>, <TokenType.SEMI: 'SEMI'>, <TokenType.SCHEMA: 'SCHEMA'>, <TokenType.TINYINT: 'TINYINT'>, <TokenType.TIMESTAMPLTZ: 'TIMESTAMPLTZ'>, <TokenType.RANGE: 'RANGE'>, <TokenType.TIMESTAMP_MS: 'TIMESTAMP_MS'>, <TokenType.IS: 'IS'>, <TokenType.CURRENT_DATETIME: 'CURRENT_DATETIME'>, <TokenType.LOAD: 'LOAD'>, <TokenType.USERDEFINED: 'USERDEFINED'>, <TokenType.INT8MULTIRANGE: 'INT8MULTIRANGE'>, <TokenType.LONGTEXT: 'LONGTEXT'>, <TokenType.BOOLEAN: 'BOOLEAN'>, <TokenType.DATERANGE: 'DATERANGE'>, <TokenType.CHAR: 'CHAR'>, <TokenType.PSEUDO_TYPE: 'PSEUDO_TYPE'>, <TokenType.HLLSKETCH: 'HLLSKETCH'>, <TokenType.CURRENT_USER: 'CURRENT_USER'>, <TokenType.CURRENT_TIME: 'CURRENT_TIME'>, <TokenType.COMMENT: 'COMMENT'>, <TokenType.PIVOT: 'PIVOT'>, <TokenType.TIMESTAMP: 'TIMESTAMP'>, <TokenType.TEXT: 'TEXT'>, <TokenType.TIMESTAMP_NS: 'TIMESTAMP_NS'>, <TokenType.UNIQUE: 'UNIQUE'>, <TokenType.MAP: 'MAP'>, <TokenType.DELETE: 'DELETE'>, <TokenType.IMAGE: 'IMAGE'>, <TokenType.COLUMN: 'COLUMN'>, <TokenType.ESCAPE: 'ESCAPE'>, <TokenType.KEEP: 'KEEP'>, <TokenType.TIMESTAMPTZ: 'TIMESTAMPTZ'>, <TokenType.SUPER: 'SUPER'>, <TokenType.XML: 'XML'>, <TokenType.ENUM8: 'ENUM8'>, <TokenType.TSTZMULTIRANGE: 'TSTZMULTIRANGE'>, <TokenType.ROWVERSION: 'ROWVERSION'>, <TokenType.ANTI: 'ANTI'>, <TokenType.HSTORE: 'HSTORE'>, <TokenType.TSMULTIRANGE: 'TSMULTIRANGE'>, <TokenType.TIMETZ: 'TIMETZ'>, <TokenType.TIMESTAMP_S: 'TIMESTAMP_S'>, <TokenType.FUNCTION: 'FUNCTION'>, <TokenType.TSRANGE: 'TSRANGE'>, <TokenType.TEMPORARY: 'TEMPORARY'>, <TokenType.BEGIN: 'BEGIN'>, <TokenType.OVERWRITE: 'OVERWRITE'>, <TokenType.FILTER: 'FILTER'>, <TokenType.UINT: 'UINT'>, <TokenType.DATE: 'DATE'>, <TokenType.CASE: 'CASE'>, <TokenType.GEOMETRY: 'GEOMETRY'>, <TokenType.TIME: 'TIME'>, <TokenType.ENUM: 'ENUM'>, <TokenType.LOWCARDINALITY: 'LOWCARDINALITY'>, <TokenType.UNPIVOT: 'UNPIVOT'>, <TokenType.UMEDIUMINT: 'UMEDIUMINT'>, <TokenType.NUMRANGE: 'NUMRANGE'>, <TokenType.INT128: 'INT128'>, <TokenType.NULL: 'NULL'>, <TokenType.END: 'END'>, <TokenType.FIRST: 'FIRST'>, <TokenType.DECIMAL: 'DECIMAL'>, <TokenType.DATETIME64: 'DATETIME64'>, <TokenType.SET: 'SET'>, <TokenType.ALL: 'ALL'>, <TokenType.SMALLSERIAL: 'SMALLSERIAL'>, <TokenType.NCHAR: 'NCHAR'>, <TokenType.MEDIUMINT: 'MEDIUMINT'>, <TokenType.DEFAULT: 'DEFAULT'>, <TokenType.COLLATE: 'COLLATE'>, <TokenType.UNKNOWN: 'UNKNOWN'>, <TokenType.OVERLAPS: 'OVERLAPS'>, <TokenType.UINT256: 'UINT256'>, <TokenType.SETTINGS: 'SETTINGS'>, <TokenType.COMMIT: 'COMMIT'>, <TokenType.CURRENT_DATE: 'CURRENT_DATE'>, <TokenType.ISNULL: 'ISNULL'>, <TokenType.ROW: 'ROW'>, <TokenType.INT256: 'INT256'>, <TokenType.NULLABLE: 'NULLABLE'>, <TokenType.VAR: 'VAR'>, <TokenType.VOLATILE: 'VOLATILE'>, <TokenType.VARBINARY: 'VARBINARY'>, <TokenType.COMMAND: 'COMMAND'>, <TokenType.STRUCT: 'STRUCT'>, <TokenType.GEOGRAPHY: 'GEOGRAPHY'>, <TokenType.PROCEDURE: 'PROCEDURE'>}
TOKENIZER_CLASS: Type[sqlglot.tokens.Tokenizer] = <class 'SQLite.Tokenizer'>
SHOW_TRIE: Dict = {}
SET_TRIE: Dict = {'GLOBAL': {0: True}, 'LOCAL': {0: True}, 'SESSION': {0: True}, 'TRANSACTION': {0: True}}
FORMAT_TRIE: Dict = {}
TIME_TRIE: Dict = {}

##### Inherited Members

sqlglot.parser.Parser
  Parser
  NO_PAREN_FUNCTIONS
  STRUCT_TYPE_TOKENS
  NESTED_TYPE_TOKENS
  ENUM_TYPE_TOKENS
  TYPE_TOKENS
  SIGNED_TO_UNSIGNED_TYPE_TOKEN
  SUBQUERY_PREDICATES
  RESERVED_KEYWORDS
  DB_CREATABLES
  CREATABLES
  ID_VAR_TOKENS
  INTERVAL_VARS
  COMMENT_TABLE_ALIAS_TOKENS
  UPDATE_ALIAS_TOKENS
  TRIM_TYPES
  FUNC_TOKENS
  CONJUNCTION
  EQUALITY
  COMPARISON
  BITWISE
  TERM
  FACTOR
  TIMES
  TIMESTAMPS
  SET_OPERATIONS
  JOIN_METHODS
  JOIN_SIDES
  JOIN_KINDS
  JOIN_HINTS
  LAMBDAS
  COLUMN_OPERATORS
  EXPRESSION_PARSERS
  STATEMENT_PARSERS
  UNARY_PARSERS
  PRIMARY_PARSERS
  PLACEHOLDER_PARSERS
  RANGE_PARSERS
  PROPERTY_PARSERS
  CONSTRAINT_PARSERS
  ALTER_PARSERS
  SCHEMA_UNNAMED_CONSTRAINTS
  NO_PAREN_FUNCTION_PARSERS
  INVALID_FUNC_NAME_TOKENS
  FUNCTIONS_WITH_ALIASED_ARGS
  FUNCTION_PARSERS
  QUERY_MODIFIER_PARSERS
  SET_PARSERS
  SHOW_PARSERS
  TYPE_LITERAL_PARSERS
  MODIFIABLES
  DDL_SELECT_TOKENS
  PRE_VOLATILE_TOKENS
  TRANSACTION_KIND
  TRANSACTION_CHARACTERISTICS
  INSERT_ALTERNATIVES
  CLONE_KEYWORDS
  CLONE_KINDS
  OPCLASS_FOLLOW_KEYWORDS
  TABLE_INDEX_HINT_TOKENS
  WINDOW_ALIAS_TOKENS
  WINDOW_BEFORE_PAREN_TOKENS
  WINDOW_SIDES
  FETCH_TOKENS
  ADD_CONSTRAINT_TOKENS
  DISTINCT_TOKENS
  NULL_TOKENS
  UNNEST_OFFSET_ALIAS_TOKENS
  STRICT_CAST
  CONCAT_NULL_OUTPUTS_STRING
  PREFIXED_PIVOT_COLUMNS
  IDENTIFY_PIVOT_STRINGS
  LOG_BASE_FIRST
  LOG_DEFAULTS_TO_LN
  ALTER_TABLE_ADD_COLUMN_KEYWORD
  TABLESAMPLE_CSV
  SET_REQUIRES_ASSIGNMENT_DELIMITER
  TRIM_PATTERN_FIRST
  INDEX_OFFSET
  UNNEST_COLUMN_ONLY
  ALIAS_POST_TABLESAMPLE
  STRICT_STRING_CONCAT
  SUPPORTS_USER_DEFINED_TYPES
  NORMALIZE_FUNCTIONS
  NULL_ORDERING
  FORMAT_MAPPING
  TIME_MAPPING
  error_level
  error_message_context
  max_errors
  reset
  parse
  parse_into
  check_errors
  raise_error
  expression
  validate_expression
  errors
  sql

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

     80    class Generator(generator.Generator):
     81        JOIN_HINTS = False
     82        TABLE_HINTS = False
     83        QUERY_HINTS = False
     84        NVL2_SUPPORTED = False
     85
     86        TYPE_MAPPING = {
     87            **generator.Generator.TYPE_MAPPING,
     88            exp.DataType.Type.BOOLEAN: "INTEGER",
     89            exp.DataType.Type.TINYINT: "INTEGER",
     90            exp.DataType.Type.SMALLINT: "INTEGER",
     91            exp.DataType.Type.INT: "INTEGER",
     92            exp.DataType.Type.BIGINT: "INTEGER",
     93            exp.DataType.Type.FLOAT: "REAL",
     94            exp.DataType.Type.DOUBLE: "REAL",
     95            exp.DataType.Type.DECIMAL: "REAL",
     96            exp.DataType.Type.CHAR: "TEXT",
     97            exp.DataType.Type.NCHAR: "TEXT",
     98            exp.DataType.Type.VARCHAR: "TEXT",
     99            exp.DataType.Type.NVARCHAR: "TEXT",
    100            exp.DataType.Type.BINARY: "BLOB",
    101            exp.DataType.Type.VARBINARY: "BLOB",
    102        }
    103
    104        TOKEN_MAPPING = {
    105            TokenType.AUTO_INCREMENT: "AUTOINCREMENT",
    106        }
    107
    108        TRANSFORMS = {
    109            **generator.Generator.TRANSFORMS,
    110            exp.AnyValue: any_value_to_max_sql,
    111            exp.Concat: concat_to_dpipe_sql,
    112            exp.CountIf: count_if_to_sum,
    113            exp.Create: transforms.preprocess([_transform_create]),
    114            exp.CurrentDate: lambda *_: "CURRENT_DATE",
    115            exp.CurrentTime: lambda *_: "CURRENT_TIME",
    116            exp.CurrentTimestamp: lambda *_: "CURRENT_TIMESTAMP",
    117            exp.DateAdd: _date_add_sql,
    118            exp.DateStrToDate: lambda self, e: self.sql(e, "this"),
    119            exp.ILike: no_ilike_sql,
    120            exp.JSONExtract: arrow_json_extract_sql,
    121            exp.JSONExtractScalar: arrow_json_extract_scalar_sql,
    122            exp.JSONBExtract: arrow_json_extract_sql,
    123            exp.JSONBExtractScalar: arrow_json_extract_scalar_sql,
    124            exp.Levenshtein: rename_func("EDITDIST3"),
    125            exp.LogicalOr: rename_func("MAX"),
    126            exp.LogicalAnd: rename_func("MIN"),
    127            exp.Pivot: no_pivot_sql,
    128            exp.SafeConcat: concat_to_dpipe_sql,
    129            exp.Select: transforms.preprocess(
    130                [
    131                    transforms.eliminate_distinct_on,
    132                    transforms.eliminate_qualify,
    133                    transforms.eliminate_semi_and_anti_joins,
    134                ]
    135            ),
    136            exp.TableSample: no_tablesample_sql,
    137            exp.TimeStrToTime: lambda self, e: self.sql(e, "this"),
    138            exp.TryCast: no_trycast_sql,
    139        }
    140
    141        PROPERTIES_LOCATION = {
    142            k: exp.Properties.Location.UNSUPPORTED
    143            for k, v in generator.Generator.PROPERTIES_LOCATION.items()
    144        }
    145
    146        LIMIT_FETCH = "LIMIT"
    147
    148        def cast_sql(self, expression: exp.Cast, safe_prefix: t.Optional[str] = None) -> str:
    149            if expression.is_type("date"):
    150                return self.func("DATE", expression.this)
    151
    152            return super().cast_sql(expression)
    153
    154        def datediff_sql(self, expression: exp.DateDiff) -> str:
    155            unit = expression.args.get("unit")
    156            unit = unit.name.upper() if unit else "DAY"
    157
    158            sql = f"(JULIANDAY({self.sql(expression, 'this')}) - JULIANDAY({self.sql(expression, 'expression')}))"
    159
    160            if unit == "MONTH":
    161                sql = f"{sql} / 30.0"
    162            elif unit == "YEAR":
    163                sql = f"{sql} / 365.0"
    164            elif unit == "HOUR":
    165                sql = f"{sql} * 24.0"
    166            elif unit == "MINUTE":
    167                sql = f"{sql} * 1440.0"
    168            elif unit == "SECOND":
    169                sql = f"{sql} * 86400.0"
    170            elif unit == "MILLISECOND":
    171                sql = f"{sql} * 86400000.0"
    172            elif unit == "MICROSECOND":
    173                sql = f"{sql} * 86400000000.0"
    174            elif unit == "NANOSECOND":
    175                sql = f"{sql} * 8640000000000.0"
    176            else:
    177                self.unsupported("DATEDIFF unsupported for '{unit}'.")
    178
    179            return f"CAST({sql} AS INTEGER)"
    180
    181        # https://www.sqlite.org/lang_aggfunc.html#group_concat
    182        def groupconcat_sql(self, expression: exp.GroupConcat) -> str:
    183            this = expression.this
    184            distinct = expression.find(exp.Distinct)
    185
    186            if distinct:
    187                this = distinct.expressions[0]
    188                distinct_sql = "DISTINCT "
    189            else:
    190                distinct_sql = ""
    191
    192            if isinstance(expression.this, exp.Order):
    193                self.unsupported("SQLite GROUP_CONCAT doesn't support ORDER BY.")
    194                if expression.this.this and not distinct:
    195                    this = expression.this.this
    196
    197            separator = expression.args.get("separator")
    198            return f"GROUP_CONCAT({distinct_sql}{self.format_args(this, separator)})"
    199
    200        def least_sql(self, expression: exp.Least) -> str:
    201            if len(expression.expressions) > 1:
    202                return rename_func("MIN")(self, expression)
    203
    204            return self.sql(expression, "this")
    205
    206        def transaction_sql(self, expression: exp.Transaction) -> str:
    207            this = expression.this
    208            this = f" {this}" if this else ""
    209            return f"BEGIN{this} TRANSACTION"

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

JOIN_HINTS = False
TABLE_HINTS = False
QUERY_HINTS = False
NVL2_SUPPORTED = False
TYPE_MAPPING = {<Type.NCHAR: 'NCHAR'>: 'TEXT', <Type.NVARCHAR: 'NVARCHAR'>: 'TEXT', <Type.MEDIUMTEXT: 'MEDIUMTEXT'>: 'TEXT', <Type.LONGTEXT: 'LONGTEXT'>: 'TEXT', <Type.TINYTEXT: 'TINYTEXT'>: 'TEXT', <Type.MEDIUMBLOB: 'MEDIUMBLOB'>: 'BLOB', <Type.LONGBLOB: 'LONGBLOB'>: 'BLOB', <Type.TINYBLOB: 'TINYBLOB'>: 'BLOB', <Type.INET: 'INET'>: 'INET', <Type.BOOLEAN: 'BOOLEAN'>: 'INTEGER', <Type.TINYINT: 'TINYINT'>: 'INTEGER', <Type.SMALLINT: 'SMALLINT'>: 'INTEGER', <Type.INT: 'INT'>: 'INTEGER', <Type.BIGINT: 'BIGINT'>: 'INTEGER', <Type.FLOAT: 'FLOAT'>: 'REAL', <Type.DOUBLE: 'DOUBLE'>: 'REAL', <Type.DECIMAL: 'DECIMAL'>: 'REAL', <Type.CHAR: 'CHAR'>: 'TEXT', <Type.VARCHAR: 'VARCHAR'>: 'TEXT', <Type.BINARY: 'BINARY'>: 'BLOB', <Type.VARBINARY: 'VARBINARY'>: 'BLOB'}
TOKEN_MAPPING = {<TokenType.AUTO_INCREMENT: 'AUTO_INCREMENT'>: 'AUTOINCREMENT'}
TRANSFORMS = {<class 'sqlglot.expressions.DateAdd'>: <function _date_add_sql>, <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.ClusteredColumnConstraint'>: <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.HeapProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.InlineLengthColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.InputModelProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.IntervalSpan'>: <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.NonClusteredColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.NotForReplicationColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.OnCommitProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.OnProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.OnUpdateColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.OutputModelProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.PathColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.RemoteWithConnectionModelProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.ReturnsProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.SampleProperty'>: <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.TransformModelProperty'>: <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.AnyValue'>: <function any_value_to_max_sql>, <class 'sqlglot.expressions.Concat'>: <function concat_to_dpipe_sql>, <class 'sqlglot.expressions.CountIf'>: <function count_if_to_sum>, <class 'sqlglot.expressions.Create'>: <function preprocess.<locals>._to_sql>, <class 'sqlglot.expressions.CurrentDate'>: <function SQLite.Generator.<lambda>>, <class 'sqlglot.expressions.CurrentTime'>: <function SQLite.Generator.<lambda>>, <class 'sqlglot.expressions.CurrentTimestamp'>: <function SQLite.Generator.<lambda>>, <class 'sqlglot.expressions.DateStrToDate'>: <function SQLite.Generator.<lambda>>, <class 'sqlglot.expressions.ILike'>: <function no_ilike_sql>, <class 'sqlglot.expressions.JSONExtract'>: <function arrow_json_extract_sql>, <class 'sqlglot.expressions.JSONExtractScalar'>: <function arrow_json_extract_scalar_sql>, <class 'sqlglot.expressions.JSONBExtract'>: <function arrow_json_extract_sql>, <class 'sqlglot.expressions.JSONBExtractScalar'>: <function arrow_json_extract_scalar_sql>, <class 'sqlglot.expressions.Levenshtein'>: <function rename_func.<locals>.<lambda>>, <class 'sqlglot.expressions.LogicalOr'>: <function rename_func.<locals>.<lambda>>, <class 'sqlglot.expressions.LogicalAnd'>: <function rename_func.<locals>.<lambda>>, <class 'sqlglot.expressions.Pivot'>: <function no_pivot_sql>, <class 'sqlglot.expressions.SafeConcat'>: <function concat_to_dpipe_sql>, <class 'sqlglot.expressions.Select'>: <function preprocess.<locals>._to_sql>, <class 'sqlglot.expressions.TableSample'>: <function no_tablesample_sql>, <class 'sqlglot.expressions.TimeStrToTime'>: <function SQLite.Generator.<lambda>>, <class 'sqlglot.expressions.TryCast'>: <function no_trycast_sql>}
PROPERTIES_LOCATION = {<class 'sqlglot.expressions.AlgorithmProperty'>: <Location.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.AutoIncrementProperty'>: <Location.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.BlockCompressionProperty'>: <Location.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.CharacterSetProperty'>: <Location.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.ChecksumProperty'>: <Location.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.CollateProperty'>: <Location.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.CopyGrantsProperty'>: <Location.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.Cluster'>: <Location.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.ClusteredByProperty'>: <Location.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.DataBlocksizeProperty'>: <Location.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.DefinerProperty'>: <Location.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.DictRange'>: <Location.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.DictProperty'>: <Location.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.DistKeyProperty'>: <Location.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.DistStyleProperty'>: <Location.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.EngineProperty'>: <Location.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.ExecuteAsProperty'>: <Location.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.ExternalProperty'>: <Location.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.FallbackProperty'>: <Location.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.FileFormatProperty'>: <Location.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.FreespaceProperty'>: <Location.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.HeapProperty'>: <Location.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.InputModelProperty'>: <Location.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.IsolatedLoadingProperty'>: <Location.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.JournalProperty'>: <Location.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.LanguageProperty'>: <Location.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.LikeProperty'>: <Location.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.LocationProperty'>: <Location.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.LockingProperty'>: <Location.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.LogProperty'>: <Location.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.MaterializedProperty'>: <Location.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.MergeBlockRatioProperty'>: <Location.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.NoPrimaryIndexProperty'>: <Location.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.OnProperty'>: <Location.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.OnCommitProperty'>: <Location.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.Order'>: <Location.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.OutputModelProperty'>: <Location.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.PartitionedByProperty'>: <Location.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.PrimaryKey'>: <Location.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.Property'>: <Location.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.RemoteWithConnectionModelProperty'>: <Location.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.ReturnsProperty'>: <Location.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.RowFormatProperty'>: <Location.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.RowFormatDelimitedProperty'>: <Location.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.RowFormatSerdeProperty'>: <Location.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.SampleProperty'>: <Location.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.SchemaCommentProperty'>: <Location.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.SerdeProperties'>: <Location.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.Set'>: <Location.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.SettingsProperty'>: <Location.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.SetProperty'>: <Location.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.SortKeyProperty'>: <Location.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.SqlSecurityProperty'>: <Location.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.StabilityProperty'>: <Location.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.TemporaryProperty'>: <Location.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.ToTableProperty'>: <Location.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.TransientProperty'>: <Location.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.TransformModelProperty'>: <Location.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.MergeTreeTTL'>: <Location.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.VolatileProperty'>: <Location.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.WithDataProperty'>: <Location.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.WithJournalTableProperty'>: <Location.UNSUPPORTED: 'UNSUPPORTED'>}
LIMIT_FETCH = 'LIMIT'
def cast_sql( self, expression: sqlglot.expressions.Cast, safe_prefix: Optional[str] = None) -> str: View Source

    148        def cast_sql(self, expression: exp.Cast, safe_prefix: t.Optional[str] = None) -> str:
    149            if expression.is_type("date"):
    150                return self.func("DATE", expression.this)
    151
    152            return super().cast_sql(expression)

def datediff_sql(self, expression: sqlglot.expressions.DateDiff) -> str: View Source

    154        def datediff_sql(self, expression: exp.DateDiff) -> str:
    155            unit = expression.args.get("unit")
    156            unit = unit.name.upper() if unit else "DAY"
    157
    158            sql = f"(JULIANDAY({self.sql(expression, 'this')}) - JULIANDAY({self.sql(expression, 'expression')}))"
    159
    160            if unit == "MONTH":
    161                sql = f"{sql} / 30.0"
    162            elif unit == "YEAR":
    163                sql = f"{sql} / 365.0"
    164            elif unit == "HOUR":
    165                sql = f"{sql} * 24.0"
    166            elif unit == "MINUTE":
    167                sql = f"{sql} * 1440.0"
    168            elif unit == "SECOND":
    169                sql = f"{sql} * 86400.0"
    170            elif unit == "MILLISECOND":
    171                sql = f"{sql} * 86400000.0"
    172            elif unit == "MICROSECOND":
    173                sql = f"{sql} * 86400000000.0"
    174            elif unit == "NANOSECOND":
    175                sql = f"{sql} * 8640000000000.0"
    176            else:
    177                self.unsupported("DATEDIFF unsupported for '{unit}'.")
    178
    179            return f"CAST({sql} AS INTEGER)"

def groupconcat_sql(self, expression: sqlglot.expressions.GroupConcat) -> str: View Source

    182        def groupconcat_sql(self, expression: exp.GroupConcat) -> str:
    183            this = expression.this
    184            distinct = expression.find(exp.Distinct)
    185
    186            if distinct:
    187                this = distinct.expressions[0]
    188                distinct_sql = "DISTINCT "
    189            else:
    190                distinct_sql = ""
    191
    192            if isinstance(expression.this, exp.Order):
    193                self.unsupported("SQLite GROUP_CONCAT doesn't support ORDER BY.")
    194                if expression.this.this and not distinct:
    195                    this = expression.this.this
    196
    197            separator = expression.args.get("separator")
    198            return f"GROUP_CONCAT({distinct_sql}{self.format_args(this, separator)})"

def least_sql(self, expression: sqlglot.expressions.Least) -> str: View Source

    200        def least_sql(self, expression: exp.Least) -> str:
    201            if len(expression.expressions) > 1:
    202                return rename_func("MIN")(self, expression)
    203
    204            return self.sql(expression, "this")

def transaction_sql(self, expression: sqlglot.expressions.Transaction) -> str: View Source

    206        def transaction_sql(self, expression: exp.Transaction) -> str:
    207            this = expression.this
    208            this = f" {this}" if this else ""
    209            return f"BEGIN{this} TRANSACTION"

SELECT_KINDS: Tuple[str, ...] = ()
INVERSE_TIME_MAPPING: Dict[str, str] = {}
INVERSE_TIME_TRIE: Dict = {}
INVERSE_ESCAPE_SEQUENCES: Dict[str, str] = {}
@classmethod
def can_identify(text: str, identify: str | bool = 'safe') -> bool: View Source

    279    @classmethod
    280    def can_identify(cls, text: str, identify: str | bool = "safe") -> bool:
    281        """Checks if text can be identified given an identify option.
    282
    283        Args:
    284            text: The text to check.
    285            identify:
    286                "always" or `True`: Always returns true.
    287                "safe": True if the identifier is case-insensitive.
    288
    289        Returns:
    290            Whether or not the given text can be identified.
    291        """
    292        if identify is True or identify == "always":
    293            return True
    294
    295        if identify == "safe":
    296            return not cls.case_sensitive(text)
    297
    298        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 = '"'
TOKENIZER_CLASS = <class 'SQLite.Tokenizer'>
BIT_START: Optional[str] = None
BIT_END: Optional[str] = None
HEX_START: Optional[str] = "x'"
HEX_END: Optional[str] = "'"
BYTE_START: Optional[str] = None
BYTE_END: Optional[str] = None

##### Inherited Members

sqlglot.generator.Generator
  Generator
  LOG_BASE_FIRST
  NULL_ORDERING_SUPPORTED
  LOCKING_READS_SUPPORTED
  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
  LIMIT_ONLY_LITERALS
  RENAME_TABLE_WITH_DB
  GROUPINGS_SEP
  INDEX_ON
  QUERY_HINT_SEP
  IS_BOOL_ALLOWED
  DUPLICATE_KEY_UPDATE_WITH_SET
  LIMIT_IS_TOP
  RETURNING_END
  COLUMN_JOIN_MARKS_SUPPORTED
  EXTRACT_ALLOWS_QUOTES
  TZ_TO_WITH_TIME_ZONE
  VALUES_AS_TABLE
  ALTER_TABLE_ADD_COLUMN_KEYWORD
  UNNEST_WITH_ORDINALITY
  AGGREGATE_FILTER_SUPPORTED
  SEMI_ANTI_JOIN_WITH_SIDE
  SUPPORTS_PARAMETERS
  COMPUTED_COLUMN_WITH_TYPE
  SUPPORTS_TABLE_COPY
  TABLESAMPLE_REQUIRES_PARENS
  COLLATE_IS_FUNC
  DATA_TYPE_SPECIFIERS_ALLOWED
  STAR_MAPPING
  TIME_PART_SINGULARS
  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
  computedcolumnconstraint_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
  datatypeparam_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_name
  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
  kill_sql
  pseudotype_sql
  objectidentifier_sql
  onconflict_sql
  returning_sql
  rowformatdelimitedproperty_sql
  withtablehint_sql
  indextablehint_sql
  table_sql
  tablesample_sql
  pivot_sql
  version_sql
  tuple_sql
  update_sql
  values_sql
  var_sql
  into_sql
  from_sql
  group_sql
  having_sql
  connect_sql
  prior_sql
  join_sql
  lambda_sql
  lateral_sql
  limit_sql
  offset_sql
  setitem_sql
  set_sql
  pragma_sql
  lock_sql
  literal_sql
  escape_str
  loaddata_sql
  null_sql
  boolean_sql
  order_sql
  cluster_sql
  distribute_sql
  sort_sql
  ordered_sql
  matchrecognize_sql
  query_modifiers
  offset_limit_modifiers
  after_having_modifiers
  after_limit_modifiers
  select_sql
  schema_sql
  schema_columns_sql
  star_sql
  parameter_sql
  sessionparameter_sql
  placeholder_sql
  subquery_sql
  qualify_sql
  union_sql
  union_op
  unnest_sql
  where_sql
  window_sql
  partition_by_sql
  windowspec_sql
  withingroup_sql
  between_sql
  bracket_sql
  safebracket_sql
  all_sql
  any_sql
  exists_sql
  case_sql
  constraint_sql
  nextvaluefor_sql
  extract_sql
  trim_sql
  safeconcat_sql
  check_sql
  foreignkey_sql
  primarykey_sql
  if_sql
  matchagainst_sql
  jsonkeyvalue_sql
  formatjson_sql
  jsonobject_sql
  jsonarray_sql
  jsonarrayagg_sql
  jsoncolumndef_sql
  jsonschema_sql
  jsontable_sql
  openjsoncolumndef_sql
  openjson_sql
  in_sql
  in_unnest_op
  interval_sql
  return_sql
  reference_sql
  anonymous_sql
  paren_sql
  neg_sql
  not_sql
  alias_sql
  aliases_sql
  attimezone_sql
  add_sql
  and_sql
  xor_sql
  connector_sql
  bitwiseand_sql
  bitwiseleftshift_sql
  bitwisenot_sql
  bitwiseor_sql
  bitwiserightshift_sql
  bitwisexor_sql
  currentdate_sql
  collate_sql
  command_sql
  comment_sql
  mergetreettlaction_sql
  mergetreettl_sql
  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
  log_sql
  use_sql
  binary
  function_fallback_sql
  func
  format_args
  text_width
  format_time
  expressions
  op_expressions
  naked_property
  set_operation
  tag_sql
  token_sql
  userdefinedfunction_sql
  joinhint_sql
  kwarg_sql
  when_sql
  merge_sql
  tochar_sql
  dictproperty_sql
  dictrange_sql
  dictsubproperty_sql
  oncluster_sql
  clusteredbyproperty_sql
  anyvalue_sql
  querytransform_sql
  indexconstraintoption_sql
  indexcolumnconstraint_sql
  nvl2_sql
  comprehension_sql
  columnprefix_sql
  opclass_sql
  predict_sql