sqlglot.dialects.sqlite API documentation

Edit on GitHub

# sqlglot.dialects.sqlite

View Source

      1from __future__ import annotations
      2
      3from sqlglot import exp, generator, parser, tokens, transforms
      4from sqlglot.dialects.dialect import (
      5    Dialect,
      6    arrow_json_extract_scalar_sql,
      7    arrow_json_extract_sql,
      8    count_if_to_sum,
      9    no_ilike_sql,
     10    no_tablesample_sql,
     11    no_trycast_sql,
     12    rename_func,
     13)
     14from sqlglot.tokens import TokenType
     15
     16
     17def _date_add_sql(self, expression):
     18    modifier = expression.expression
     19    modifier = modifier.name if modifier.is_string else self.sql(modifier)
     20    unit = expression.args.get("unit")
     21    modifier = f"'{modifier} {unit.name}'" if unit else f"'{modifier}'"
     22    return self.func("DATE", expression.this, modifier)
     23
     24
     25class SQLite(Dialect):
     26    class Tokenizer(tokens.Tokenizer):
     27        IDENTIFIERS = ['"', ("[", "]"), "`"]
     28        HEX_STRINGS = [("x'", "'"), ("X'", "'"), ("0x", ""), ("0X", "")]
     29
     30        KEYWORDS = {
     31            **tokens.Tokenizer.KEYWORDS,
     32        }
     33
     34    class Parser(parser.Parser):
     35        FUNCTIONS = {
     36            **parser.Parser.FUNCTIONS,  # type: ignore
     37            "EDITDIST3": exp.Levenshtein.from_arg_list,
     38        }
     39
     40    class Generator(generator.Generator):
     41        JOIN_HINTS = False
     42        TABLE_HINTS = False
     43
     44        TYPE_MAPPING = {
     45            **generator.Generator.TYPE_MAPPING,  # type: ignore
     46            exp.DataType.Type.BOOLEAN: "INTEGER",
     47            exp.DataType.Type.TINYINT: "INTEGER",
     48            exp.DataType.Type.SMALLINT: "INTEGER",
     49            exp.DataType.Type.INT: "INTEGER",
     50            exp.DataType.Type.BIGINT: "INTEGER",
     51            exp.DataType.Type.FLOAT: "REAL",
     52            exp.DataType.Type.DOUBLE: "REAL",
     53            exp.DataType.Type.DECIMAL: "REAL",
     54            exp.DataType.Type.CHAR: "TEXT",
     55            exp.DataType.Type.NCHAR: "TEXT",
     56            exp.DataType.Type.VARCHAR: "TEXT",
     57            exp.DataType.Type.NVARCHAR: "TEXT",
     58            exp.DataType.Type.BINARY: "BLOB",
     59            exp.DataType.Type.VARBINARY: "BLOB",
     60        }
     61
     62        TOKEN_MAPPING = {
     63            TokenType.AUTO_INCREMENT: "AUTOINCREMENT",
     64        }
     65
     66        TRANSFORMS = {
     67            **generator.Generator.TRANSFORMS,  # type: ignore
     68            exp.CountIf: count_if_to_sum,
     69            exp.CurrentDate: lambda *_: "CURRENT_DATE",
     70            exp.CurrentTime: lambda *_: "CURRENT_TIME",
     71            exp.CurrentTimestamp: lambda *_: "CURRENT_TIMESTAMP",
     72            exp.DateAdd: _date_add_sql,
     73            exp.DateStrToDate: lambda self, e: self.sql(e, "this"),
     74            exp.ILike: no_ilike_sql,
     75            exp.JSONExtract: arrow_json_extract_sql,
     76            exp.JSONExtractScalar: arrow_json_extract_scalar_sql,
     77            exp.JSONBExtract: arrow_json_extract_sql,
     78            exp.JSONBExtractScalar: arrow_json_extract_scalar_sql,
     79            exp.Levenshtein: rename_func("EDITDIST3"),
     80            exp.LogicalOr: rename_func("MAX"),
     81            exp.LogicalAnd: rename_func("MIN"),
     82            exp.Select: transforms.preprocess(
     83                [transforms.eliminate_distinct_on, transforms.eliminate_qualify]
     84            ),
     85            exp.TableSample: no_tablesample_sql,
     86            exp.TimeStrToTime: lambda self, e: self.sql(e, "this"),
     87            exp.TryCast: no_trycast_sql,
     88        }
     89
     90        PROPERTIES_LOCATION = {
     91            k: exp.Properties.Location.UNSUPPORTED
     92            for k, v in generator.Generator.PROPERTIES_LOCATION.items()
     93        }
     94
     95        LIMIT_FETCH = "LIMIT"
     96
     97        def cast_sql(self, expression: exp.Cast) -> str:
     98            if expression.to.this == exp.DataType.Type.DATE:
     99                return self.func("DATE", expression.this)
    100
    101            return super().cast_sql(expression)
    102
    103        def datediff_sql(self, expression: exp.DateDiff) -> str:
    104            unit = expression.args.get("unit")
    105            unit = unit.name.upper() if unit else "DAY"
    106
    107            sql = f"(JULIANDAY({self.sql(expression, 'this')}) - JULIANDAY({self.sql(expression, 'expression')}))"
    108
    109            if unit == "MONTH":
    110                sql = f"{sql} / 30.0"
    111            elif unit == "YEAR":
    112                sql = f"{sql} / 365.0"
    113            elif unit == "HOUR":
    114                sql = f"{sql} * 24.0"
    115            elif unit == "MINUTE":
    116                sql = f"{sql} * 1440.0"
    117            elif unit == "SECOND":
    118                sql = f"{sql} * 86400.0"
    119            elif unit == "MILLISECOND":
    120                sql = f"{sql} * 86400000.0"
    121            elif unit == "MICROSECOND":
    122                sql = f"{sql} * 86400000000.0"
    123            elif unit == "NANOSECOND":
    124                sql = f"{sql} * 8640000000000.0"
    125            else:
    126                self.unsupported("DATEDIFF unsupported for '{unit}'.")
    127
    128            return f"CAST({sql} AS INTEGER)"
    129
    130        # https://www.sqlite.org/lang_aggfunc.html#group_concat
    131        def groupconcat_sql(self, expression):
    132            this = expression.this
    133            distinct = expression.find(exp.Distinct)
    134            if distinct:
    135                this = distinct.expressions[0]
    136                distinct = "DISTINCT "
    137
    138            if isinstance(expression.this, exp.Order):
    139                self.unsupported("SQLite GROUP_CONCAT doesn't support ORDER BY.")
    140                if expression.this.this and not distinct:
    141                    this = expression.this.this
    142
    143            separator = expression.args.get("separator")
    144            return f"GROUP_CONCAT({distinct or ''}{self.format_args(this, separator)})"
    145
    146        def least_sql(self, expression: exp.Least) -> str:
    147            if len(expression.expressions) > 1:
    148                return rename_func("MIN")(self, expression)
    149
    150            return self.expressions(expression)
    151
    152        def transaction_sql(self, expression: exp.Transaction) -> str:
    153            this = expression.this
    154            this = f" {this}" if this else ""
    155            return f"BEGIN{this} TRANSACTION"

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

     26class SQLite(Dialect):
     27    class Tokenizer(tokens.Tokenizer):
     28        IDENTIFIERS = ['"', ("[", "]"), "`"]
     29        HEX_STRINGS = [("x'", "'"), ("X'", "'"), ("0x", ""), ("0X", "")]
     30
     31        KEYWORDS = {
     32            **tokens.Tokenizer.KEYWORDS,
     33        }
     34
     35    class Parser(parser.Parser):
     36        FUNCTIONS = {
     37            **parser.Parser.FUNCTIONS,  # type: ignore
     38            "EDITDIST3": exp.Levenshtein.from_arg_list,
     39        }
     40
     41    class Generator(generator.Generator):
     42        JOIN_HINTS = False
     43        TABLE_HINTS = False
     44
     45        TYPE_MAPPING = {
     46            **generator.Generator.TYPE_MAPPING,  # type: ignore
     47            exp.DataType.Type.BOOLEAN: "INTEGER",
     48            exp.DataType.Type.TINYINT: "INTEGER",
     49            exp.DataType.Type.SMALLINT: "INTEGER",
     50            exp.DataType.Type.INT: "INTEGER",
     51            exp.DataType.Type.BIGINT: "INTEGER",
     52            exp.DataType.Type.FLOAT: "REAL",
     53            exp.DataType.Type.DOUBLE: "REAL",
     54            exp.DataType.Type.DECIMAL: "REAL",
     55            exp.DataType.Type.CHAR: "TEXT",
     56            exp.DataType.Type.NCHAR: "TEXT",
     57            exp.DataType.Type.VARCHAR: "TEXT",
     58            exp.DataType.Type.NVARCHAR: "TEXT",
     59            exp.DataType.Type.BINARY: "BLOB",
     60            exp.DataType.Type.VARBINARY: "BLOB",
     61        }
     62
     63        TOKEN_MAPPING = {
     64            TokenType.AUTO_INCREMENT: "AUTOINCREMENT",
     65        }
     66
     67        TRANSFORMS = {
     68            **generator.Generator.TRANSFORMS,  # type: ignore
     69            exp.CountIf: count_if_to_sum,
     70            exp.CurrentDate: lambda *_: "CURRENT_DATE",
     71            exp.CurrentTime: lambda *_: "CURRENT_TIME",
     72            exp.CurrentTimestamp: lambda *_: "CURRENT_TIMESTAMP",
     73            exp.DateAdd: _date_add_sql,
     74            exp.DateStrToDate: lambda self, e: self.sql(e, "this"),
     75            exp.ILike: no_ilike_sql,
     76            exp.JSONExtract: arrow_json_extract_sql,
     77            exp.JSONExtractScalar: arrow_json_extract_scalar_sql,
     78            exp.JSONBExtract: arrow_json_extract_sql,
     79            exp.JSONBExtractScalar: arrow_json_extract_scalar_sql,
     80            exp.Levenshtein: rename_func("EDITDIST3"),
     81            exp.LogicalOr: rename_func("MAX"),
     82            exp.LogicalAnd: rename_func("MIN"),
     83            exp.Select: transforms.preprocess(
     84                [transforms.eliminate_distinct_on, transforms.eliminate_qualify]
     85            ),
     86            exp.TableSample: no_tablesample_sql,
     87            exp.TimeStrToTime: lambda self, e: self.sql(e, "this"),
     88            exp.TryCast: no_trycast_sql,
     89        }
     90
     91        PROPERTIES_LOCATION = {
     92            k: exp.Properties.Location.UNSUPPORTED
     93            for k, v in generator.Generator.PROPERTIES_LOCATION.items()
     94        }
     95
     96        LIMIT_FETCH = "LIMIT"
     97
     98        def cast_sql(self, expression: exp.Cast) -> str:
     99            if expression.to.this == exp.DataType.Type.DATE:
    100                return self.func("DATE", expression.this)
    101
    102            return super().cast_sql(expression)
    103
    104        def datediff_sql(self, expression: exp.DateDiff) -> str:
    105            unit = expression.args.get("unit")
    106            unit = unit.name.upper() if unit else "DAY"
    107
    108            sql = f"(JULIANDAY({self.sql(expression, 'this')}) - JULIANDAY({self.sql(expression, 'expression')}))"
    109
    110            if unit == "MONTH":
    111                sql = f"{sql} / 30.0"
    112            elif unit == "YEAR":
    113                sql = f"{sql} / 365.0"
    114            elif unit == "HOUR":
    115                sql = f"{sql} * 24.0"
    116            elif unit == "MINUTE":
    117                sql = f"{sql} * 1440.0"
    118            elif unit == "SECOND":
    119                sql = f"{sql} * 86400.0"
    120            elif unit == "MILLISECOND":
    121                sql = f"{sql} * 86400000.0"
    122            elif unit == "MICROSECOND":
    123                sql = f"{sql} * 86400000000.0"
    124            elif unit == "NANOSECOND":
    125                sql = f"{sql} * 8640000000000.0"
    126            else:
    127                self.unsupported("DATEDIFF unsupported for '{unit}'.")
    128
    129            return f"CAST({sql} AS INTEGER)"
    130
    131        # https://www.sqlite.org/lang_aggfunc.html#group_concat
    132        def groupconcat_sql(self, expression):
    133            this = expression.this
    134            distinct = expression.find(exp.Distinct)
    135            if distinct:
    136                this = distinct.expressions[0]
    137                distinct = "DISTINCT "
    138
    139            if isinstance(expression.this, exp.Order):
    140                self.unsupported("SQLite GROUP_CONCAT doesn't support ORDER BY.")
    141                if expression.this.this and not distinct:
    142                    this = expression.this.this
    143
    144            separator = expression.args.get("separator")
    145            return f"GROUP_CONCAT({distinct or ''}{self.format_args(this, separator)})"
    146
    147        def least_sql(self, expression: exp.Least) -> str:
    148            if len(expression.expressions) > 1:
    149                return rename_func("MIN")(self, expression)
    150
    151            return self.expressions(expression)
    152
    153        def transaction_sql(self, expression: exp.Transaction) -> str:
    154            this = expression.this
    155            this = f" {this}" if this else ""
    156            return f"BEGIN{this} TRANSACTION"

