sqlglot.generators.sqlite
1from __future__ import annotations 2 3import typing as t 4 5from sqlglot import exp, generator, transforms 6from sqlglot.dialects.dialect import ( 7 any_value_to_max_sql, 8 arrow_json_extract_sql, 9 count_if_to_sum, 10 groupconcat_sql, 11 no_ilike_sql, 12 no_pivot_sql, 13 no_tablesample_sql, 14 no_trycast_sql, 15 rename_func, 16 strposition_sql, 17) 18from sqlglot.generator import unsupported_args 19from sqlglot.tokens import TokenType 20 21 22def _transform_create(expression: exp.Expr) -> exp.Expr: 23 """Move primary key to a column and place auto_increment after it.""" 24 schema = expression.this 25 26 if isinstance(expression, exp.Create) and isinstance(schema, exp.Schema): 27 defs = {} 28 primary_key = None 29 30 for e in schema.expressions: 31 if isinstance(e, exp.ColumnDef): 32 defs[e.name] = e 33 elif isinstance(e, exp.PrimaryKey): 34 primary_key = e 35 36 if primary_key and len(primary_key.expressions) == 1: 37 column = defs[primary_key.expressions[0].name] 38 column.append( 39 "constraints", exp.ColumnConstraint(kind=exp.PrimaryKeyColumnConstraint()) 40 ) 41 schema.expressions.remove(primary_key) 42 43 for column in defs.values(): 44 primary_key_index = -1 45 auto_increment = None 46 auto_increment_index = -1 47 48 for i, constraint in enumerate(column.constraints): 49 if isinstance(constraint.kind, exp.PrimaryKeyColumnConstraint): 50 primary_key_index = i 51 elif isinstance(constraint.kind, exp.AutoIncrementColumnConstraint): 52 auto_increment = constraint 53 auto_increment_index = i 54 55 if auto_increment is not None and 0 <= auto_increment_index < primary_key_index: 56 column.constraints.remove(auto_increment) 57 column.constraints.insert(primary_key_index, auto_increment) 58 59 return expression 60 61 62def _generated_to_auto_increment(expression: exp.Expr) -> exp.Expr: 63 if not isinstance(expression, exp.ColumnDef): 64 return expression 65 66 generated = expression.find(exp.GeneratedAsIdentityColumnConstraint) 67 68 # Only rewrite true identity columns. Expression-bearing forms are computed 69 # columns (GENERATED ALWAYS AS (expr)) and must keep their expression. 70 if generated and generated.expression is None: 71 t.cast(exp.ColumnConstraint, generated.parent).pop() 72 73 not_null = expression.find(exp.NotNullColumnConstraint) 74 if not_null: 75 t.cast(exp.ColumnConstraint, not_null.parent).pop() 76 77 expression.append( 78 "constraints", exp.ColumnConstraint(kind=exp.AutoIncrementColumnConstraint()) 79 ) 80 81 return expression 82 83 84def _offset_to_limit(expression: exp.Expr) -> exp.Expr: 85 if not isinstance(expression, exp.Select): 86 return expression 87 88 offset = expression.args.get("offset") 89 90 if offset and not expression.args.get("limit"): 91 expression.limit(-1, copy=False) 92 93 return expression 94 95 96class SQLiteGenerator(generator.Generator): 97 SELECT_KINDS: tuple[str, ...] = () 98 TRY_SUPPORTED = False 99 SUPPORTS_UESCAPE = False 100 SUPPORTS_DECODE_CASE = False 101 SET_OP_PARENTHESIZED_OPERANDS = False 102 103 AFTER_HAVING_MODIFIER_TRANSFORMS = generator.AFTER_HAVING_MODIFIER_TRANSFORMS 104 105 JOIN_HINTS = False 106 TABLE_HINTS = False 107 QUERY_HINTS = False 108 NVL2_SUPPORTED = False 109 JSON_PATH_BRACKETED_KEY_SUPPORTED = False 110 SUPPORTS_CREATE_TABLE_LIKE = False 111 SUPPORTS_TABLE_ALIAS_COLUMNS = False 112 SUPPORTS_TO_NUMBER = False 113 SUPPORTS_WINDOW_EXCLUDE = True 114 EXCEPT_INTERSECT_SUPPORT_ALL_CLAUSE = False 115 SUPPORTS_MEDIAN = False 116 JSON_KEY_VALUE_PAIR_SEP = "," 117 PARSE_JSON_NAME: str | None = None 118 119 SUPPORTED_JSON_PATH_PARTS = { 120 exp.JSONPathKey, 121 exp.JSONPathRoot, 122 exp.JSONPathSubscript, 123 } 124 125 TYPE_MAPPING = { 126 **{k: v for k, v in generator.Generator.TYPE_MAPPING.items() if k != exp.DType.BLOB}, 127 exp.DType.BOOLEAN: "INTEGER", 128 exp.DType.TINYINT: "INTEGER", 129 exp.DType.SMALLINT: "INTEGER", 130 exp.DType.INT: "INTEGER", 131 exp.DType.BIGINT: "INTEGER", 132 exp.DType.FLOAT: "REAL", 133 exp.DType.DOUBLE: "REAL", 134 exp.DType.DECIMAL: "REAL", 135 exp.DType.CHAR: "TEXT", 136 exp.DType.NCHAR: "TEXT", 137 exp.DType.VARCHAR: "TEXT", 138 exp.DType.NVARCHAR: "TEXT", 139 exp.DType.BINARY: "BLOB", 140 exp.DType.VARBINARY: "BLOB", 141 } 142 143 TOKEN_MAPPING = { 144 TokenType.AUTO_INCREMENT: "AUTOINCREMENT", 145 } 146 147 TRANSFORMS = { 148 **generator.Generator.TRANSFORMS, 149 exp.AnyValue: any_value_to_max_sql, 150 exp.Chr: rename_func("CHAR"), 151 exp.CountIf: count_if_to_sum, 152 exp.Create: transforms.preprocess([_transform_create]), 153 exp.CurrentDate: lambda *_: "CURRENT_DATE", 154 exp.CurrentTime: lambda *_: "CURRENT_TIME", 155 exp.CurrentTimestamp: lambda *_: "CURRENT_TIMESTAMP", 156 exp.CurrentVersion: lambda *_: "SQLITE_VERSION()", 157 exp.ColumnDef: transforms.preprocess([_generated_to_auto_increment]), 158 exp.DateStrToDate: lambda self, e: self.sql(e, "this"), 159 exp.If: rename_func("IIF"), 160 exp.ILike: no_ilike_sql, 161 exp.JSONArrayAgg: unsupported_args("order", "null_handling", "return_type", "strict")( 162 rename_func("JSON_GROUP_ARRAY") 163 ), 164 exp.JSONObjectAgg: lambda self, e: self._jsonobject_sql(e, name="JSON_GROUP_OBJECT"), 165 exp.Levenshtein: unsupported_args("ins_cost", "del_cost", "sub_cost", "max_dist")( 166 rename_func("EDITDIST3") 167 ), 168 exp.LogicalOr: rename_func("MAX"), 169 exp.LogicalAnd: rename_func("MIN"), 170 exp.Pivot: no_pivot_sql, 171 exp.Rand: rename_func("RANDOM"), 172 exp.RegexpLike: lambda self, e: self.binary(e, "REGEXP"), 173 exp.Select: transforms.preprocess( 174 [ 175 _offset_to_limit, 176 transforms.eliminate_distinct_on, 177 transforms.eliminate_qualify, 178 transforms.eliminate_semi_and_anti_joins, 179 ] 180 ), 181 exp.StrPosition: lambda self, e: strposition_sql(self, e, func_name="INSTR"), 182 exp.TableSample: no_tablesample_sql, 183 exp.TimeStrToTime: lambda self, e: self.sql(e, "this"), 184 exp.TimeToStr: lambda self, e: self.func("STRFTIME", e.args.get("format"), e.this), 185 exp.TryCast: no_trycast_sql, 186 exp.TsOrDsToTimestamp: lambda self, e: self.sql(e, "this"), 187 } 188 189 # SQLite doesn't generally support CREATE TABLE .. properties 190 # https://www.sqlite.org/lang_createtable.html 191 PROPERTIES_LOCATION = { 192 **{ 193 prop: exp.Properties.Location.UNSUPPORTED 194 for prop in generator.Generator.PROPERTIES_LOCATION 195 }, 196 # There are a few exceptions (e.g. temporary tables) which are supported or 197 # can be transpiled to SQLite, so we explicitly override them accordingly 198 exp.LikeProperty: exp.Properties.Location.POST_SCHEMA, 199 exp.ModuleProperty: exp.Properties.Location.POST_SCHEMA, 200 exp.TemporaryProperty: exp.Properties.Location.POST_CREATE, 201 exp.VirtualProperty: exp.Properties.Location.POST_CREATE, 202 } 203 204 LIMIT_FETCH = "LIMIT" 205 206 def autoincrementcolumnconstraint_sql( 207 self, expression: exp.AutoIncrementColumnConstraint 208 ) -> str: 209 column = expression.find_ancestor(exp.ColumnDef) 210 if column and column.find(exp.PrimaryKeyColumnConstraint): 211 return super().autoincrementcolumnconstraint_sql(expression) 212 213 self.unsupported("SQLite AUTOINCREMENT requires an INTEGER PRIMARY KEY") 214 return "" 215 216 def insert_sql(self, expression: exp.Insert) -> str: 217 if expression.args.get("ignore"): 218 expression.set("ignore", False) 219 expression.set("alternative", "IGNORE") 220 221 return super().insert_sql(expression) 222 223 def bitwiseandagg_sql(self, expression: exp.BitwiseAndAgg) -> str: 224 self.unsupported("BITWISE_AND aggregation is not supported in SQLite") 225 return self.function_fallback_sql(expression) 226 227 def bitwiseoragg_sql(self, expression: exp.BitwiseOrAgg) -> str: 228 self.unsupported("BITWISE_OR aggregation is not supported in SQLite") 229 return self.function_fallback_sql(expression) 230 231 def bitwisexoragg_sql(self, expression: exp.BitwiseXorAgg) -> str: 232 self.unsupported("BITWISE_XOR aggregation is not supported in SQLite") 233 return self.function_fallback_sql(expression) 234 235 def jsonextract_sql(self, expression: exp.JSONExtract) -> str: 236 if expression.expressions: 237 return self.function_fallback_sql(expression) 238 return arrow_json_extract_sql(self, expression) 239 240 def jsonextractscalar_sql(self, expression: exp.JSONExtractScalar) -> str: 241 if expression.args.get("json_subtype"): 242 # json_extract() keeps the JSON subtype on object/array results; 243 # ->> strips it, observable when the result feeds another JSON function 244 return self.func("JSON_EXTRACT", expression.this, expression.expression) 245 return arrow_json_extract_sql(self, expression) 246 247 def dateadd_sql(self, expression: exp.DateAdd) -> str: 248 modifier = expression.expression 249 unit = expression.args.get("unit") 250 # An INTERVAL amount carries its own unit, e.g. DATE_ADD(d, INTERVAL 1 DAY); 251 # unwrap it so the unit is not left inside the quoted modifier string. 252 if isinstance(modifier, exp.Interval): 253 unit = unit or modifier.unit 254 modifier = modifier.this 255 256 modifier = modifier.unnest() 257 if ( 258 unit 259 and not isinstance(modifier, exp.Literal) 260 and not (isinstance(modifier, exp.Neg) and modifier.this.is_number) 261 ): 262 return self.func( 263 "DATE", 264 expression.this, 265 exp.DPipe( 266 this=exp.paren(modifier), 267 expression=exp.Literal.string(f" {unit.name}"), 268 ), 269 ) 270 modifier = modifier.name if modifier.is_string else self.sql(modifier) 271 modifier = f"'{modifier} {unit.name}'" if unit else f"'{modifier}'" 272 return self.func("DATE", expression.this, modifier) 273 274 def cast_sql(self, expression: exp.Cast, safe_prefix: str | None = None) -> str: 275 if expression.is_type("date"): 276 return self.func("DATE", expression.this) 277 278 return super().cast_sql(expression) 279 280 # https://www.sqlite.org/gencol.html 281 # Inline unsupported check: mypyc cannot compile @unsupported_args on an 282 # override of an undecorated base-class method. 283 def computedcolumnconstraint_sql(self, expression: exp.ComputedColumnConstraint) -> str: 284 if expression.args.get("data_type"): 285 self.unsupported("SQLite generated columns do not support a data type") 286 287 this = expression.this 288 this_sql = self.sql(this) if isinstance(this, exp.Paren) else f"({self.sql(this)})" 289 storage = " STORED" if expression.args.get("persisted") else "" 290 not_null = " NOT NULL" if expression.args.get("not_null") else "" 291 return f"AS {this_sql}{storage}{not_null}" 292 293 # Note: SQLite's TRUNC always returns REAL (e.g., trunc(10.99) -> 10.0), not INTEGER. 294 # This creates a transpilation gap affecting division semantics, similar to Presto. 295 # Unlike Presto where this only affects decimals=0, SQLite has no decimals parameter 296 # so every use of TRUNC is affected. Modeling precisely would require exp.FloatTrunc. 297 @unsupported_args("decimals") 298 def trunc_sql(self, expression: exp.Trunc) -> str: 299 return self.func("TRUNC", expression.this) 300 301 def generateseries_sql(self, expression: exp.GenerateSeries) -> str: 302 parent = expression.parent 303 alias = parent and parent.args.get("alias") 304 305 if isinstance(alias, exp.TableAlias) and alias.columns: 306 column_alias = alias.columns[0] 307 alias.set("columns", None) 308 sql = self.sql( 309 exp.select(exp.alias_("value", column_alias)).from_(expression).subquery() 310 ) 311 else: 312 sql = self.function_fallback_sql(expression) 313 314 return sql 315 316 def datediff_sql(self, expression: exp.DateDiff) -> str: 317 unit = expression.args.get("unit") 318 unit = unit.name.upper() if unit else "DAY" 319 320 sql = f"(JULIANDAY({self.sql(expression, 'this')}) - JULIANDAY({self.sql(expression, 'expression')}))" 321 322 if unit == "MONTH": 323 sql = f"{sql} / 30.0" 324 elif unit == "YEAR": 325 sql = f"{sql} / 365.0" 326 elif unit == "HOUR": 327 sql = f"{sql} * 24.0" 328 elif unit == "MINUTE": 329 sql = f"{sql} * 1440.0" 330 elif unit == "SECOND": 331 sql = f"{sql} * 86400.0" 332 elif unit == "MILLISECOND": 333 sql = f"{sql} * 86400000.0" 334 elif unit == "MICROSECOND": 335 sql = f"{sql} * 86400000000.0" 336 elif unit == "NANOSECOND": 337 sql = f"{sql} * 86400000000000.0" 338 else: 339 self.unsupported(f"DATEDIFF unsupported for '{unit}'.") 340 341 return f"CAST({sql} AS INTEGER)" 342 343 def groupconcat_sql(self, expression: exp.GroupConcat) -> str: 344 node = expression.parent if isinstance(expression.parent, exp.Filter) else expression 345 window = node.parent 346 347 if ( 348 isinstance(expression.this, exp.Order) 349 and isinstance(window, exp.Window) 350 and window.this is node 351 ): 352 self.unsupported( 353 "SQLite GROUP_CONCAT window functions do not support argument ORDER BY" 354 ) 355 expression.set("this", expression.this.this) 356 357 return groupconcat_sql( 358 self, expression, func_name="GROUP_CONCAT", sep=None, within_group=False 359 ) 360 361 def _greatest_least_sql(self, expression: exp.Greatest | exp.Least) -> str: 362 if not expression.expressions: 363 return self.sql(expression, "this") 364 365 name = "MAX" if isinstance(expression, exp.Greatest) else "MIN" 366 367 if not expression.args.get("ignore_nulls"): 368 return rename_func(name)(self, expression) 369 370 # SQLite's multi-argument MAX/MIN return NULL if any argument is NULL. 371 # GREATEST(a, b, c) -> MAX(COALESCE(a, b, c), COALESCE(b, c, a), COALESCE(c, a, b)). 372 args = [expression.this, *expression.expressions] 373 374 coalesces = [] 375 for i in range(len(args)): 376 rotated = args[i:] + args[:i] 377 coalesces.append(exp.Coalesce(this=rotated[0], expressions=rotated[1:])) 378 379 return self.func(name, *coalesces) 380 381 def greatest_sql(self, expression: exp.Greatest) -> str: 382 return self._greatest_least_sql(expression) 383 384 def least_sql(self, expression: exp.Least) -> str: 385 return self._greatest_least_sql(expression) 386 387 def transaction_sql(self, expression: exp.Transaction) -> str: 388 this = expression.this 389 this = f" {this}" if this else "" 390 return f"BEGIN{this} TRANSACTION" 391 392 def isascii_sql(self, expression: exp.IsAscii) -> str: 393 return f"(NOT {self.sql(expression.this)} GLOB CAST(x'2a5b5e012d7f5d2a' AS TEXT))" 394 395 @unsupported_args("this") 396 def currentschema_sql(self, expression: exp.CurrentSchema) -> str: 397 return "'main'" 398 399 def ignorenulls_sql(self, expression: exp.IgnoreNulls) -> str: 400 self.unsupported("SQLite does not support IGNORE NULLS.") 401 return self.sql(expression.this) 402 403 def respectnulls_sql(self, expression: exp.RespectNulls) -> str: 404 return self.sql(expression.this) 405 406 def windowspec_sql(self, expression: exp.WindowSpec) -> str: 407 if ( 408 expression.text("kind").upper() == "RANGE" 409 and expression.text("start").upper() == "CURRENT ROW" 410 and expression.args.get("end") is None 411 ): 412 return "RANGE CURRENT ROW" 413 414 return super().windowspec_sql(expression)
97class SQLiteGenerator(generator.Generator): 98 SELECT_KINDS: tuple[str, ...] = () 99 TRY_SUPPORTED = False 100 SUPPORTS_UESCAPE = False 101 SUPPORTS_DECODE_CASE = False 102 SET_OP_PARENTHESIZED_OPERANDS = False 103 104 AFTER_HAVING_MODIFIER_TRANSFORMS = generator.AFTER_HAVING_MODIFIER_TRANSFORMS 105 106 JOIN_HINTS = False 107 TABLE_HINTS = False 108 QUERY_HINTS = False 109 NVL2_SUPPORTED = False 110 JSON_PATH_BRACKETED_KEY_SUPPORTED = False 111 SUPPORTS_CREATE_TABLE_LIKE = False 112 SUPPORTS_TABLE_ALIAS_COLUMNS = False 113 SUPPORTS_TO_NUMBER = False 114 SUPPORTS_WINDOW_EXCLUDE = True 115 EXCEPT_INTERSECT_SUPPORT_ALL_CLAUSE = False 116 SUPPORTS_MEDIAN = False 117 JSON_KEY_VALUE_PAIR_SEP = "," 118 PARSE_JSON_NAME: str | None = None 119 120 SUPPORTED_JSON_PATH_PARTS = { 121 exp.JSONPathKey, 122 exp.JSONPathRoot, 123 exp.JSONPathSubscript, 124 } 125 126 TYPE_MAPPING = { 127 **{k: v for k, v in generator.Generator.TYPE_MAPPING.items() if k != exp.DType.BLOB}, 128 exp.DType.BOOLEAN: "INTEGER", 129 exp.DType.TINYINT: "INTEGER", 130 exp.DType.SMALLINT: "INTEGER", 131 exp.DType.INT: "INTEGER", 132 exp.DType.BIGINT: "INTEGER", 133 exp.DType.FLOAT: "REAL", 134 exp.DType.DOUBLE: "REAL", 135 exp.DType.DECIMAL: "REAL", 136 exp.DType.CHAR: "TEXT", 137 exp.DType.NCHAR: "TEXT", 138 exp.DType.VARCHAR: "TEXT", 139 exp.DType.NVARCHAR: "TEXT", 140 exp.DType.BINARY: "BLOB", 141 exp.DType.VARBINARY: "BLOB", 142 } 143 144 TOKEN_MAPPING = { 145 TokenType.AUTO_INCREMENT: "AUTOINCREMENT", 146 } 147 148 TRANSFORMS = { 149 **generator.Generator.TRANSFORMS, 150 exp.AnyValue: any_value_to_max_sql, 151 exp.Chr: rename_func("CHAR"), 152 exp.CountIf: count_if_to_sum, 153 exp.Create: transforms.preprocess([_transform_create]), 154 exp.CurrentDate: lambda *_: "CURRENT_DATE", 155 exp.CurrentTime: lambda *_: "CURRENT_TIME", 156 exp.CurrentTimestamp: lambda *_: "CURRENT_TIMESTAMP", 157 exp.CurrentVersion: lambda *_: "SQLITE_VERSION()", 158 exp.ColumnDef: transforms.preprocess([_generated_to_auto_increment]), 159 exp.DateStrToDate: lambda self, e: self.sql(e, "this"), 160 exp.If: rename_func("IIF"), 161 exp.ILike: no_ilike_sql, 162 exp.JSONArrayAgg: unsupported_args("order", "null_handling", "return_type", "strict")( 163 rename_func("JSON_GROUP_ARRAY") 164 ), 165 exp.JSONObjectAgg: lambda self, e: self._jsonobject_sql(e, name="JSON_GROUP_OBJECT"), 166 exp.Levenshtein: unsupported_args("ins_cost", "del_cost", "sub_cost", "max_dist")( 167 rename_func("EDITDIST3") 168 ), 169 exp.LogicalOr: rename_func("MAX"), 170 exp.LogicalAnd: rename_func("MIN"), 171 exp.Pivot: no_pivot_sql, 172 exp.Rand: rename_func("RANDOM"), 173 exp.RegexpLike: lambda self, e: self.binary(e, "REGEXP"), 174 exp.Select: transforms.preprocess( 175 [ 176 _offset_to_limit, 177 transforms.eliminate_distinct_on, 178 transforms.eliminate_qualify, 179 transforms.eliminate_semi_and_anti_joins, 180 ] 181 ), 182 exp.StrPosition: lambda self, e: strposition_sql(self, e, func_name="INSTR"), 183 exp.TableSample: no_tablesample_sql, 184 exp.TimeStrToTime: lambda self, e: self.sql(e, "this"), 185 exp.TimeToStr: lambda self, e: self.func("STRFTIME", e.args.get("format"), e.this), 186 exp.TryCast: no_trycast_sql, 187 exp.TsOrDsToTimestamp: lambda self, e: self.sql(e, "this"), 188 } 189 190 # SQLite doesn't generally support CREATE TABLE .. properties 191 # https://www.sqlite.org/lang_createtable.html 192 PROPERTIES_LOCATION = { 193 **{ 194 prop: exp.Properties.Location.UNSUPPORTED 195 for prop in generator.Generator.PROPERTIES_LOCATION 196 }, 197 # There are a few exceptions (e.g. temporary tables) which are supported or 198 # can be transpiled to SQLite, so we explicitly override them accordingly 199 exp.LikeProperty: exp.Properties.Location.POST_SCHEMA, 200 exp.ModuleProperty: exp.Properties.Location.POST_SCHEMA, 201 exp.TemporaryProperty: exp.Properties.Location.POST_CREATE, 202 exp.VirtualProperty: exp.Properties.Location.POST_CREATE, 203 } 204 205 LIMIT_FETCH = "LIMIT" 206 207 def autoincrementcolumnconstraint_sql( 208 self, expression: exp.AutoIncrementColumnConstraint 209 ) -> str: 210 column = expression.find_ancestor(exp.ColumnDef) 211 if column and column.find(exp.PrimaryKeyColumnConstraint): 212 return super().autoincrementcolumnconstraint_sql(expression) 213 214 self.unsupported("SQLite AUTOINCREMENT requires an INTEGER PRIMARY KEY") 215 return "" 216 217 def insert_sql(self, expression: exp.Insert) -> str: 218 if expression.args.get("ignore"): 219 expression.set("ignore", False) 220 expression.set("alternative", "IGNORE") 221 222 return super().insert_sql(expression) 223 224 def bitwiseandagg_sql(self, expression: exp.BitwiseAndAgg) -> str: 225 self.unsupported("BITWISE_AND aggregation is not supported in SQLite") 226 return self.function_fallback_sql(expression) 227 228 def bitwiseoragg_sql(self, expression: exp.BitwiseOrAgg) -> str: 229 self.unsupported("BITWISE_OR aggregation is not supported in SQLite") 230 return self.function_fallback_sql(expression) 231 232 def bitwisexoragg_sql(self, expression: exp.BitwiseXorAgg) -> str: 233 self.unsupported("BITWISE_XOR aggregation is not supported in SQLite") 234 return self.function_fallback_sql(expression) 235 236 def jsonextract_sql(self, expression: exp.JSONExtract) -> str: 237 if expression.expressions: 238 return self.function_fallback_sql(expression) 239 return arrow_json_extract_sql(self, expression) 240 241 def jsonextractscalar_sql(self, expression: exp.JSONExtractScalar) -> str: 242 if expression.args.get("json_subtype"): 243 # json_extract() keeps the JSON subtype on object/array results; 244 # ->> strips it, observable when the result feeds another JSON function 245 return self.func("JSON_EXTRACT", expression.this, expression.expression) 246 return arrow_json_extract_sql(self, expression) 247 248 def dateadd_sql(self, expression: exp.DateAdd) -> str: 249 modifier = expression.expression 250 unit = expression.args.get("unit") 251 # An INTERVAL amount carries its own unit, e.g. DATE_ADD(d, INTERVAL 1 DAY); 252 # unwrap it so the unit is not left inside the quoted modifier string. 253 if isinstance(modifier, exp.Interval): 254 unit = unit or modifier.unit 255 modifier = modifier.this 256 257 modifier = modifier.unnest() 258 if ( 259 unit 260 and not isinstance(modifier, exp.Literal) 261 and not (isinstance(modifier, exp.Neg) and modifier.this.is_number) 262 ): 263 return self.func( 264 "DATE", 265 expression.this, 266 exp.DPipe( 267 this=exp.paren(modifier), 268 expression=exp.Literal.string(f" {unit.name}"), 269 ), 270 ) 271 modifier = modifier.name if modifier.is_string else self.sql(modifier) 272 modifier = f"'{modifier} {unit.name}'" if unit else f"'{modifier}'" 273 return self.func("DATE", expression.this, modifier) 274 275 def cast_sql(self, expression: exp.Cast, safe_prefix: str | None = None) -> str: 276 if expression.is_type("date"): 277 return self.func("DATE", expression.this) 278 279 return super().cast_sql(expression) 280 281 # https://www.sqlite.org/gencol.html 282 # Inline unsupported check: mypyc cannot compile @unsupported_args on an 283 # override of an undecorated base-class method. 284 def computedcolumnconstraint_sql(self, expression: exp.ComputedColumnConstraint) -> str: 285 if expression.args.get("data_type"): 286 self.unsupported("SQLite generated columns do not support a data type") 287 288 this = expression.this 289 this_sql = self.sql(this) if isinstance(this, exp.Paren) else f"({self.sql(this)})" 290 storage = " STORED" if expression.args.get("persisted") else "" 291 not_null = " NOT NULL" if expression.args.get("not_null") else "" 292 return f"AS {this_sql}{storage}{not_null}" 293 294 # Note: SQLite's TRUNC always returns REAL (e.g., trunc(10.99) -> 10.0), not INTEGER. 295 # This creates a transpilation gap affecting division semantics, similar to Presto. 296 # Unlike Presto where this only affects decimals=0, SQLite has no decimals parameter 297 # so every use of TRUNC is affected. Modeling precisely would require exp.FloatTrunc. 298 @unsupported_args("decimals") 299 def trunc_sql(self, expression: exp.Trunc) -> str: 300 return self.func("TRUNC", expression.this) 301 302 def generateseries_sql(self, expression: exp.GenerateSeries) -> str: 303 parent = expression.parent 304 alias = parent and parent.args.get("alias") 305 306 if isinstance(alias, exp.TableAlias) and alias.columns: 307 column_alias = alias.columns[0] 308 alias.set("columns", None) 309 sql = self.sql( 310 exp.select(exp.alias_("value", column_alias)).from_(expression).subquery() 311 ) 312 else: 313 sql = self.function_fallback_sql(expression) 314 315 return sql 316 317 def datediff_sql(self, expression: exp.DateDiff) -> str: 318 unit = expression.args.get("unit") 319 unit = unit.name.upper() if unit else "DAY" 320 321 sql = f"(JULIANDAY({self.sql(expression, 'this')}) - JULIANDAY({self.sql(expression, 'expression')}))" 322 323 if unit == "MONTH": 324 sql = f"{sql} / 30.0" 325 elif unit == "YEAR": 326 sql = f"{sql} / 365.0" 327 elif unit == "HOUR": 328 sql = f"{sql} * 24.0" 329 elif unit == "MINUTE": 330 sql = f"{sql} * 1440.0" 331 elif unit == "SECOND": 332 sql = f"{sql} * 86400.0" 333 elif unit == "MILLISECOND": 334 sql = f"{sql} * 86400000.0" 335 elif unit == "MICROSECOND": 336 sql = f"{sql} * 86400000000.0" 337 elif unit == "NANOSECOND": 338 sql = f"{sql} * 86400000000000.0" 339 else: 340 self.unsupported(f"DATEDIFF unsupported for '{unit}'.") 341 342 return f"CAST({sql} AS INTEGER)" 343 344 def groupconcat_sql(self, expression: exp.GroupConcat) -> str: 345 node = expression.parent if isinstance(expression.parent, exp.Filter) else expression 346 window = node.parent 347 348 if ( 349 isinstance(expression.this, exp.Order) 350 and isinstance(window, exp.Window) 351 and window.this is node 352 ): 353 self.unsupported( 354 "SQLite GROUP_CONCAT window functions do not support argument ORDER BY" 355 ) 356 expression.set("this", expression.this.this) 357 358 return groupconcat_sql( 359 self, expression, func_name="GROUP_CONCAT", sep=None, within_group=False 360 ) 361 362 def _greatest_least_sql(self, expression: exp.Greatest | exp.Least) -> str: 363 if not expression.expressions: 364 return self.sql(expression, "this") 365 366 name = "MAX" if isinstance(expression, exp.Greatest) else "MIN" 367 368 if not expression.args.get("ignore_nulls"): 369 return rename_func(name)(self, expression) 370 371 # SQLite's multi-argument MAX/MIN return NULL if any argument is NULL. 372 # GREATEST(a, b, c) -> MAX(COALESCE(a, b, c), COALESCE(b, c, a), COALESCE(c, a, b)). 373 args = [expression.this, *expression.expressions] 374 375 coalesces = [] 376 for i in range(len(args)): 377 rotated = args[i:] + args[:i] 378 coalesces.append(exp.Coalesce(this=rotated[0], expressions=rotated[1:])) 379 380 return self.func(name, *coalesces) 381 382 def greatest_sql(self, expression: exp.Greatest) -> str: 383 return self._greatest_least_sql(expression) 384 385 def least_sql(self, expression: exp.Least) -> str: 386 return self._greatest_least_sql(expression) 387 388 def transaction_sql(self, expression: exp.Transaction) -> str: 389 this = expression.this 390 this = f" {this}" if this else "" 391 return f"BEGIN{this} TRANSACTION" 392 393 def isascii_sql(self, expression: exp.IsAscii) -> str: 394 return f"(NOT {self.sql(expression.this)} GLOB CAST(x'2a5b5e012d7f5d2a' AS TEXT))" 395 396 @unsupported_args("this") 397 def currentschema_sql(self, expression: exp.CurrentSchema) -> str: 398 return "'main'" 399 400 def ignorenulls_sql(self, expression: exp.IgnoreNulls) -> str: 401 self.unsupported("SQLite does not support IGNORE NULLS.") 402 return self.sql(expression.this) 403 404 def respectnulls_sql(self, expression: exp.RespectNulls) -> str: 405 return self.sql(expression.this) 406 407 def windowspec_sql(self, expression: exp.WindowSpec) -> str: 408 if ( 409 expression.text("kind").upper() == "RANGE" 410 and expression.text("start").upper() == "CURRENT ROW" 411 and expression.args.get("end") is None 412 ): 413 return "RANGE CURRENT ROW" 414 415 return super().windowspec_sql(expression)
Generator converts a given syntax tree to the corresponding SQL string.
Arguments:
- pretty: Whether 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: Always quote except for specials cases. 'safe': Only quote identifiers that are case insensitive.
- normalize: Whether to normalize identifiers to lowercase. Default: False.
- pad: The pad size in a formatted string. For example, this affects the indentation of a projection in a query, relative to its nesting level. Default: 2.
- indent: The indentation size in a formatted string. For example, this affects the
indentation of subqueries and filters under a
WHEREclause. Default: 2. - normalize_functions: How to normalize 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: Whether 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 to preserve comments in the output SQL code. Default: True
SUPPORTED_JSON_PATH_PARTS =
{<class 'sqlglot.expressions.query.JSONPathKey'>, <class 'sqlglot.expressions.query.JSONPathRoot'>, <class 'sqlglot.expressions.query.JSONPathSubscript'>}
TYPE_MAPPING =
{<DType.DATETIME2: 'DATETIME2'>: 'TIMESTAMP', <DType.NCHAR: 'NCHAR'>: 'TEXT', <DType.NVARCHAR: 'NVARCHAR'>: 'TEXT', <DType.MEDIUMTEXT: 'MEDIUMTEXT'>: 'TEXT', <DType.LONGTEXT: 'LONGTEXT'>: 'TEXT', <DType.TINYTEXT: 'TINYTEXT'>: 'TEXT', <DType.MEDIUMBLOB: 'MEDIUMBLOB'>: 'BLOB', <DType.LONGBLOB: 'LONGBLOB'>: 'BLOB', <DType.TINYBLOB: 'TINYBLOB'>: 'BLOB', <DType.INET: 'INET'>: 'INET', <DType.ROWVERSION: 'ROWVERSION'>: 'VARBINARY', <DType.SMALLDATETIME: 'SMALLDATETIME'>: 'TIMESTAMP', <DType.BOOLEAN: 'BOOLEAN'>: 'INTEGER', <DType.TINYINT: 'TINYINT'>: 'INTEGER', <DType.SMALLINT: 'SMALLINT'>: 'INTEGER', <DType.INT: 'INT'>: 'INTEGER', <DType.BIGINT: 'BIGINT'>: 'INTEGER', <DType.FLOAT: 'FLOAT'>: 'REAL', <DType.DOUBLE: 'DOUBLE'>: 'REAL', <DType.DECIMAL: 'DECIMAL'>: 'REAL', <DType.CHAR: 'CHAR'>: 'TEXT', <DType.VARCHAR: 'VARCHAR'>: 'TEXT', <DType.BINARY: 'BINARY'>: 'BLOB', <DType.VARBINARY: 'VARBINARY'>: 'BLOB'}
TRANSFORMS =
{<class 'sqlglot.expressions.query.JSONPathKey'>: <function <lambda>>, <class 'sqlglot.expressions.query.JSONPathRoot'>: <function <lambda>>, <class 'sqlglot.expressions.query.JSONPathSubscript'>: <function <lambda>>, <class 'sqlglot.expressions.core.Adjacent'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.AllowedValuesProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.query.AnalyzeColumns'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.query.AnalyzeWith'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.array.ArrayContainedBy'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.array.ArrayContainsAll'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.array.ArrayOverlaps'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.constraints.AssumeColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.AutoRefreshProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.BackupProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.constraints.BinaryColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.constraints.CaseSpecificColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.CalledOnNullInputProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.math.Ceil'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.constraints.CharacterSetColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.CharacterSetProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.constraints.ClusteredColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.constraints.CollateColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.constraints.CommentColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.functions.ConnectByRoot'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.string.ConvertToCharset'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.CopyGrantsProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.CredentialsProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.functions.CurrentCatalog'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.functions.SessionUser'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.constraints.DateFormatColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.constraints.DefaultColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.ApiProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.ApplicationProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.CatalogProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.ComputeProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.DatabaseProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.DynamicProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.EmptyProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.constraints.EncodeColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.query.EndStatement'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.EnviromentProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.HandlerProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.ParameterStyleProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.constraints.EphemeralColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.constraints.ExcludeColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.ExecuteAsProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.query.Except'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.ExternalProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.math.Floor'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.query.Get'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.GlobalProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.HeapProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.HybridProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.IcebergProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.InheritsProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.constraints.InlineLengthColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.InputModelProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.query.Intersect'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.datatypes.IntervalSpan'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.functions.Int64'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.json.JSONBContainsAnyTopKeys'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.json.JSONBContainsAllTopKeys'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.json.JSONBContainsTopKey'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.json.JSONBDeleteAtPath'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.json.JSONBPathExists'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.json.JSONObject'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.json.JSONObjectAgg'>: <function SQLiteGenerator.<lambda>>, <class 'sqlglot.expressions.properties.LanguageProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.LocationProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.LogProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.MaskingProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.MaterializedProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.functions.NetFunc'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.NetworkProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.constraints.NonClusteredColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.NoPrimaryIndexProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.constraints.NotForReplicationColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.OnCommitProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.OnProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.constraints.OnUpdateColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.core.Operator'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.OutputModelProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.core.ExtendsLeft'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.core.ExtendsRight'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.constraints.PathColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.PartitionedByBucket'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.PartitionByTruncate'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.core.PivotAny'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.array.PositionalColumn'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.constraints.ProjectionPolicyColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.constraints.InvisibleColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.constraints.ZeroFillColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.query.Put'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.RemoteWithConnectionModelProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.ReturnsProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.RowAccessProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.core.SafeFunc'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.SampleProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.SecureProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.SecurityIntegrationProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.SetConfigProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.SetProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.SettingsProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.SharingProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.SqlReadWriteProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.SqlSecurityProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.StabilityProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.query.Stream'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.StreamingTableProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.StrictProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.ddl.SwapTable'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.query.TableColumn'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.Tags'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.TemporaryProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.constraints.TitleColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.array.ToMap'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.ToTableProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.TransformModelProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.TransientProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.VirtualProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.ddl.TriggerExecute'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.query.Union'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.UnloggedProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.UsingTemplateProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.query.UsingData'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.constraints.UppercaseColumnConstraint'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.temporal.UtcDate'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.temporal.UtcTime'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.temporal.UtcTimestamp'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.query.Variadic'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.array.VarMap'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.ViewAttributeProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.VolatileProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.WithJournalTableProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.WithProcedureOptions'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.WithSchemaBindingProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.constraints.WithOperator'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.properties.ForceProperty'>: <function Generator.<lambda>>, <class 'sqlglot.expressions.aggregate.AnyValue'>: <function any_value_to_max_sql>, <class 'sqlglot.expressions.string.Chr'>: <function rename_func.<locals>.<lambda>>, <class 'sqlglot.expressions.aggregate.CountIf'>: <function count_if_to_sum>, <class 'sqlglot.expressions.ddl.Create'>: <function preprocess.<locals>._to_sql>, <class 'sqlglot.expressions.temporal.CurrentDate'>: <function SQLiteGenerator.<lambda>>, <class 'sqlglot.expressions.temporal.CurrentTime'>: <function SQLiteGenerator.<lambda>>, <class 'sqlglot.expressions.temporal.CurrentTimestamp'>: <function SQLiteGenerator.<lambda>>, <class 'sqlglot.expressions.functions.CurrentVersion'>: <function SQLiteGenerator.<lambda>>, <class 'sqlglot.expressions.query.ColumnDef'>: <function preprocess.<locals>._to_sql>, <class 'sqlglot.expressions.temporal.DateStrToDate'>: <function SQLiteGenerator.<lambda>>, <class 'sqlglot.expressions.functions.If'>: <function rename_func.<locals>.<lambda>>, <class 'sqlglot.expressions.core.ILike'>: <function no_ilike_sql>, <class 'sqlglot.expressions.json.JSONArrayAgg'>: <function rename_func.<locals>.<lambda>>, <class 'sqlglot.expressions.string.Levenshtein'>: <function rename_func.<locals>.<lambda>>, <class 'sqlglot.expressions.aggregate.LogicalOr'>: <function rename_func.<locals>.<lambda>>, <class 'sqlglot.expressions.aggregate.LogicalAnd'>: <function rename_func.<locals>.<lambda>>, <class 'sqlglot.expressions.query.Pivot'>: <function no_pivot_sql>, <class 'sqlglot.expressions.functions.Rand'>: <function rename_func.<locals>.<lambda>>, <class 'sqlglot.expressions.core.RegexpLike'>: <function SQLiteGenerator.<lambda>>, <class 'sqlglot.expressions.query.Select'>: <function preprocess.<locals>._to_sql>, <class 'sqlglot.expressions.string.StrPosition'>: <function SQLiteGenerator.<lambda>>, <class 'sqlglot.expressions.query.TableSample'>: <function no_tablesample_sql>, <class 'sqlglot.expressions.temporal.TimeStrToTime'>: <function SQLiteGenerator.<lambda>>, <class 'sqlglot.expressions.temporal.TimeToStr'>: <function SQLiteGenerator.<lambda>>, <class 'sqlglot.expressions.functions.TryCast'>: <function no_trycast_sql>, <class 'sqlglot.expressions.temporal.TsOrDsToTimestamp'>: <function SQLiteGenerator.<lambda>>}
PROPERTIES_LOCATION =
{<class 'sqlglot.expressions.properties.AllowedValuesProperty'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.AlgorithmProperty'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.ApiProperty'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.ApplicationProperty'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.AutoIncrementProperty'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.AutoRefreshProperty'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.BackupProperty'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.BlockCompressionProperty'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.CalledOnNullInputProperty'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.CatalogProperty'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.CharacterSetProperty'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.ChecksumProperty'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.CollateProperty'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.ComputeProperty'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.CopyGrantsProperty'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.query.Cluster'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.ClusteredByProperty'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.ClusterProperty'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.DistributedByProperty'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.DuplicateKeyProperty'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.DataBlocksizeProperty'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.DatabaseProperty'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.DataDeletionProperty'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.DefinerProperty'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.DictRange'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.DictProperty'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.DynamicProperty'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.DistKeyProperty'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.DistStyleProperty'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.EmptyProperty'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.EncodeProperty'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.EngineProperty'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.EnviromentProperty'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.HandlerProperty'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.ParameterStyleProperty'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.ExecuteAsProperty'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.ExternalProperty'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.FallbackProperty'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.FileFormatProperty'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.FreespaceProperty'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.GlobalProperty'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.HeapProperty'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.HybridProperty'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.InheritsProperty'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.IcebergProperty'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.IncludeProperty'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.InputModelProperty'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.IsolatedLoadingProperty'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.JournalProperty'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.LanguageProperty'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.LikeProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.LocationProperty'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.LockProperty'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.LockingProperty'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.LogProperty'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.MaskingProperty'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.MaterializedProperty'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.MergeBlockRatioProperty'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.ModuleProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.NetworkProperty'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.NoPrimaryIndexProperty'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.OnProperty'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.OnCommitProperty'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.query.Order'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.OutputModelProperty'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.PartitionedByProperty'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.PartitionedOfProperty'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.constraints.PrimaryKey'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.Property'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.RefreshTriggerProperty'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.RemoteWithConnectionModelProperty'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.ReturnsProperty'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.RollupProperty'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.RowAccessProperty'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.RowFormatProperty'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.RowFormatDelimitedProperty'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.RowFormatSerdeProperty'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.SampleProperty'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.SchemaCommentProperty'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.SecureProperty'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.SecurityIntegrationProperty'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.SerdeProperties'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.ddl.Set'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.SettingsProperty'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.SetProperty'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.SetConfigProperty'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.SharingProperty'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.ddl.SequenceProperties'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.ddl.TriggerProperties'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.SortKeyProperty'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.SqlReadWriteProperty'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.SqlSecurityProperty'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.StabilityProperty'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.StorageHandlerProperty'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.StreamingTableProperty'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.StrictProperty'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.Tags'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.TemporaryProperty'>: <PropertiesLocation.POST_CREATE: 'POST_CREATE'>, <class 'sqlglot.expressions.properties.ToTableProperty'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.TransientProperty'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.TransformModelProperty'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.ddl.MergeTreeTTL'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.UnloggedProperty'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.UsingProperty'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.UsingTemplateProperty'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.ViewAttributeProperty'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.VirtualProperty'>: <PropertiesLocation.POST_CREATE: 'POST_CREATE'>, <class 'sqlglot.expressions.properties.VolatileProperty'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.WithDataProperty'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.WithJournalTableProperty'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.WithProcedureOptions'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.WithSchemaBindingProperty'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.WithSystemVersioningProperty'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.ForceProperty'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>}
def
autoincrementcolumnconstraint_sql( self, expression: sqlglot.expressions.constraints.AutoIncrementColumnConstraint) -> str:
207 def autoincrementcolumnconstraint_sql( 208 self, expression: exp.AutoIncrementColumnConstraint 209 ) -> str: 210 column = expression.find_ancestor(exp.ColumnDef) 211 if column and column.find(exp.PrimaryKeyColumnConstraint): 212 return super().autoincrementcolumnconstraint_sql(expression) 213 214 self.unsupported("SQLite AUTOINCREMENT requires an INTEGER PRIMARY KEY") 215 return ""
241 def jsonextractscalar_sql(self, expression: exp.JSONExtractScalar) -> str: 242 if expression.args.get("json_subtype"): 243 # json_extract() keeps the JSON subtype on object/array results; 244 # ->> strips it, observable when the result feeds another JSON function 245 return self.func("JSON_EXTRACT", expression.this, expression.expression) 246 return arrow_json_extract_sql(self, expression)
248 def dateadd_sql(self, expression: exp.DateAdd) -> str: 249 modifier = expression.expression 250 unit = expression.args.get("unit") 251 # An INTERVAL amount carries its own unit, e.g. DATE_ADD(d, INTERVAL 1 DAY); 252 # unwrap it so the unit is not left inside the quoted modifier string. 253 if isinstance(modifier, exp.Interval): 254 unit = unit or modifier.unit 255 modifier = modifier.this 256 257 modifier = modifier.unnest() 258 if ( 259 unit 260 and not isinstance(modifier, exp.Literal) 261 and not (isinstance(modifier, exp.Neg) and modifier.this.is_number) 262 ): 263 return self.func( 264 "DATE", 265 expression.this, 266 exp.DPipe( 267 this=exp.paren(modifier), 268 expression=exp.Literal.string(f" {unit.name}"), 269 ), 270 ) 271 modifier = modifier.name if modifier.is_string else self.sql(modifier) 272 modifier = f"'{modifier} {unit.name}'" if unit else f"'{modifier}'" 273 return self.func("DATE", expression.this, modifier)
def
cast_sql( self, expression: sqlglot.expressions.functions.Cast, safe_prefix: str | None = None) -> str:
def
computedcolumnconstraint_sql( self, expression: sqlglot.expressions.constraints.ComputedColumnConstraint) -> str:
284 def computedcolumnconstraint_sql(self, expression: exp.ComputedColumnConstraint) -> str: 285 if expression.args.get("data_type"): 286 self.unsupported("SQLite generated columns do not support a data type") 287 288 this = expression.this 289 this_sql = self.sql(this) if isinstance(this, exp.Paren) else f"({self.sql(this)})" 290 storage = " STORED" if expression.args.get("persisted") else "" 291 not_null = " NOT NULL" if expression.args.get("not_null") else "" 292 return f"AS {this_sql}{storage}{not_null}"
@unsupported_args('decimals')
def
trunc_sql(self, expression: sqlglot.expressions.math.Trunc) -> str:
302 def generateseries_sql(self, expression: exp.GenerateSeries) -> str: 303 parent = expression.parent 304 alias = parent and parent.args.get("alias") 305 306 if isinstance(alias, exp.TableAlias) and alias.columns: 307 column_alias = alias.columns[0] 308 alias.set("columns", None) 309 sql = self.sql( 310 exp.select(exp.alias_("value", column_alias)).from_(expression).subquery() 311 ) 312 else: 313 sql = self.function_fallback_sql(expression) 314 315 return sql
317 def datediff_sql(self, expression: exp.DateDiff) -> str: 318 unit = expression.args.get("unit") 319 unit = unit.name.upper() if unit else "DAY" 320 321 sql = f"(JULIANDAY({self.sql(expression, 'this')}) - JULIANDAY({self.sql(expression, 'expression')}))" 322 323 if unit == "MONTH": 324 sql = f"{sql} / 30.0" 325 elif unit == "YEAR": 326 sql = f"{sql} / 365.0" 327 elif unit == "HOUR": 328 sql = f"{sql} * 24.0" 329 elif unit == "MINUTE": 330 sql = f"{sql} * 1440.0" 331 elif unit == "SECOND": 332 sql = f"{sql} * 86400.0" 333 elif unit == "MILLISECOND": 334 sql = f"{sql} * 86400000.0" 335 elif unit == "MICROSECOND": 336 sql = f"{sql} * 86400000000.0" 337 elif unit == "NANOSECOND": 338 sql = f"{sql} * 86400000000000.0" 339 else: 340 self.unsupported(f"DATEDIFF unsupported for '{unit}'.") 341 342 return f"CAST({sql} AS INTEGER)"
344 def groupconcat_sql(self, expression: exp.GroupConcat) -> str: 345 node = expression.parent if isinstance(expression.parent, exp.Filter) else expression 346 window = node.parent 347 348 if ( 349 isinstance(expression.this, exp.Order) 350 and isinstance(window, exp.Window) 351 and window.this is node 352 ): 353 self.unsupported( 354 "SQLite GROUP_CONCAT window functions do not support argument ORDER BY" 355 ) 356 expression.set("this", expression.this.this) 357 358 return groupconcat_sql( 359 self, expression, func_name="GROUP_CONCAT", sep=None, within_group=False 360 )
@unsupported_args('this')
def
currentschema_sql(self, expression: sqlglot.expressions.functions.CurrentSchema) -> str:
407 def windowspec_sql(self, expression: exp.WindowSpec) -> str: 408 if ( 409 expression.text("kind").upper() == "RANGE" 410 and expression.text("start").upper() == "CURRENT ROW" 411 and expression.args.get("end") is None 412 ): 413 return "RANGE CURRENT ROW" 414 415 return super().windowspec_sql(expression)
Inherited Members
- sqlglot.generator.Generator
- Generator
- NULL_ORDERING_SUPPORTED
- WINDOW_FUNCS_WITH_NULL_ORDERING
- IGNORE_NULLS_IN_FUNC
- IGNORE_NULLS_BEFORE_ORDER
- LOCKING_READS_SUPPORTED
- WRAP_DERIVED_VALUES
- CREATE_FUNCTION_RETURN_AS
- MATCHED_BY_SOURCE
- SUPPORTS_MERGE_WHERE
- SINGLE_STRING_INTERVAL
- INTERVAL_ALLOWS_PLURAL_FORM
- AUTO_REFRESH_BARE_INTERVALS
- LIMIT_ONLY_LITERALS
- RENAME_TABLE_WITH_DB
- GROUPINGS_SEP
- SUPPORTS_GROUPING_SETS_AS_SUFFIX
- INDEX_ON
- INOUT_SEPARATOR
- DIRECTED_JOINS
- QUERY_HINT_SEP
- IS_BOOL_ALLOWED
- DUPLICATE_KEY_UPDATE_WITH_SET
- LIMIT_IS_TOP
- RETURNING_END
- EXTRACT_ALLOWS_QUOTES
- TZ_TO_WITH_TIME_ZONE
- VALUES_AS_TABLE
- ALTER_TABLE_INCLUDE_COLUMN_KEYWORD
- UNNEST_WITH_ORDINALITY
- SEMI_ANTI_JOIN_WITH_SIDE
- COMPUTED_COLUMN_WITH_TYPE
- SUPPORTS_TABLE_COPY
- TABLESAMPLE_REQUIRES_PARENS
- TABLESAMPLE_SIZE_IS_ROWS
- TABLESAMPLE_KEYWORDS
- TABLESAMPLE_WITH_METHOD
- TABLESAMPLE_SEED_KEYWORD
- HISTORICAL_DATA_POST_ALIAS
- COLLATE_IS_FUNC
- DATA_TYPE_SPECIFIERS_ALLOWED
- ENSURE_BOOLS
- CTE_RECURSIVE_KEYWORD_REQUIRED
- SUPPORTS_SINGLE_ARG_CONCAT
- LAST_DAY_SUPPORTS_DATE_PART
- SUPPORTS_NAMED_CTE_COLUMNS
- UNPIVOT_ALIASES_ARE_IDENTIFIERS
- PIVOT_ALIAS_WITH_AS
- INSERT_OVERWRITE
- SUPPORTS_SELECT_INTO
- SUPPORTS_UNLOGGED_TABLES
- SUPPORTS_MODIFY_COLUMN
- SUPPORTS_CHANGE_COLUMN
- SUPPORTS_ALTER_COLUMN_NULLABILITY
- SUPPORTS_ALTER_COLUMN_IF_EXISTS
- LIKE_PROPERTY_INSIDE_SCHEMA
- MULTI_ARG_DISTINCT
- JSON_TYPE_REQUIRED_FOR_EXTRACTION
- JSON_PATH_SINGLE_QUOTE_ESCAPE
- JSON_PATH_KEY_QUOTED_FORCES_BRACKETS
- CAN_IMPLEMENT_ARRAY_ANY
- SET_OP_MODIFIERS
- SET_OP_LIMITS
- COPY_PARAMS_ARE_WRAPPED
- COPY_PARAMS_EQ_REQUIRED
- COPY_HAS_INTO_KEYWORD
- UNICODE_SUBSTITUTE
- STAR_EXCEPT
- HEX_FUNC
- WITH_PROPERTIES_PREFIX
- QUOTE_JSON_PATH
- PAD_FILL_PATTERN_IS_REQUIRED
- SUPPORTS_EXPLODING_PROJECTIONS
- ARRAY_CONCAT_IS_VAR_LEN
- SUPPORTS_CONVERT_TIMEZONE
- SUPPORTS_UNIX_SECONDS
- ALTER_SET_WRAPPED
- NORMALIZE_EXTRACT_DATE_PARTS
- ARRAY_SIZE_NAME
- ALTER_SET_TYPE
- ARRAY_SIZE_DIM_REQUIRED
- SUPPORTS_BETWEEN_FLAGS
- SUPPORTS_LIKE_QUANTIFIERS
- MATCH_AGAINST_TABLE_PREFIX
- SET_ASSIGNMENT_REQUIRES_VARIABLE_KEYWORD
- DECLARE_DEFAULT_ASSIGNMENT
- UPDATE_STATEMENT_SUPPORTS_FROM
- STAR_EXCLUDE_REQUIRES_DERIVED_TABLE
- SUPPORTS_DROP_ALTER_ICEBERG_PROPERTY
- UNSUPPORTED_TYPES
- TYPE_PARAM_SETTINGS
- TIME_PART_SINGULARS
- STRUCT_DELIMITER
- PARAMETER_TOKEN
- NAMED_PLACEHOLDER_TOKEN
- EXPRESSION_PRECEDES_PROPERTIES_CREATABLES
- RESERVED_KEYWORDS
- WITH_SEPARATED_COMMENTS
- EXCLUDE_COMMENTS
- UNWRAPPED_INTERVAL_VALUES
- PARAMETERIZABLE_TEXT_TYPES
- EXPRESSIONS_WITHOUT_NESTED_CTES
- RESPECT_IGNORE_NULLS_UNSUPPORTED_EXPRESSIONS
- MOD_OPERATOR
- MOD_PAREN_PARENT_TYPES
- SAFE_JSON_PATH_KEY_RE
- SENTINEL_LINE_BREAK
- pretty
- identify
- normalize
- pad
- unsupported_level
- max_unsupported
- leading_comma
- max_text_width
- comments
- dialect
- normalize_functions
- unsupported_messages
- generate
- preprocess
- unsupported
- sep
- seg
- sanitize_comment
- maybe_comment
- wrap
- no_identify
- normalize_func
- indent
- sql
- uncache_sql
- cache_sql
- characterset_sql
- column_parts
- column_sql
- pseudocolumn_sql
- columnposition_sql
- columndef_sql
- columnconstraint_sql
- compresscolumnconstraint_sql
- generatedasidentitycolumnconstraint_sql
- generatedasrowcolumnconstraint_sql
- periodforsystemtimeconstraint_sql
- notnullcolumnconstraint_sql
- primarykeycolumnconstraint_sql
- uniquecolumnconstraint_sql
- inoutcolumnconstraint_sql
- createable_sql
- create_sql
- sequenceproperties_sql
- triggerproperties_sql
- triggerreferencing_sql
- triggerevent_sql
- clone_sql
- describe_sql
- heredoc_sql
- prepend_ctes
- with_sql
- cte_sql
- tablealias_sql
- bitstring_sql
- hexstring_sql
- bytestring_sql
- unicodestring_sql
- rawstring_sql
- datatypeparam_sql
- datatype_param_bound_limiter
- datatype_sql
- directory_sql
- delete_sql
- drop_sql
- set_operation
- set_operations
- fetch_sql
- limitoptions_sql
- filter_sql
- hint_sql
- indexparameters_sql
- index_sql
- dynamicidentifier_sql
- identifier_sql
- hex_sql
- lowerhex_sql
- inputoutputformat_sql
- national_sql
- partition_sql
- properties_sql
- root_properties
- properties
- with_properties
- locate_properties
- property_name
- property_sql
- uuidproperty_sql
- likeproperty_sql
- fallbackproperty_sql
- journalproperty_sql
- freespaceproperty_sql
- checksumproperty_sql
- mergeblockratioproperty_sql
- moduleproperty_sql
- datablocksizeproperty_sql
- blockcompressionproperty_sql
- isolatedloadingproperty_sql
- partitionboundspec_sql
- partitionedofproperty_sql
- lockingproperty_sql
- withdataproperty_sql
- withsystemversioningproperty_sql
- introducer_sql
- kill_sql
- pseudotype_sql
- objectidentifier_sql
- onconflict_sql
- returning_sql
- rowformatdelimitedproperty_sql
- withtablehint_sql
- indextablehint_sql
- historicaldata_sql
- table_parts
- table_sql
- tablefromrows_sql
- tablesample_sql
- pivot_sql
- version_sql
- tuple_sql
- update_sql
- values_sql
- var_sql
- into_sql
- from_sql
- groupingsets_sql
- rollup_sql
- rollupindex_sql
- rollupproperty_sql
- cube_sql
- group_sql
- having_sql
- connect_sql
- prior_sql
- join_sql
- lambda_sql
- lateral_op
- lateral_sql
- limit_sql
- offset_sql
- setitem_sql
- set_sql
- queryband_sql
- pragma_sql
- lock_sql
- literal_sql
- escape_str
- loaddata_sql
- null_sql
- boolean_sql
- booland_sql
- boolor_sql
- order_sql
- withfill_sql
- cluster_sql
- clusterproperty_sql
- distribute_sql
- sort_sql
- ordered_sql
- matchrecognizemeasure_sql
- matchrecognize_sql
- query_modifiers
- options_modifier
- forclause_sql
- queryoption_sql
- offset_limit_modifiers
- after_limit_modifiers
- select_sql
- schema_sql
- schema_columns_sql
- star_sql
- parameter_sql
- sessionparameter_sql
- placeholder_sql
- subquery_sql
- qualify_sql
- unnest_sql
- prewhere_sql
- where_sql
- window_sql
- partition_by_sql
- withingroup_sql
- between_sql
- bracket_offset_expressions
- bracket_sql
- all_sql
- any_sql
- exists_sql
- case_sql
- constraint_sql
- nextvaluefor_sql
- extract_sql
- trim_sql
- convert_concat_args
- concat_sql
- concatws_sql
- check_sql
- foreignkey_sql
- primarykey_sql
- timeserieskey_sql
- if_sql
- matchagainst_sql
- jsonkeyvalue_sql
- jsonpath_sql
- json_path_part
- formatjson_sql
- formatphrase_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
- pivotalias_sql
- aliases_sql
- atindex_sql
- attimezone_sql
- fromtimezone_sql
- fromiso8601date_sql
- fromiso8601timestamp_sql
- fromiso8601timestampnanos_sql
- add_sql
- and_sql
- or_sql
- xor_sql
- connector_sql
- bitwiseand_sql
- bitwiseleftshift_sql
- bitwisenot_sql
- bitwiseor_sql
- bitwiserightshift_sql
- bitwisexor_sql
- strtotime_sql
- strtodate_sql
- parsedatetime_sql
- currentdate_sql
- collate_sql
- command_sql
- comment_sql
- mergetreettlaction_sql
- mergetreettl_sql
- commit_sql
- rollback_sql
- altercolumn_sql
- modifycolumn_sql
- alterindex_sql
- alterdiststyle_sql
- altersortkey_sql
- alterrename_sql
- renamecolumn_sql
- alterset_sql
- alter_sql
- altersession_sql
- add_column_sql
- droppartition_sql
- dropprimarykey_sql
- addconstraint_sql
- addpartition_sql
- distinct_sql
- havingmax_sql
- intdiv_sql
- dpipe_sql
- div_sql
- safedivide_sql
- overlaps_sql
- distance_sql
- distancend_sql
- dot_sql
- eq_sql
- propertyeq_sql
- escape_sql
- glob_sql
- gt_sql
- gte_sql
- is_sql
- like_sql
- ilike_sql
- match_sql
- similarto_sql
- lt_sql
- lte_sql
- mod_sql
- mul_sql
- neq_sql
- nullsafeeq_sql
- nullsafeneq_sql
- sub_sql
- trycast_sql
- jsoncast_sql
- try_sql
- log_sql
- use_sql
- binary
- ceil_floor
- function_fallback_sql
- func
- format_args
- too_wide
- format_time
- expressions
- op_expressions
- naked_property
- tag_sql
- token_sql
- userdefinedfunction_sql
- macrooverloads_sql
- macrooverload_sql
- joinhint_sql
- kwarg_sql
- when_sql
- whens_sql
- merge_sql
- tochar_sql
- tonumber_sql
- dictproperty_sql
- dictrange_sql
- dictsubproperty_sql
- duplicatekeyproperty_sql
- uniquekeyproperty_sql
- distributedbyproperty_sql
- oncluster_sql
- clusteredbyproperty_sql
- anyvalue_sql
- querytransform_sql
- indexconstraintoption_sql
- checkcolumnconstraint_sql
- indexcolumnconstraint_sql
- nvl2_sql
- nthvalue_sql
- comprehension_sql
- columnprefix_sql
- opclass_sql
- predict_sql
- generateembedding_sql
- generatetext_sql
- generatetable_sql
- generatebool_sql
- generateint_sql
- generatedouble_sql
- mltranslate_sql
- mlforecast_sql
- aiforecast_sql
- featuresattime_sql
- vectorsearch_sql
- forin_sql
- refresh_sql
- toarray_sql
- tsordstotime_sql
- tsordstotimestamp_sql
- tsordstodatetime_sql
- tsordstodate_sql
- unixdate_sql
- lastday_sql
- arrayinsert_sql
- arrayany_sql
- struct_sql
- partitionrange_sql
- truncatetable_sql
- convert_sql
- copyparameter_sql
- credentials_sql
- copy_sql
- semicolon_sql
- datadeletionproperty_sql
- maskingpolicycolumnconstraint_sql
- gapfill_sql
- scope_resolution
- scoperesolution_sql
- parsejson_sql
- rand_sql
- changes_sql
- pad_sql
- summarize_sql
- explodinggenerateseries_sql
- converttimezone_sql
- json_sql
- jsonvalue_sql
- skipjsoncolumn_sql
- conditionalinsert_sql
- multitableinserts_sql
- oncondition_sql
- jsonextractquote_sql
- jsonexists_sql
- arrayagg_sql
- slice_sql
- apply_sql
- grant_sql
- revoke_sql
- grantprivilege_sql
- grantprincipal_sql
- columns_sql
- overlay_sql
- todouble_sql
- string_sql
- median_sql
- overflowtruncatebehavior_sql
- unixseconds_sql
- arraysize_sql
- attach_sql
- detach_sql
- attachoption_sql
- watermarkcolumnconstraint_sql
- encodeproperty_sql
- includeproperty_sql
- xmlelement_sql
- xmlkeyvalueoption_sql
- partitionbyrangeproperty_sql
- partitionbyrangepropertydynamic_sql
- unpivotcolumns_sql
- analyzesample_sql
- analyzestatistics_sql
- analyzehistogram_sql
- analyzedelete_sql
- analyzelistchainedrows_sql
- analyzevalidate_sql
- analyze_sql
- xmltable_sql
- xmlnamespace_sql
- export_sql
- declare_sql
- declareitem_sql
- recursivewithsearch_sql
- parameterizedagg_sql
- anonymousaggfunc_sql
- combinedaggfunc_sql
- combinedparameterizedagg_sql
- show_sql
- install_sql
- get_put_sql
- translatecharacters_sql
- decodecase_sql
- semanticview_sql
- getextract_sql
- datefromunixdate_sql
- space_sql
- buildproperty_sql
- refreshtriggerproperty_sql
- modelattribute_sql
- directorystage_sql
- uuid_sql
- initcap_sql
- localtime_sql
- localtimestamp_sql
- weekstart_name
- weekstart_sql
- chr_sql
- block_sql
- functionspecification_sql
- storedprocedure_sql
- ifblock_sql
- casestatement_sql
- whileblock_sql
- loopblock_sql
- repeatblock_sql
- leave_sql
- iterate_sql
- execute_sql
- executesql_sql
- altermodifysqlsecurity_sql
- usingproperty_sql
- renameindex_sql