##### Inherited Members

sqlglot.dialects.dialect.Dialect
  get_or_raise
  format_time
  parse
  parse_into
  generate
  transpile
  tokenize
  parser
  generator

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

    27    class Tokenizer(tokens.Tokenizer):
    28        IDENTIFIERS = ['"', ("[", "]"), "`"]
    29        HEX_STRINGS = [("x'", "'"), ("X'", "'"), ("0x", ""), ("0X", "")]
    30
    31        KEYWORDS = {
    32            **tokens.Tokenizer.KEYWORDS,
    33        }

##### Inherited Members

sqlglot.tokens.Tokenizer
  reset
  tokenize

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

    35    class Parser(parser.Parser):
    36        FUNCTIONS = {
    37            **parser.Parser.FUNCTIONS,  # type: ignore
    38            "EDITDIST3": exp.Levenshtein.from_arg_list,
    39        }

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

###### Arguments:

- error_level: the desired error level. Default: ErrorLevel.RAISE
- error_message_context: determines the amount of context to capture from a query string when displaying the error message (in number of characters). Default: 50.
- index_offset: Index offset for arrays eg ARRAY[0] vs ARRAY[1] as the head of a list. Default: 0
- alias_post_tablesample: If the table alias comes after tablesample. Default: False
- max_errors: Maximum number of error messages to include in a raised ParseError. This is only relevant if error_level is ErrorLevel.RAISE. Default: 3
- null_ordering: Indicates the default null ordering method to use if not explicitly set. Options are "nulls_are_small", "nulls_are_large", "nulls_are_last". Default: "nulls_are_small"

##### Inherited Members

sqlglot.parser.Parser
  Parser
  reset
  parse
  parse_into
  check_errors
  raise_error
  expression
  validate_expression

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

     41    class Generator(generator.Generator):
     42        JOIN_HINTS = False
     43        TABLE_HINTS = False
     44
     45        TYPE_MAPPING = {
     46            **generator.Generator.TYPE_MAPPING,  # type: ignore
     47            exp.DataType.Type.BOOLEAN: "INTEGER",
     48            exp.DataType.Type.TINYINT: "INTEGER",
     49            exp.DataType.Type.SMALLINT: "INTEGER",
     50            exp.DataType.Type.INT: "INTEGER",
     51            exp.DataType.Type.BIGINT: "INTEGER",
     52            exp.DataType.Type.FLOAT: "REAL",
     53            exp.DataType.Type.DOUBLE: "REAL",
     54            exp.DataType.Type.DECIMAL: "REAL",
     55            exp.DataType.Type.CHAR: "TEXT",
     56            exp.DataType.Type.NCHAR: "TEXT",
     57            exp.DataType.Type.VARCHAR: "TEXT",
     58            exp.DataType.Type.NVARCHAR: "TEXT",
     59            exp.DataType.Type.BINARY: "BLOB",
     60            exp.DataType.Type.VARBINARY: "BLOB",
     61        }
     62
     63        TOKEN_MAPPING = {
     64            TokenType.AUTO_INCREMENT: "AUTOINCREMENT",
     65        }
     66
     67        TRANSFORMS = {
     68            **generator.Generator.TRANSFORMS,  # type: ignore
     69            exp.CountIf: count_if_to_sum,
     70            exp.CurrentDate: lambda *_: "CURRENT_DATE",
     71            exp.CurrentTime: lambda *_: "CURRENT_TIME",
     72            exp.CurrentTimestamp: lambda *_: "CURRENT_TIMESTAMP",
     73            exp.DateAdd: _date_add_sql,
     74            exp.DateStrToDate: lambda self, e: self.sql(e, "this"),
     75            exp.ILike: no_ilike_sql,
     76            exp.JSONExtract: arrow_json_extract_sql,
     77            exp.JSONExtractScalar: arrow_json_extract_scalar_sql,
     78            exp.JSONBExtract: arrow_json_extract_sql,
     79            exp.JSONBExtractScalar: arrow_json_extract_scalar_sql,
     80            exp.Levenshtein: rename_func("EDITDIST3"),
     81            exp.LogicalOr: rename_func("MAX"),
     82            exp.LogicalAnd: rename_func("MIN"),
     83            exp.Select: transforms.preprocess(
     84                [transforms.eliminate_distinct_on, transforms.eliminate_qualify]
     85            ),
     86            exp.TableSample: no_tablesample_sql,
     87            exp.TimeStrToTime: lambda self, e: self.sql(e, "this"),
     88            exp.TryCast: no_trycast_sql,
     89        }
     90
     91        PROPERTIES_LOCATION = {
     92            k: exp.Properties.Location.UNSUPPORTED
     93            for k, v in generator.Generator.PROPERTIES_LOCATION.items()
     94        }
     95
     96        LIMIT_FETCH = "LIMIT"
     97
     98        def cast_sql(self, expression: exp.Cast) -> str:
     99            if expression.to.this == exp.DataType.Type.DATE:
    100                return self.func("DATE", expression.this)
    101
    102            return super().cast_sql(expression)
    103
    104        def datediff_sql(self, expression: exp.DateDiff) -> str:
    105            unit = expression.args.get("unit")
    106            unit = unit.name.upper() if unit else "DAY"
    107
    108            sql = f"(JULIANDAY({self.sql(expression, 'this')}) - JULIANDAY({self.sql(expression, 'expression')}))"
    109
    110            if unit == "MONTH":
    111                sql = f"{sql} / 30.0"
    112            elif unit == "YEAR":
    113                sql = f"{sql} / 365.0"
    114            elif unit == "HOUR":
    115                sql = f"{sql} * 24.0"
    116            elif unit == "MINUTE":
    117                sql = f"{sql} * 1440.0"
    118            elif unit == "SECOND":
    119                sql = f"{sql} * 86400.0"
    120            elif unit == "MILLISECOND":
    121                sql = f"{sql} * 86400000.0"
    122            elif unit == "MICROSECOND":
    123                sql = f"{sql} * 86400000000.0"
    124            elif unit == "NANOSECOND":
    125                sql = f"{sql} * 8640000000000.0"
    126            else:
    127                self.unsupported("DATEDIFF unsupported for '{unit}'.")
    128
    129            return f"CAST({sql} AS INTEGER)"
    130
    131        # https://www.sqlite.org/lang_aggfunc.html#group_concat
    132        def groupconcat_sql(self, expression):
    133            this = expression.this
    134            distinct = expression.find(exp.Distinct)
    135            if distinct:
    136                this = distinct.expressions[0]
    137                distinct = "DISTINCT "
    138
    139            if isinstance(expression.this, exp.Order):
    140                self.unsupported("SQLite GROUP_CONCAT doesn't support ORDER BY.")
    141                if expression.this.this and not distinct:
    142                    this = expression.this.this
    143
    144            separator = expression.args.get("separator")
    145            return f"GROUP_CONCAT({distinct or ''}{self.format_args(this, separator)})"
    146
    147        def least_sql(self, expression: exp.Least) -> str:
    148            if len(expression.expressions) > 1:
    149                return rename_func("MIN")(self, expression)
    150
    151            return self.expressions(expression)
    152
    153        def transaction_sql(self, expression: exp.Transaction) -> str:
    154            this = expression.this
    155            this = f" {this}" if this else ""
    156            return f"BEGIN{this} TRANSACTION"

Generator interprets the given syntax tree and produces a SQL string as an output.

###### Arguments:

- time_mapping (dict): the dictionary of custom time mappings in which the key represents a python time format and the output the target time format
- time_trie (trie): a trie of the time_mapping keys
- pretty (bool): if set to True the returned string will be formatted. Default: False.
- quote_start (str): specifies which starting character to use to delimit quotes. Default: '.
- quote_end (str): specifies which ending character to use to delimit quotes. Default: '.
- identifier_start (str): specifies which starting character to use to delimit identifiers. Default: ".
- identifier_end (str): specifies which ending character to use to delimit identifiers. Default: ".
- identify (bool | str): 'always': always quote, 'safe': quote identifiers if they don't contain an upcase, True defaults to always.
- normalize (bool): if set to True all identifiers will lower cased
- string_escape (str): specifies a string escape character. Default: '.
- identifier_escape (str): specifies an identifier escape character. Default: ".
- pad (int): determines padding in a formatted string. Default: 2.
- indent (int): determines the size of indentation in a formatted string. Default: 4.
- unnest_column_only (bool): if true unnest table aliases are considered only as column aliases
- normalize_functions (str): normalize function names, "upper", "lower", or None Default: "upper"
- alias_post_tablesample (bool): if the table alias comes after tablesample Default: False
- unsupported_level (ErrorLevel): determines the generator's behavior when it encounters unsupported expressions. Default ErrorLevel.WARN.
- null_ordering (str): Indicates the default null ordering method to use if not explicitly set. Options are "nulls_are_small", "nulls_are_large", "nulls_are_last". Default: "nulls_are_small"
- max_unsupported (int): Maximum number of unsupported messages to include in a raised UnsupportedError. This is only relevant if unsupported_level is ErrorLevel.RAISE. Default: 3
- leading_comma (bool): if the the comma is leading or trailing in select statements Default: False
- max_text_width: The max number of characters in a segment before creating new lines in pretty mode. The default is on the smaller end because the length only represents a segment and not the true line length. Default: 80
- comments: Whether or not to preserve comments in the output SQL code. Default: True

def cast_sql(self, expression: sqlglot.expressions.Cast) -> str: View Source

     98        def cast_sql(self, expression: exp.Cast) -> str:
     99            if expression.to.this == exp.DataType.Type.DATE:
    100                return self.func("DATE", expression.this)
    101
    102            return super().cast_sql(expression)

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

    104        def datediff_sql(self, expression: exp.DateDiff) -> str:
    105            unit = expression.args.get("unit")
    106            unit = unit.name.upper() if unit else "DAY"
    107
    108            sql = f"(JULIANDAY({self.sql(expression, 'this')}) - JULIANDAY({self.sql(expression, 'expression')}))"
    109
    110            if unit == "MONTH":
    111                sql = f"{sql} / 30.0"
    112            elif unit == "YEAR":
    113                sql = f"{sql} / 365.0"
    114            elif unit == "HOUR":
    115                sql = f"{sql} * 24.0"
    116            elif unit == "MINUTE":
    117                sql = f"{sql} * 1440.0"
    118            elif unit == "SECOND":
    119                sql = f"{sql} * 86400.0"
    120            elif unit == "MILLISECOND":
    121                sql = f"{sql} * 86400000.0"
    122            elif unit == "MICROSECOND":
    123                sql = f"{sql} * 86400000000.0"
    124            elif unit == "NANOSECOND":
    125                sql = f"{sql} * 8640000000000.0"
    126            else:
    127                self.unsupported("DATEDIFF unsupported for '{unit}'.")
    128
    129            return f"CAST({sql} AS INTEGER)"

def groupconcat_sql(self, expression): View Source

    132        def groupconcat_sql(self, expression):
    133            this = expression.this
    134            distinct = expression.find(exp.Distinct)
    135            if distinct:
    136                this = distinct.expressions[0]
    137                distinct = "DISTINCT "
    138
    139            if isinstance(expression.this, exp.Order):
    140                self.unsupported("SQLite GROUP_CONCAT doesn't support ORDER BY.")
    141                if expression.this.this and not distinct:
    142                    this = expression.this.this
    143
    144            separator = expression.args.get("separator")
    145            return f"GROUP_CONCAT({distinct or ''}{self.format_args(this, separator)})"

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

    147        def least_sql(self, expression: exp.Least) -> str:
    148            if len(expression.expressions) > 1:
    149                return rename_func("MIN")(self, expression)
    150
    151            return self.expressions(expression)

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

    153        def transaction_sql(self, expression: exp.Transaction) -> str:
    154            this = expression.this
    155            this = f" {this}" if this else ""
    156            return f"BEGIN{this} TRANSACTION"

##### Inherited Members

sqlglot.generator.Generator
  Generator
  generate
  unsupported
  sep
  seg
  pad_comment
  maybe_comment
  wrap
  no_identify
  normalize_func
  indent
  sql
  uncache_sql
  cache_sql
  characterset_sql
  column_sql
  columnposition_sql
  columndef_sql
  columnconstraint_sql
  autoincrementcolumnconstraint_sql
  compresscolumnconstraint_sql
  generatedasidentitycolumnconstraint_sql
  notnullcolumnconstraint_sql
  primarykeycolumnconstraint_sql
  uniquecolumnconstraint_sql
  create_sql
  describe_sql
  prepend_ctes
  with_sql
  cte_sql
  tablealias_sql
  bitstring_sql
  hexstring_sql
  bytestring_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
  afterjournalproperty_sql
  checksumproperty_sql
  mergeblockratioproperty_sql
  datablocksizeproperty_sql
  blockcompressionproperty_sql
  isolatedloadingproperty_sql
  lockingproperty_sql
  withdataproperty_sql
  insert_sql
  intersect_sql
  intersect_op
  introducer_sql
  pseudotype_sql
  onconflict_sql
  returning_sql
  rowformatdelimitedproperty_sql
  table_sql
  tablesample_sql
  pivot_sql
  tuple_sql
  update_sql
  values_sql
  var_sql
  into_sql
  from_sql
  group_sql
  having_sql
  join_sql
  lambda_sql
  lateral_sql
  limit_sql
  offset_sql
  setitem_sql
  set_sql
  pragma_sql
  lock_sql
  literal_sql
  loaddata_sql
  null_sql
  boolean_sql
  order_sql
  cluster_sql
  distribute_sql
  sort_sql
  ordered_sql
  matchrecognize_sql
  query_modifiers
  select_sql
  schema_sql
  star_sql
  structkwarg_sql
  parameter_sql
  sessionparameter_sql
  placeholder_sql
  subquery_sql
  qualify_sql
  union_sql
  union_op
  unnest_sql
  where_sql
  window_sql
  partition_by_sql
  windowspec_sql
  withingroup_sql
  between_sql
  bracket_sql
  all_sql
  any_sql
  exists_sql
  case_sql
  constraint_sql
  nextvaluefor_sql
  extract_sql
  trim_sql
  concat_sql
  check_sql
  foreignkey_sql
  primarykey_sql
  unique_sql
  if_sql
  matchagainst_sql
  jsonkeyvalue_sql
  jsonobject_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
  currentdate_sql
  collate_sql
  command_sql
  comment_sql
  commit_sql
  rollback_sql
  altercolumn_sql
  renametable_sql
  altertable_sql
  droppartition_sql
  addconstraint_sql
  distinct_sql
  ignorenulls_sql
  respectnulls_sql
  intdiv_sql
  dpipe_sql
  div_sql
  overlaps_sql
  distance_sql
  dot_sql
  eq_sql
  escape_sql
  glob_sql
  gt_sql
  gte_sql
  ilike_sql
  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