sqlglot.generators.postgres
1from __future__ import annotations 2 3import typing as t 4 5from sqlglot import exp, generator, transforms 6from sqlglot.dialects.dialect import ( 7 DATE_ADD_OR_SUB, 8 JSON_EXTRACT_TYPE, 9 any_value_to_max_sql, 10 array_append_sql, 11 array_concat_sql, 12 bool_xor_sql, 13 count_if_to_sum, 14 datestrtodate_sql, 15 filter_array_using_unnest, 16 generate_series_sql, 17 getbit_sql, 18 groupconcat_sql, 19 inline_array_sql, 20 json_extract_segments, 21 json_path_key_only_name, 22 max_or_greatest, 23 merge_without_target_sql, 24 min_or_least, 25 no_last_day_sql, 26 no_map_from_entries_sql, 27 no_paren_current_date_sql, 28 no_pivot_sql, 29 no_trycast_sql, 30 regexp_replace_global_modifier, 31 rename_func, 32 sha256_sql, 33 sha2_digest_sql, 34 strposition_sql, 35 struct_extract_sql, 36 timestamptrunc_sql, 37 timestrtotime_sql, 38 trim_sql, 39 ts_or_ds_add_cast, 40) 41from sqlglot.generator import unsupported_args 42from sqlglot.helper import seq_get 43 44 45DATE_DIFF_FACTOR = { 46 "MICROSECOND": " * 1000000", 47 "MILLISECOND": " * 1000", 48 "SECOND": "", 49 "MINUTE": " / 60", 50 "HOUR": " / 3600", 51 "DAY": " / 86400", 52} 53 54 55def _date_add_sql(kind: str) -> t.Callable[[PostgresGenerator, DATE_ADD_OR_SUB], str]: 56 def func(self: PostgresGenerator, expression: DATE_ADD_OR_SUB) -> str: 57 if isinstance(expression, exp.TsOrDsAdd): 58 expression = ts_or_ds_add_cast(expression) 59 60 this = self.sql(expression, "this") 61 unit = expression.args.get("unit") 62 63 e = self._simplify_unless_literal(expression.expression) 64 if isinstance(e, exp.Interval): 65 return f"{this} {kind} {self.sql(e)}" 66 elif isinstance(e, exp.Literal): 67 e.set("is_string", True) 68 elif e.is_number: 69 e = exp.Literal.string(e.to_py()) 70 else: 71 one = exp.Literal.number(1) 72 interval_times_value = exp.Interval(this=one, unit=unit) * e 73 return f"{this} {kind} {self.sql(interval_times_value)}" 74 75 return f"{this} {kind} {self.sql(exp.Interval(this=e, unit=unit))}" 76 77 return func 78 79 80def _day_month_year_sql(self: PostgresGenerator, expression: exp.Day | exp.Month | exp.Year) -> str: 81 this = expression.this 82 value = this.this if isinstance(this, exp.TsOrDsToDate) else this 83 84 if value.is_type(*exp.DataType.INTEGER_TYPES) and ( 85 default_date := this.args.get("default_date") 86 ): 87 this = exp.cast(default_date, exp.DType.DATE) + value 88 89 return self.sql(exp.Extract(this=exp.var(expression.sql_name()), expression=this)) 90 91 92def _date_diff_sql(self: PostgresGenerator, expression: exp.DateDiff | exp.TsOrDsDiff) -> str: 93 unit = expression.text("unit").upper() or "DAY" 94 95 # Dialects like MySQL count crossed day boundaries, which maps to DATE subtraction 96 if unit == "DAY" and expression.args.get("date_part_boundary"): 97 this = exp.cast(expression.this, exp.DType.DATE) 98 expr = exp.cast(expression.expression, exp.DType.DATE) 99 return self.sql(exp.paren(this - expr)) 100 101 factor = DATE_DIFF_FACTOR.get(unit) 102 103 end = f"CAST({self.sql(expression, 'this')} AS TIMESTAMP)" 104 start = f"CAST({self.sql(expression, 'expression')} AS TIMESTAMP)" 105 106 if factor is not None: 107 return f"CAST(EXTRACT(epoch FROM {end} - {start}){factor} AS BIGINT)" 108 109 age = f"AGE({end}, {start})" 110 111 if unit == "WEEK": 112 unit = f"EXTRACT(days FROM ({end} - {start})) / 7" 113 elif unit == "MONTH": 114 unit = f"EXTRACT(year FROM {age}) * 12 + EXTRACT(month FROM {age})" 115 elif unit == "QUARTER": 116 unit = f"EXTRACT(year FROM {age}) * 4 + EXTRACT(month FROM {age}) / 3" 117 elif unit == "YEAR": 118 unit = f"EXTRACT(year FROM {age})" 119 else: 120 unit = age 121 122 return f"CAST({unit} AS BIGINT)" 123 124 125def _substring_sql(self: PostgresGenerator, expression: exp.Substring) -> str: 126 this = self.sql(expression, "this") 127 start = self.sql(expression, "start") 128 length = self.sql(expression, "length") 129 130 from_part = f" FROM {start}" if start else "" 131 for_part = f" FOR {length}" if length else "" 132 133 return f"SUBSTRING({this}{from_part}{for_part})" 134 135 136def _auto_increment_to_serial(expression: exp.Expr) -> exp.Expr: 137 auto = expression.find(exp.AutoIncrementColumnConstraint) 138 139 if auto: 140 expression.args["constraints"].remove(auto.parent) 141 kind = expression.args["kind"] 142 143 if kind.this == exp.DType.INT: 144 kind.replace(exp.DataType(this=exp.DType.SERIAL)) 145 elif kind.this == exp.DType.SMALLINT: 146 kind.replace(exp.DataType(this=exp.DType.SMALLSERIAL)) 147 elif kind.this == exp.DType.BIGINT: 148 kind.replace(exp.DataType(this=exp.DType.BIGSERIAL)) 149 150 return expression 151 152 153def _serial_to_generated(expression: exp.Expr) -> exp.Expr: 154 if not isinstance(expression, exp.ColumnDef): 155 return expression 156 kind = expression.kind 157 if not kind: 158 return expression 159 160 if kind.this == exp.DType.SERIAL: 161 data_type = exp.DataType(this=exp.DType.INT) 162 elif kind.this == exp.DType.SMALLSERIAL: 163 data_type = exp.DataType(this=exp.DType.SMALLINT) 164 elif kind.this == exp.DType.BIGSERIAL: 165 data_type = exp.DataType(this=exp.DType.BIGINT) 166 else: 167 data_type = None 168 169 if data_type: 170 expression.args["kind"].replace(data_type) 171 constraints = expression.args["constraints"] 172 generated = exp.ColumnConstraint(kind=exp.GeneratedAsIdentityColumnConstraint(this=False)) 173 notnull = exp.ColumnConstraint(kind=exp.NotNullColumnConstraint()) 174 175 if notnull not in constraints: 176 constraints.insert(0, notnull) 177 if generated not in constraints: 178 constraints.insert(0, generated) 179 180 return expression 181 182 183def _json_extract_sql( 184 name: str, op: str 185) -> t.Callable[[PostgresGenerator, JSON_EXTRACT_TYPE], str]: 186 def _generate(self: PostgresGenerator, expression: JSON_EXTRACT_TYPE) -> str: 187 if expression.args.get("only_json_types"): 188 return json_extract_segments(name, quoted_index=False, op=op)(self, expression) 189 return json_extract_segments(name)(self, expression) 190 191 return _generate 192 193 194def _unix_to_time_sql(self: PostgresGenerator, expression: exp.UnixToTime) -> str: 195 scale = expression.args.get("scale") 196 timestamp = expression.this 197 198 if scale in (None, exp.UnixToTime.SECONDS): 199 return self.func("TO_TIMESTAMP", timestamp, self.format_time(expression)) 200 201 return self.func( 202 "TO_TIMESTAMP", 203 exp.Div(this=timestamp, expression=exp.func("POW", 10, scale)), 204 self.format_time(expression), 205 ) 206 207 208def _levenshtein_sql(self: PostgresGenerator, expression: exp.Levenshtein) -> str: 209 name = "LEVENSHTEIN_LESS_EQUAL" if expression.args.get("max_dist") else "LEVENSHTEIN" 210 211 return rename_func(name)(self, expression) 212 213 214def _versioned_anyvalue_sql(self: PostgresGenerator, expression: exp.AnyValue) -> str: 215 # https://www.postgresql.org/docs/16/functions-aggregate.html 216 # https://www.postgresql.org/about/featurematrix/ 217 if self.dialect.version < (16,): 218 return any_value_to_max_sql(self, expression) 219 220 return rename_func("ANY_VALUE")(self, expression) 221 222 223def _round_sql(self: PostgresGenerator, expression: exp.Round) -> str: 224 this = self.sql(expression, "this") 225 decimals = self.sql(expression, "decimals") 226 227 if not decimals: 228 return self.func("ROUND", this) 229 230 if not expression.type: 231 from sqlglot.optimizer.annotate_types import annotate_types 232 233 expression = annotate_types(expression, dialect=self.dialect) 234 235 # ROUND(double precision, integer) is not permitted in Postgres 236 # so it's necessary to cast to decimal before rounding. 237 if expression.this.is_type(exp.DType.DOUBLE): 238 decimal_type = exp.DType.DECIMAL.into_expr(expressions=expression.expressions) 239 this = self.sql(exp.Cast(this=this, to=decimal_type)) 240 241 return self.func("ROUND", this, decimals) 242 243 244class PostgresGenerator(generator.Generator): 245 SELECT_KINDS: tuple[str, ...] = () 246 TRY_SUPPORTED = False 247 SUPPORTS_DECODE_CASE = False 248 249 AFTER_HAVING_MODIFIER_TRANSFORMS = generator.AFTER_HAVING_MODIFIER_TRANSFORMS 250 251 SINGLE_STRING_INTERVAL = True 252 RENAME_TABLE_WITH_DB = False 253 LOCKING_READS_SUPPORTED = True 254 JOIN_HINTS = False 255 TABLE_HINTS = False 256 QUERY_HINTS = False 257 NVL2_SUPPORTED = False 258 PARAMETER_TOKEN = "$" 259 NAMED_PLACEHOLDER_TOKEN = "%" 260 TABLESAMPLE_SIZE_IS_ROWS = False 261 TABLESAMPLE_SEED_KEYWORD = "REPEATABLE" 262 SUPPORTS_SELECT_INTO = True 263 JSON_TYPE_REQUIRED_FOR_EXTRACTION = True 264 SUPPORTS_UNLOGGED_TABLES = True 265 LIKE_PROPERTY_INSIDE_SCHEMA = True 266 MULTI_ARG_DISTINCT = False 267 CAN_IMPLEMENT_ARRAY_ANY = True 268 SUPPORTS_WINDOW_EXCLUDE = True 269 COPY_HAS_INTO_KEYWORD = False 270 ARRAY_CONCAT_IS_VAR_LEN = False 271 SUPPORTS_MEDIAN = False 272 ARRAY_SIZE_DIM_REQUIRED: bool | None = True 273 SUPPORTS_BETWEEN_FLAGS = True 274 INOUT_SEPARATOR = "" # PostgreSQL uses "INOUT" (no space) 275 276 SUPPORTED_JSON_PATH_PARTS = { 277 exp.JSONPathKey, 278 exp.JSONPathRoot, 279 exp.JSONPathSubscript, 280 } 281 282 def lateral_sql(self, expression: exp.Lateral) -> str: 283 sql = super().lateral_sql(expression) 284 285 if expression.args.get("cross_apply") is not None: 286 sql = f"{sql} ON TRUE" 287 288 return sql 289 290 TYPE_MAPPING = { 291 **generator.Generator.TYPE_MAPPING, 292 exp.DType.TINYINT: "SMALLINT", 293 exp.DType.FLOAT: "REAL", 294 exp.DType.DOUBLE: "DOUBLE PRECISION", 295 exp.DType.BINARY: "BYTEA", 296 exp.DType.VARBINARY: "BYTEA", 297 exp.DType.ROWVERSION: "BYTEA", 298 exp.DType.DATETIME: "TIMESTAMP", 299 exp.DType.TIMESTAMPNTZ: "TIMESTAMP", 300 exp.DType.BLOB: "BYTEA", 301 } 302 303 TRANSFORMS = { 304 **{ 305 k: v 306 for k, v in generator.Generator.TRANSFORMS.items() 307 if k != exp.CommentColumnConstraint 308 }, 309 exp.AnyValue: _versioned_anyvalue_sql, 310 exp.ArrayConcat: array_concat_sql("ARRAY_CAT"), 311 exp.ArrayFilter: filter_array_using_unnest, 312 exp.ArrayAppend: array_append_sql("ARRAY_APPEND"), 313 exp.ArrayPrepend: array_append_sql("ARRAY_PREPEND", swap_params=True), 314 exp.BitwiseAndAgg: rename_func("BIT_AND"), 315 exp.BitwiseOrAgg: rename_func("BIT_OR"), 316 exp.BitwiseXor: lambda self, e: self.binary(e, "#"), 317 exp.BitwiseXorAgg: rename_func("BIT_XOR"), 318 exp.ColumnDef: transforms.preprocess([_auto_increment_to_serial, _serial_to_generated]), 319 exp.CurrentDate: no_paren_current_date_sql, 320 exp.CurrentTimestamp: lambda *_: "CURRENT_TIMESTAMP", 321 exp.CurrentUser: lambda *_: "CURRENT_USER", 322 exp.CurrentVersion: rename_func("VERSION"), 323 exp.DateAdd: _date_add_sql("+"), 324 exp.DateDiff: _date_diff_sql, 325 exp.DateStrToDate: datestrtodate_sql, 326 exp.DateSub: _date_add_sql("-"), 327 exp.Day: _day_month_year_sql, 328 exp.Explode: rename_func("UNNEST"), 329 exp.ExplodingGenerateSeries: rename_func("GENERATE_SERIES"), 330 exp.GenerateSeries: generate_series_sql("GENERATE_SERIES"), 331 exp.Getbit: getbit_sql, 332 exp.GroupConcat: lambda self, e: groupconcat_sql( 333 self, e, func_name="STRING_AGG", within_group=False 334 ), 335 exp.IntDiv: rename_func("DIV"), 336 exp.JSONArrayAgg: lambda self, e: self.func( 337 "JSON_AGG", 338 self.sql(e, "this"), 339 suffix=f"{self.sql(e, 'order')})", 340 ), 341 exp.JSONExtract: _json_extract_sql("JSON_EXTRACT_PATH", "->"), 342 exp.JSONExtractScalar: _json_extract_sql("JSON_EXTRACT_PATH_TEXT", "->>"), 343 exp.JSONBExtract: lambda self, e: self.binary(e, "#>"), 344 exp.JSONBExtractScalar: lambda self, e: self.binary(e, "#>>"), 345 exp.JSONBContains: lambda self, e: self.binary(e, "?"), 346 exp.ParseJSON: lambda self, e: self.sql(exp.cast(e.this, exp.DType.JSON)), 347 exp.JSONPathKey: json_path_key_only_name, 348 exp.JSONPathRoot: lambda *_: "", 349 exp.JSONPathSubscript: lambda self, e: self.json_path_part(e.this), 350 exp.LastDay: no_last_day_sql, 351 exp.LogicalOr: rename_func("BOOL_OR"), 352 exp.LogicalAnd: rename_func("BOOL_AND"), 353 exp.Max: max_or_greatest, 354 exp.MapFromEntries: no_map_from_entries_sql, 355 exp.Min: min_or_least, 356 exp.Merge: merge_without_target_sql, 357 exp.Month: _day_month_year_sql, 358 exp.PartitionedByProperty: lambda self, e: f"PARTITION BY {self.sql(e, 'this')}", 359 exp.PercentileCont: transforms.preprocess([transforms.add_within_group_for_percentiles]), 360 exp.PercentileDisc: transforms.preprocess([transforms.add_within_group_for_percentiles]), 361 exp.Pivot: no_pivot_sql, 362 exp.Rand: rename_func("RANDOM"), 363 exp.RegexpLike: lambda self, e: self.binary(e, "~"), 364 exp.RegexpILike: lambda self, e: self.binary(e, "~*"), 365 exp.RegexpReplace: lambda self, e: self.func( 366 "REGEXP_REPLACE", 367 e.this, 368 e.expression, 369 e.args.get("replacement"), 370 e.args.get("position"), 371 e.args.get("occurrence"), 372 regexp_replace_global_modifier(e), 373 ), 374 exp.Round: _round_sql, 375 exp.Select: transforms.preprocess( 376 [ 377 transforms.eliminate_semi_and_anti_joins, 378 transforms.eliminate_qualify, 379 ] 380 ), 381 exp.SHA2: sha256_sql, 382 exp.SHA2Digest: sha2_digest_sql, 383 exp.StrPosition: lambda self, e: strposition_sql(self, e, func_name="POSITION"), 384 exp.StrToDate: lambda self, e: self.func("TO_DATE", e.this, self.format_time(e)), 385 exp.StrToTime: lambda self, e: self.func("TO_TIMESTAMP", e.this, self.format_time(e)), 386 exp.StructExtract: struct_extract_sql, 387 exp.Substring: _substring_sql, 388 exp.TimeFromParts: rename_func("MAKE_TIME"), 389 exp.TimestampFromParts: rename_func("MAKE_TIMESTAMP"), 390 exp.TimestampTrunc: timestamptrunc_sql(zone=True), 391 exp.TimeStrToTime: timestrtotime_sql, 392 exp.TimeToStr: lambda self, e: self.func("TO_CHAR", e.this, self.format_time(e)), 393 exp.ToChar: lambda self, e: ( 394 self.function_fallback_sql(e) if e.args.get("format") else self.tochar_sql(e) 395 ), 396 exp.Trim: trim_sql, 397 exp.TryCast: no_trycast_sql, 398 exp.TsOrDsAdd: _date_add_sql("+"), 399 exp.TsOrDsDiff: _date_diff_sql, 400 exp.UnixToTime: lambda self, e: self.func("TO_TIMESTAMP", e.this), 401 exp.Uuid: lambda *_: "GEN_RANDOM_UUID()", 402 exp.TimeToUnix: lambda self, e: self.func("DATE_PART", exp.Literal.string("epoch"), e.this), 403 exp.VariancePop: rename_func("VAR_POP"), 404 exp.Variance: rename_func("VAR_SAMP"), 405 exp.Xor: bool_xor_sql, 406 exp.Year: _day_month_year_sql, 407 exp.Unicode: rename_func("ASCII"), 408 exp.UnixToTime: _unix_to_time_sql, 409 exp.Levenshtein: _levenshtein_sql, 410 exp.JSONObjectAgg: rename_func("JSON_OBJECT_AGG"), 411 exp.JSONBObjectAgg: rename_func("JSONB_OBJECT_AGG"), 412 exp.CountIf: count_if_to_sum, 413 } 414 415 PROPERTIES_LOCATION = { 416 **generator.Generator.PROPERTIES_LOCATION, 417 exp.PartitionedByProperty: exp.Properties.Location.POST_SCHEMA, 418 exp.TransientProperty: exp.Properties.Location.UNSUPPORTED, 419 exp.VolatileProperty: exp.Properties.Location.UNSUPPORTED, 420 } 421 422 def schemacommentproperty_sql(self, expression: exp.SchemaCommentProperty) -> str: 423 self.unsupported("Table comments are not supported in the CREATE statement") 424 return "" 425 426 def commentcolumnconstraint_sql(self, expression: exp.CommentColumnConstraint) -> str: 427 self.unsupported("Column comments are not supported in the CREATE statement") 428 return "" 429 430 def columndef_sql(self, expression: exp.ColumnDef, sep: str = " ") -> str: 431 # PostgreSQL places parameter modes BEFORE parameter name 432 param_constraint = expression.find(exp.InOutColumnConstraint) 433 434 if param_constraint: 435 mode_sql = self.sql(param_constraint) 436 param_constraint.pop() # Remove to prevent double-rendering 437 base_sql = super().columndef_sql(expression, sep) 438 return f"{mode_sql} {base_sql}" 439 440 return super().columndef_sql(expression, sep) 441 442 def unnest_sql(self, expression: exp.Unnest) -> str: 443 if len(expression.expressions) == 1: 444 arg = expression.expressions[0] 445 if isinstance(arg, exp.GenerateDateArray): 446 generate_series: exp.Expr = exp.GenerateSeries(**arg.args) 447 if isinstance(expression.parent, (exp.From, exp.Join)): 448 generate_series = ( 449 exp.select("value::date") 450 .from_(exp.Table(this=generate_series).as_("_t", table=["value"])) 451 .subquery(expression.args.get("alias") or "_unnested_generate_series") 452 ) 453 return self.sql(generate_series) 454 455 from sqlglot.optimizer.annotate_types import annotate_types 456 457 this = annotate_types(arg, dialect=self.dialect) 458 if this.is_type("array<json>"): 459 while isinstance(this, exp.Cast): 460 this = this.this 461 462 arg_as_json = self.sql(exp.cast(this, exp.DType.JSON)) 463 alias = self.sql(expression, "alias") 464 alias = f" AS {alias}" if alias else "" 465 466 if expression.args.get("offset"): 467 self.unsupported("Unsupported JSON_ARRAY_ELEMENTS with offset") 468 469 return f"JSON_ARRAY_ELEMENTS({arg_as_json}){alias}" 470 471 return super().unnest_sql(expression) 472 473 def bracket_sql(self, expression: exp.Bracket) -> str: 474 """Forms like ARRAY[1, 2, 3][3] aren't allowed; we need to wrap the ARRAY.""" 475 if isinstance(expression.this, exp.Array): 476 expression.set("this", exp.paren(expression.this, copy=False)) 477 478 return super().bracket_sql(expression) 479 480 def matchagainst_sql(self, expression: exp.MatchAgainst) -> str: 481 this = self.sql(expression, "this") 482 expressions = [f"{self.sql(e)} @@ {this}" for e in expression.expressions] 483 sql = " OR ".join(expressions) 484 return f"({sql})" if len(expressions) > 1 else sql 485 486 def alterset_sql(self, expression: exp.AlterSet) -> str: 487 exprs = self.expressions(expression, flat=True) 488 exprs = f"({exprs})" if exprs else "" 489 490 access_method = self.sql(expression, "access_method") 491 access_method = f"ACCESS METHOD {access_method}" if access_method else "" 492 tablespace = self.sql(expression, "tablespace") 493 tablespace = f"TABLESPACE {tablespace}" if tablespace else "" 494 option = self.sql(expression, "option") 495 496 return f"SET {exprs}{access_method}{tablespace}{option}" 497 498 def datatype_sql(self, expression: exp.DataType) -> str: 499 if expression.is_type(exp.DType.ARRAY): 500 if expression.expressions: 501 values = self.expressions(expression, key="values", flat=True) 502 return f"{self.expressions(expression, flat=True)}[{values}]" 503 return "ARRAY" 504 505 if expression.is_type(exp.DType.ENUM): 506 return f"ENUM ({self.expressions(expression, flat=True)})" 507 508 if expression.is_type(exp.DType.DOUBLE, exp.DType.FLOAT) and expression.expressions: 509 # Postgres doesn't support precision for REAL and DOUBLE PRECISION types 510 return f"FLOAT({self.expressions(expression, flat=True)})" 511 512 return super().datatype_sql(expression) 513 514 def cast_sql(self, expression: exp.Cast, safe_prefix: str | None = None) -> str: 515 this = expression.this 516 517 # Postgres casts DIV() to decimal for transpilation but when roundtripping it's superfluous 518 if isinstance(this, exp.IntDiv) and expression.to == exp.DType.DECIMAL.into_expr(): 519 return self.sql(this) 520 521 return super().cast_sql(expression, safe_prefix=safe_prefix) 522 523 def array_sql(self, expression: exp.Array) -> str: 524 exprs = expression.expressions 525 func_name = self.normalize_func("ARRAY") 526 527 if isinstance(seq_get(exprs, 0), exp.Query): 528 return f"{func_name}({self.sql(exprs[0])})" 529 530 return f"{func_name}{inline_array_sql(self, expression)}" 531 532 def computedcolumnconstraint_sql(self, expression: exp.ComputedColumnConstraint) -> str: 533 return f"GENERATED ALWAYS AS ({self.sql(expression, 'this')}) STORED" 534 535 def isascii_sql(self, expression: exp.IsAscii) -> str: 536 return f"({self.sql(expression.this)} ~ '^[[:ascii:]]*$')" 537 538 def ignorenulls_sql(self, expression: exp.IgnoreNulls) -> str: 539 # https://www.postgresql.org/docs/current/functions-window.html 540 self.unsupported("PostgreSQL does not support IGNORE NULLS.") 541 return self.sql(expression.this) 542 543 def respectnulls_sql(self, expression: exp.RespectNulls) -> str: 544 # https://www.postgresql.org/docs/current/functions-window.html 545 self.unsupported("PostgreSQL does not support RESPECT NULLS.") 546 return self.sql(expression.this) 547 548 @unsupported_args("this") 549 def currentschema_sql(self, expression: exp.CurrentSchema) -> str: 550 return "CURRENT_SCHEMA" 551 552 def interval_sql(self, expression: exp.Interval) -> str: 553 unit = expression.text("unit").lower() 554 555 this = expression.this 556 if unit.startswith("quarter") and isinstance(this, exp.Literal): 557 this.replace(exp.Literal.string(int(this.to_py()) * 3)) 558 expression.args["unit"].replace(exp.var("MONTH")) 559 560 return super().interval_sql(expression) 561 562 def placeholder_sql(self, expression: exp.Placeholder) -> str: 563 if expression.args.get("jdbc"): 564 return "?" 565 566 this = f"({expression.name})" if expression.this else "" 567 return f"{self.NAMED_PLACEHOLDER_TOKEN}{this}s" 568 569 def arraycontains_sql(self, expression: exp.ArrayContains) -> str: 570 # Convert DuckDB's LIST_CONTAINS(array, value) to PostgreSQL 571 # DuckDB behavior: 572 # - LIST_CONTAINS([1,2,3], 2) -> true 573 # - LIST_CONTAINS([1,2,3], 4) -> false 574 # - LIST_CONTAINS([1,2,NULL], 4) -> false (not NULL) 575 # - LIST_CONTAINS([1,2,3], NULL) -> NULL 576 # 577 # PostgreSQL equivalent: CASE WHEN value IS NULL THEN NULL 578 # ELSE COALESCE(value = ANY(array), FALSE) END 579 value = expression.expression 580 array = expression.this 581 582 coalesce_expr = exp.Coalesce( 583 this=value.eq(exp.Any(this=exp.paren(expression=array, copy=False))), 584 expressions=[exp.false()], 585 ) 586 587 case_expr = ( 588 exp.Case() 589 .when(exp.Is(this=value, expression=exp.null()), exp.null(), copy=False) 590 .else_(coalesce_expr, copy=False) 591 ) 592 593 return self.sql(case_expr)
DATE_DIFF_FACTOR =
{'MICROSECOND': ' * 1000000', 'MILLISECOND': ' * 1000', 'SECOND': '', 'MINUTE': ' / 60', 'HOUR': ' / 3600', 'DAY': ' / 86400'}
245class PostgresGenerator(generator.Generator): 246 SELECT_KINDS: tuple[str, ...] = () 247 TRY_SUPPORTED = False 248 SUPPORTS_DECODE_CASE = False 249 250 AFTER_HAVING_MODIFIER_TRANSFORMS = generator.AFTER_HAVING_MODIFIER_TRANSFORMS 251 252 SINGLE_STRING_INTERVAL = True 253 RENAME_TABLE_WITH_DB = False 254 LOCKING_READS_SUPPORTED = True 255 JOIN_HINTS = False 256 TABLE_HINTS = False 257 QUERY_HINTS = False 258 NVL2_SUPPORTED = False 259 PARAMETER_TOKEN = "$" 260 NAMED_PLACEHOLDER_TOKEN = "%" 261 TABLESAMPLE_SIZE_IS_ROWS = False 262 TABLESAMPLE_SEED_KEYWORD = "REPEATABLE" 263 SUPPORTS_SELECT_INTO = True 264 JSON_TYPE_REQUIRED_FOR_EXTRACTION = True 265 SUPPORTS_UNLOGGED_TABLES = True 266 LIKE_PROPERTY_INSIDE_SCHEMA = True 267 MULTI_ARG_DISTINCT = False 268 CAN_IMPLEMENT_ARRAY_ANY = True 269 SUPPORTS_WINDOW_EXCLUDE = True 270 COPY_HAS_INTO_KEYWORD = False 271 ARRAY_CONCAT_IS_VAR_LEN = False 272 SUPPORTS_MEDIAN = False 273 ARRAY_SIZE_DIM_REQUIRED: bool | None = True 274 SUPPORTS_BETWEEN_FLAGS = True 275 INOUT_SEPARATOR = "" # PostgreSQL uses "INOUT" (no space) 276 277 SUPPORTED_JSON_PATH_PARTS = { 278 exp.JSONPathKey, 279 exp.JSONPathRoot, 280 exp.JSONPathSubscript, 281 } 282 283 def lateral_sql(self, expression: exp.Lateral) -> str: 284 sql = super().lateral_sql(expression) 285 286 if expression.args.get("cross_apply") is not None: 287 sql = f"{sql} ON TRUE" 288 289 return sql 290 291 TYPE_MAPPING = { 292 **generator.Generator.TYPE_MAPPING, 293 exp.DType.TINYINT: "SMALLINT", 294 exp.DType.FLOAT: "REAL", 295 exp.DType.DOUBLE: "DOUBLE PRECISION", 296 exp.DType.BINARY: "BYTEA", 297 exp.DType.VARBINARY: "BYTEA", 298 exp.DType.ROWVERSION: "BYTEA", 299 exp.DType.DATETIME: "TIMESTAMP", 300 exp.DType.TIMESTAMPNTZ: "TIMESTAMP", 301 exp.DType.BLOB: "BYTEA", 302 } 303 304 TRANSFORMS = { 305 **{ 306 k: v 307 for k, v in generator.Generator.TRANSFORMS.items() 308 if k != exp.CommentColumnConstraint 309 }, 310 exp.AnyValue: _versioned_anyvalue_sql, 311 exp.ArrayConcat: array_concat_sql("ARRAY_CAT"), 312 exp.ArrayFilter: filter_array_using_unnest, 313 exp.ArrayAppend: array_append_sql("ARRAY_APPEND"), 314 exp.ArrayPrepend: array_append_sql("ARRAY_PREPEND", swap_params=True), 315 exp.BitwiseAndAgg: rename_func("BIT_AND"), 316 exp.BitwiseOrAgg: rename_func("BIT_OR"), 317 exp.BitwiseXor: lambda self, e: self.binary(e, "#"), 318 exp.BitwiseXorAgg: rename_func("BIT_XOR"), 319 exp.ColumnDef: transforms.preprocess([_auto_increment_to_serial, _serial_to_generated]), 320 exp.CurrentDate: no_paren_current_date_sql, 321 exp.CurrentTimestamp: lambda *_: "CURRENT_TIMESTAMP", 322 exp.CurrentUser: lambda *_: "CURRENT_USER", 323 exp.CurrentVersion: rename_func("VERSION"), 324 exp.DateAdd: _date_add_sql("+"), 325 exp.DateDiff: _date_diff_sql, 326 exp.DateStrToDate: datestrtodate_sql, 327 exp.DateSub: _date_add_sql("-"), 328 exp.Day: _day_month_year_sql, 329 exp.Explode: rename_func("UNNEST"), 330 exp.ExplodingGenerateSeries: rename_func("GENERATE_SERIES"), 331 exp.GenerateSeries: generate_series_sql("GENERATE_SERIES"), 332 exp.Getbit: getbit_sql, 333 exp.GroupConcat: lambda self, e: groupconcat_sql( 334 self, e, func_name="STRING_AGG", within_group=False 335 ), 336 exp.IntDiv: rename_func("DIV"), 337 exp.JSONArrayAgg: lambda self, e: self.func( 338 "JSON_AGG", 339 self.sql(e, "this"), 340 suffix=f"{self.sql(e, 'order')})", 341 ), 342 exp.JSONExtract: _json_extract_sql("JSON_EXTRACT_PATH", "->"), 343 exp.JSONExtractScalar: _json_extract_sql("JSON_EXTRACT_PATH_TEXT", "->>"), 344 exp.JSONBExtract: lambda self, e: self.binary(e, "#>"), 345 exp.JSONBExtractScalar: lambda self, e: self.binary(e, "#>>"), 346 exp.JSONBContains: lambda self, e: self.binary(e, "?"), 347 exp.ParseJSON: lambda self, e: self.sql(exp.cast(e.this, exp.DType.JSON)), 348 exp.JSONPathKey: json_path_key_only_name, 349 exp.JSONPathRoot: lambda *_: "", 350 exp.JSONPathSubscript: lambda self, e: self.json_path_part(e.this), 351 exp.LastDay: no_last_day_sql, 352 exp.LogicalOr: rename_func("BOOL_OR"), 353 exp.LogicalAnd: rename_func("BOOL_AND"), 354 exp.Max: max_or_greatest, 355 exp.MapFromEntries: no_map_from_entries_sql, 356 exp.Min: min_or_least, 357 exp.Merge: merge_without_target_sql, 358 exp.Month: _day_month_year_sql, 359 exp.PartitionedByProperty: lambda self, e: f"PARTITION BY {self.sql(e, 'this')}", 360 exp.PercentileCont: transforms.preprocess([transforms.add_within_group_for_percentiles]), 361 exp.PercentileDisc: transforms.preprocess([transforms.add_within_group_for_percentiles]), 362 exp.Pivot: no_pivot_sql, 363 exp.Rand: rename_func("RANDOM"), 364 exp.RegexpLike: lambda self, e: self.binary(e, "~"), 365 exp.RegexpILike: lambda self, e: self.binary(e, "~*"), 366 exp.RegexpReplace: lambda self, e: self.func( 367 "REGEXP_REPLACE", 368 e.this, 369 e.expression, 370 e.args.get("replacement"), 371 e.args.get("position"), 372 e.args.get("occurrence"), 373 regexp_replace_global_modifier(e), 374 ), 375 exp.Round: _round_sql, 376 exp.Select: transforms.preprocess( 377 [ 378 transforms.eliminate_semi_and_anti_joins, 379 transforms.eliminate_qualify, 380 ] 381 ), 382 exp.SHA2: sha256_sql, 383 exp.SHA2Digest: sha2_digest_sql, 384 exp.StrPosition: lambda self, e: strposition_sql(self, e, func_name="POSITION"), 385 exp.StrToDate: lambda self, e: self.func("TO_DATE", e.this, self.format_time(e)), 386 exp.StrToTime: lambda self, e: self.func("TO_TIMESTAMP", e.this, self.format_time(e)), 387 exp.StructExtract: struct_extract_sql, 388 exp.Substring: _substring_sql, 389 exp.TimeFromParts: rename_func("MAKE_TIME"), 390 exp.TimestampFromParts: rename_func("MAKE_TIMESTAMP"), 391 exp.TimestampTrunc: timestamptrunc_sql(zone=True), 392 exp.TimeStrToTime: timestrtotime_sql, 393 exp.TimeToStr: lambda self, e: self.func("TO_CHAR", e.this, self.format_time(e)), 394 exp.ToChar: lambda self, e: ( 395 self.function_fallback_sql(e) if e.args.get("format") else self.tochar_sql(e) 396 ), 397 exp.Trim: trim_sql, 398 exp.TryCast: no_trycast_sql, 399 exp.TsOrDsAdd: _date_add_sql("+"), 400 exp.TsOrDsDiff: _date_diff_sql, 401 exp.UnixToTime: lambda self, e: self.func("TO_TIMESTAMP", e.this), 402 exp.Uuid: lambda *_: "GEN_RANDOM_UUID()", 403 exp.TimeToUnix: lambda self, e: self.func("DATE_PART", exp.Literal.string("epoch"), e.this), 404 exp.VariancePop: rename_func("VAR_POP"), 405 exp.Variance: rename_func("VAR_SAMP"), 406 exp.Xor: bool_xor_sql, 407 exp.Year: _day_month_year_sql, 408 exp.Unicode: rename_func("ASCII"), 409 exp.UnixToTime: _unix_to_time_sql, 410 exp.Levenshtein: _levenshtein_sql, 411 exp.JSONObjectAgg: rename_func("JSON_OBJECT_AGG"), 412 exp.JSONBObjectAgg: rename_func("JSONB_OBJECT_AGG"), 413 exp.CountIf: count_if_to_sum, 414 } 415 416 PROPERTIES_LOCATION = { 417 **generator.Generator.PROPERTIES_LOCATION, 418 exp.PartitionedByProperty: exp.Properties.Location.POST_SCHEMA, 419 exp.TransientProperty: exp.Properties.Location.UNSUPPORTED, 420 exp.VolatileProperty: exp.Properties.Location.UNSUPPORTED, 421 } 422 423 def schemacommentproperty_sql(self, expression: exp.SchemaCommentProperty) -> str: 424 self.unsupported("Table comments are not supported in the CREATE statement") 425 return "" 426 427 def commentcolumnconstraint_sql(self, expression: exp.CommentColumnConstraint) -> str: 428 self.unsupported("Column comments are not supported in the CREATE statement") 429 return "" 430 431 def columndef_sql(self, expression: exp.ColumnDef, sep: str = " ") -> str: 432 # PostgreSQL places parameter modes BEFORE parameter name 433 param_constraint = expression.find(exp.InOutColumnConstraint) 434 435 if param_constraint: 436 mode_sql = self.sql(param_constraint) 437 param_constraint.pop() # Remove to prevent double-rendering 438 base_sql = super().columndef_sql(expression, sep) 439 return f"{mode_sql} {base_sql}" 440 441 return super().columndef_sql(expression, sep) 442 443 def unnest_sql(self, expression: exp.Unnest) -> str: 444 if len(expression.expressions) == 1: 445 arg = expression.expressions[0] 446 if isinstance(arg, exp.GenerateDateArray): 447 generate_series: exp.Expr = exp.GenerateSeries(**arg.args) 448 if isinstance(expression.parent, (exp.From, exp.Join)): 449 generate_series = ( 450 exp.select("value::date") 451 .from_(exp.Table(this=generate_series).as_("_t", table=["value"])) 452 .subquery(expression.args.get("alias") or "_unnested_generate_series") 453 ) 454 return self.sql(generate_series) 455 456 from sqlglot.optimizer.annotate_types import annotate_types 457 458 this = annotate_types(arg, dialect=self.dialect) 459 if this.is_type("array<json>"): 460 while isinstance(this, exp.Cast): 461 this = this.this 462 463 arg_as_json = self.sql(exp.cast(this, exp.DType.JSON)) 464 alias = self.sql(expression, "alias") 465 alias = f" AS {alias}" if alias else "" 466 467 if expression.args.get("offset"): 468 self.unsupported("Unsupported JSON_ARRAY_ELEMENTS with offset") 469 470 return f"JSON_ARRAY_ELEMENTS({arg_as_json}){alias}" 471 472 return super().unnest_sql(expression) 473 474 def bracket_sql(self, expression: exp.Bracket) -> str: 475 """Forms like ARRAY[1, 2, 3][3] aren't allowed; we need to wrap the ARRAY.""" 476 if isinstance(expression.this, exp.Array): 477 expression.set("this", exp.paren(expression.this, copy=False)) 478 479 return super().bracket_sql(expression) 480 481 def matchagainst_sql(self, expression: exp.MatchAgainst) -> str: 482 this = self.sql(expression, "this") 483 expressions = [f"{self.sql(e)} @@ {this}" for e in expression.expressions] 484 sql = " OR ".join(expressions) 485 return f"({sql})" if len(expressions) > 1 else sql 486 487 def alterset_sql(self, expression: exp.AlterSet) -> str: 488 exprs = self.expressions(expression, flat=True) 489 exprs = f"({exprs})" if exprs else "" 490 491 access_method = self.sql(expression, "access_method") 492 access_method = f"ACCESS METHOD {access_method}" if access_method else "" 493 tablespace = self.sql(expression, "tablespace") 494 tablespace = f"TABLESPACE {tablespace}" if tablespace else "" 495 option = self.sql(expression, "option") 496 497 return f"SET {exprs}{access_method}{tablespace}{option}" 498 499 def datatype_sql(self, expression: exp.DataType) -> str: 500 if expression.is_type(exp.DType.ARRAY): 501 if expression.expressions: 502 values = self.expressions(expression, key="values", flat=True) 503 return f"{self.expressions(expression, flat=True)}[{values}]" 504 return "ARRAY" 505 506 if expression.is_type(exp.DType.ENUM): 507 return f"ENUM ({self.expressions(expression, flat=True)})" 508 509 if expression.is_type(exp.DType.DOUBLE, exp.DType.FLOAT) and expression.expressions: 510 # Postgres doesn't support precision for REAL and DOUBLE PRECISION types 511 return f"FLOAT({self.expressions(expression, flat=True)})" 512 513 return super().datatype_sql(expression) 514 515 def cast_sql(self, expression: exp.Cast, safe_prefix: str | None = None) -> str: 516 this = expression.this 517 518 # Postgres casts DIV() to decimal for transpilation but when roundtripping it's superfluous 519 if isinstance(this, exp.IntDiv) and expression.to == exp.DType.DECIMAL.into_expr(): 520 return self.sql(this) 521 522 return super().cast_sql(expression, safe_prefix=safe_prefix) 523 524 def array_sql(self, expression: exp.Array) -> str: 525 exprs = expression.expressions 526 func_name = self.normalize_func("ARRAY") 527 528 if isinstance(seq_get(exprs, 0), exp.Query): 529 return f"{func_name}({self.sql(exprs[0])})" 530 531 return f"{func_name}{inline_array_sql(self, expression)}" 532 533 def computedcolumnconstraint_sql(self, expression: exp.ComputedColumnConstraint) -> str: 534 return f"GENERATED ALWAYS AS ({self.sql(expression, 'this')}) STORED" 535 536 def isascii_sql(self, expression: exp.IsAscii) -> str: 537 return f"({self.sql(expression.this)} ~ '^[[:ascii:]]*$')" 538 539 def ignorenulls_sql(self, expression: exp.IgnoreNulls) -> str: 540 # https://www.postgresql.org/docs/current/functions-window.html 541 self.unsupported("PostgreSQL does not support IGNORE NULLS.") 542 return self.sql(expression.this) 543 544 def respectnulls_sql(self, expression: exp.RespectNulls) -> str: 545 # https://www.postgresql.org/docs/current/functions-window.html 546 self.unsupported("PostgreSQL does not support RESPECT NULLS.") 547 return self.sql(expression.this) 548 549 @unsupported_args("this") 550 def currentschema_sql(self, expression: exp.CurrentSchema) -> str: 551 return "CURRENT_SCHEMA" 552 553 def interval_sql(self, expression: exp.Interval) -> str: 554 unit = expression.text("unit").lower() 555 556 this = expression.this 557 if unit.startswith("quarter") and isinstance(this, exp.Literal): 558 this.replace(exp.Literal.string(int(this.to_py()) * 3)) 559 expression.args["unit"].replace(exp.var("MONTH")) 560 561 return super().interval_sql(expression) 562 563 def placeholder_sql(self, expression: exp.Placeholder) -> str: 564 if expression.args.get("jdbc"): 565 return "?" 566 567 this = f"({expression.name})" if expression.this else "" 568 return f"{self.NAMED_PLACEHOLDER_TOKEN}{this}s" 569 570 def arraycontains_sql(self, expression: exp.ArrayContains) -> str: 571 # Convert DuckDB's LIST_CONTAINS(array, value) to PostgreSQL 572 # DuckDB behavior: 573 # - LIST_CONTAINS([1,2,3], 2) -> true 574 # - LIST_CONTAINS([1,2,3], 4) -> false 575 # - LIST_CONTAINS([1,2,NULL], 4) -> false (not NULL) 576 # - LIST_CONTAINS([1,2,3], NULL) -> NULL 577 # 578 # PostgreSQL equivalent: CASE WHEN value IS NULL THEN NULL 579 # ELSE COALESCE(value = ANY(array), FALSE) END 580 value = expression.expression 581 array = expression.this 582 583 coalesce_expr = exp.Coalesce( 584 this=value.eq(exp.Any(this=exp.paren(expression=array, copy=False))), 585 expressions=[exp.false()], 586 ) 587 588 case_expr = ( 589 exp.Case() 590 .when(exp.Is(this=value, expression=exp.null()), exp.null(), copy=False) 591 .else_(coalesce_expr, copy=False) 592 ) 593 594 return self.sql(case_expr)
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'>: 'CHAR', <DType.NVARCHAR: 'NVARCHAR'>: 'VARCHAR', <DType.MEDIUMTEXT: 'MEDIUMTEXT'>: 'TEXT', <DType.LONGTEXT: 'LONGTEXT'>: 'TEXT', <DType.TINYTEXT: 'TINYTEXT'>: 'TEXT', <DType.BLOB: 'BLOB'>: 'BYTEA', <DType.MEDIUMBLOB: 'MEDIUMBLOB'>: 'BLOB', <DType.LONGBLOB: 'LONGBLOB'>: 'BLOB', <DType.TINYBLOB: 'TINYBLOB'>: 'BLOB', <DType.INET: 'INET'>: 'INET', <DType.ROWVERSION: 'ROWVERSION'>: 'BYTEA', <DType.SMALLDATETIME: 'SMALLDATETIME'>: 'TIMESTAMP', <DType.TINYINT: 'TINYINT'>: 'SMALLINT', <DType.FLOAT: 'FLOAT'>: 'REAL', <DType.DOUBLE: 'DOUBLE'>: 'DOUBLE PRECISION', <DType.BINARY: 'BINARY'>: 'BYTEA', <DType.VARBINARY: 'VARBINARY'>: 'BYTEA', <DType.DATETIME: 'DATETIME'>: 'TIMESTAMP', <DType.TIMESTAMPNTZ: 'TIMESTAMPNTZ'>: 'TIMESTAMP'}
TRANSFORMS =
{<class 'sqlglot.expressions.query.JSONPathKey'>: <function json_path_key_only_name>, <class 'sqlglot.expressions.query.JSONPathRoot'>: <function PostgresGenerator.<lambda>>, <class 'sqlglot.expressions.query.JSONPathSubscript'>: <function PostgresGenerator.<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.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.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.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 rename_func.<locals>.<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 _versioned_anyvalue_sql>, <class 'sqlglot.expressions.array.ArrayConcat'>: <function array_concat_sql.<locals>._array_concat_sql>, <class 'sqlglot.expressions.array.ArrayFilter'>: <function filter_array_using_unnest>, <class 'sqlglot.expressions.array.ArrayAppend'>: <function array_append_sql.<locals>._array_append_sql>, <class 'sqlglot.expressions.array.ArrayPrepend'>: <function array_append_sql.<locals>._array_append_sql>, <class 'sqlglot.expressions.math.BitwiseAndAgg'>: <function rename_func.<locals>.<lambda>>, <class 'sqlglot.expressions.math.BitwiseOrAgg'>: <function rename_func.<locals>.<lambda>>, <class 'sqlglot.expressions.core.BitwiseXor'>: <function PostgresGenerator.<lambda>>, <class 'sqlglot.expressions.math.BitwiseXorAgg'>: <function rename_func.<locals>.<lambda>>, <class 'sqlglot.expressions.query.ColumnDef'>: <function preprocess.<locals>._to_sql>, <class 'sqlglot.expressions.temporal.CurrentDate'>: <function no_paren_current_date_sql>, <class 'sqlglot.expressions.temporal.CurrentTimestamp'>: <function PostgresGenerator.<lambda>>, <class 'sqlglot.expressions.functions.CurrentUser'>: <function PostgresGenerator.<lambda>>, <class 'sqlglot.expressions.functions.CurrentVersion'>: <function rename_func.<locals>.<lambda>>, <class 'sqlglot.expressions.temporal.DateAdd'>: <function _date_add_sql.<locals>.func>, <class 'sqlglot.expressions.temporal.DateDiff'>: <function _date_diff_sql>, <class 'sqlglot.expressions.temporal.DateStrToDate'>: <function datestrtodate_sql>, <class 'sqlglot.expressions.temporal.DateSub'>: <function _date_add_sql.<locals>.func>, <class 'sqlglot.expressions.temporal.Day'>: <function _day_month_year_sql>, <class 'sqlglot.expressions.array.Explode'>: <function rename_func.<locals>.<lambda>>, <class 'sqlglot.expressions.array.ExplodingGenerateSeries'>: <function rename_func.<locals>.<lambda>>, <class 'sqlglot.expressions.array.GenerateSeries'>: <function generate_series_sql.<locals>._generate_series_sql>, <class 'sqlglot.expressions.math.Getbit'>: <function getbit_sql>, <class 'sqlglot.expressions.aggregate.GroupConcat'>: <function PostgresGenerator.<lambda>>, <class 'sqlglot.expressions.core.IntDiv'>: <function rename_func.<locals>.<lambda>>, <class 'sqlglot.expressions.json.JSONArrayAgg'>: <function PostgresGenerator.<lambda>>, <class 'sqlglot.expressions.json.JSONExtract'>: <function _json_extract_sql.<locals>._generate>, <class 'sqlglot.expressions.json.JSONExtractScalar'>: <function _json_extract_sql.<locals>._generate>, <class 'sqlglot.expressions.json.JSONBExtract'>: <function PostgresGenerator.<lambda>>, <class 'sqlglot.expressions.json.JSONBExtractScalar'>: <function PostgresGenerator.<lambda>>, <class 'sqlglot.expressions.json.JSONBContains'>: <function PostgresGenerator.<lambda>>, <class 'sqlglot.expressions.json.ParseJSON'>: <function PostgresGenerator.<lambda>>, <class 'sqlglot.expressions.temporal.LastDay'>: <function no_last_day_sql>, <class 'sqlglot.expressions.aggregate.LogicalOr'>: <function rename_func.<locals>.<lambda>>, <class 'sqlglot.expressions.aggregate.LogicalAnd'>: <function rename_func.<locals>.<lambda>>, <class 'sqlglot.expressions.aggregate.Max'>: <function max_or_greatest>, <class 'sqlglot.expressions.array.MapFromEntries'>: <function no_map_from_entries_sql>, <class 'sqlglot.expressions.aggregate.Min'>: <function min_or_least>, <class 'sqlglot.expressions.dml.Merge'>: <function merge_without_target_sql>, <class 'sqlglot.expressions.temporal.Month'>: <function _day_month_year_sql>, <class 'sqlglot.expressions.properties.PartitionedByProperty'>: <function PostgresGenerator.<lambda>>, <class 'sqlglot.expressions.aggregate.PercentileCont'>: <function preprocess.<locals>._to_sql>, <class 'sqlglot.expressions.aggregate.PercentileDisc'>: <function preprocess.<locals>._to_sql>, <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 PostgresGenerator.<lambda>>, <class 'sqlglot.expressions.string.RegexpILike'>: <function PostgresGenerator.<lambda>>, <class 'sqlglot.expressions.string.RegexpReplace'>: <function PostgresGenerator.<lambda>>, <class 'sqlglot.expressions.math.Round'>: <function _round_sql>, <class 'sqlglot.expressions.query.Select'>: <function preprocess.<locals>._to_sql>, <class 'sqlglot.expressions.string.SHA2'>: <function sha256_sql>, <class 'sqlglot.expressions.string.SHA2Digest'>: <function sha2_digest_sql>, <class 'sqlglot.expressions.string.StrPosition'>: <function PostgresGenerator.<lambda>>, <class 'sqlglot.expressions.temporal.StrToDate'>: <function PostgresGenerator.<lambda>>, <class 'sqlglot.expressions.temporal.StrToTime'>: <function PostgresGenerator.<lambda>>, <class 'sqlglot.expressions.array.StructExtract'>: <function struct_extract_sql>, <class 'sqlglot.expressions.string.Substring'>: <function _substring_sql>, <class 'sqlglot.expressions.temporal.TimeFromParts'>: <function rename_func.<locals>.<lambda>>, <class 'sqlglot.expressions.temporal.TimestampFromParts'>: <function rename_func.<locals>.<lambda>>, <class 'sqlglot.expressions.temporal.TimestampTrunc'>: <function timestamptrunc_sql.<locals>._timestamptrunc_sql>, <class 'sqlglot.expressions.temporal.TimeStrToTime'>: <function timestrtotime_sql>, <class 'sqlglot.expressions.temporal.TimeToStr'>: <function PostgresGenerator.<lambda>>, <class 'sqlglot.expressions.string.ToChar'>: <function PostgresGenerator.<lambda>>, <class 'sqlglot.expressions.string.Trim'>: <function trim_sql>, <class 'sqlglot.expressions.functions.TryCast'>: <function no_trycast_sql>, <class 'sqlglot.expressions.temporal.TsOrDsAdd'>: <function _date_add_sql.<locals>.func>, <class 'sqlglot.expressions.temporal.TsOrDsDiff'>: <function _date_diff_sql>, <class 'sqlglot.expressions.temporal.UnixToTime'>: <function _unix_to_time_sql>, <class 'sqlglot.expressions.functions.Uuid'>: <function PostgresGenerator.<lambda>>, <class 'sqlglot.expressions.temporal.TimeToUnix'>: <function PostgresGenerator.<lambda>>, <class 'sqlglot.expressions.aggregate.VariancePop'>: <function rename_func.<locals>.<lambda>>, <class 'sqlglot.expressions.aggregate.Variance'>: <function rename_func.<locals>.<lambda>>, <class 'sqlglot.expressions.core.Xor'>: <function bool_xor_sql>, <class 'sqlglot.expressions.temporal.Year'>: <function _day_month_year_sql>, <class 'sqlglot.expressions.string.Unicode'>: <function rename_func.<locals>.<lambda>>, <class 'sqlglot.expressions.string.Levenshtein'>: <function _levenshtein_sql>, <class 'sqlglot.expressions.json.JSONBObjectAgg'>: <function rename_func.<locals>.<lambda>>, <class 'sqlglot.expressions.aggregate.CountIf'>: <function count_if_to_sum>}
PROPERTIES_LOCATION =
{<class 'sqlglot.expressions.properties.AllowedValuesProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.AlgorithmProperty'>: <PropertiesLocation.POST_CREATE: 'POST_CREATE'>, <class 'sqlglot.expressions.properties.ApiProperty'>: <PropertiesLocation.POST_CREATE: 'POST_CREATE'>, <class 'sqlglot.expressions.properties.ApplicationProperty'>: <PropertiesLocation.POST_CREATE: 'POST_CREATE'>, <class 'sqlglot.expressions.properties.AutoIncrementProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.AutoRefreshProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.BackupProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.BlockCompressionProperty'>: <PropertiesLocation.POST_NAME: 'POST_NAME'>, <class 'sqlglot.expressions.properties.CalledOnNullInputProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.CatalogProperty'>: <PropertiesLocation.POST_CREATE: 'POST_CREATE'>, <class 'sqlglot.expressions.properties.CharacterSetProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.ChecksumProperty'>: <PropertiesLocation.POST_NAME: 'POST_NAME'>, <class 'sqlglot.expressions.properties.CollateProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.ComputeProperty'>: <PropertiesLocation.POST_CREATE: 'POST_CREATE'>, <class 'sqlglot.expressions.properties.CopyGrantsProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.query.Cluster'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.ClusteredByProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.ClusterProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.DistributedByProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.DuplicateKeyProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.DataBlocksizeProperty'>: <PropertiesLocation.POST_NAME: 'POST_NAME'>, <class 'sqlglot.expressions.properties.DatabaseProperty'>: <PropertiesLocation.POST_CREATE: 'POST_CREATE'>, <class 'sqlglot.expressions.properties.DataDeletionProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.DefinerProperty'>: <PropertiesLocation.POST_CREATE: 'POST_CREATE'>, <class 'sqlglot.expressions.properties.DictRange'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.DictProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.DynamicProperty'>: <PropertiesLocation.POST_CREATE: 'POST_CREATE'>, <class 'sqlglot.expressions.properties.DistKeyProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.DistStyleProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.EmptyProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.EncodeProperty'>: <PropertiesLocation.POST_EXPRESSION: 'POST_EXPRESSION'>, <class 'sqlglot.expressions.properties.EngineProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.EnviromentProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.HandlerProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.ParameterStyleProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.ExecuteAsProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.ExternalProperty'>: <PropertiesLocation.POST_CREATE: 'POST_CREATE'>, <class 'sqlglot.expressions.properties.FallbackProperty'>: <PropertiesLocation.POST_NAME: 'POST_NAME'>, <class 'sqlglot.expressions.properties.FileFormatProperty'>: <PropertiesLocation.POST_WITH: 'POST_WITH'>, <class 'sqlglot.expressions.properties.FreespaceProperty'>: <PropertiesLocation.POST_NAME: 'POST_NAME'>, <class 'sqlglot.expressions.properties.GlobalProperty'>: <PropertiesLocation.POST_CREATE: 'POST_CREATE'>, <class 'sqlglot.expressions.properties.HeapProperty'>: <PropertiesLocation.POST_WITH: 'POST_WITH'>, <class 'sqlglot.expressions.properties.HybridProperty'>: <PropertiesLocation.POST_CREATE: 'POST_CREATE'>, <class 'sqlglot.expressions.properties.InheritsProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.IcebergProperty'>: <PropertiesLocation.POST_CREATE: 'POST_CREATE'>, <class 'sqlglot.expressions.properties.IncludeProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.InputModelProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.IsolatedLoadingProperty'>: <PropertiesLocation.POST_NAME: 'POST_NAME'>, <class 'sqlglot.expressions.properties.JournalProperty'>: <PropertiesLocation.POST_NAME: 'POST_NAME'>, <class 'sqlglot.expressions.properties.LanguageProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.LikeProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.LocationProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.LockProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.LockingProperty'>: <PropertiesLocation.POST_ALIAS: 'POST_ALIAS'>, <class 'sqlglot.expressions.properties.LogProperty'>: <PropertiesLocation.POST_NAME: 'POST_NAME'>, <class 'sqlglot.expressions.properties.MaskingProperty'>: <PropertiesLocation.POST_CREATE: 'POST_CREATE'>, <class 'sqlglot.expressions.properties.MaterializedProperty'>: <PropertiesLocation.POST_CREATE: 'POST_CREATE'>, <class 'sqlglot.expressions.properties.MergeBlockRatioProperty'>: <PropertiesLocation.POST_NAME: 'POST_NAME'>, <class 'sqlglot.expressions.properties.ModuleProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.NetworkProperty'>: <PropertiesLocation.POST_CREATE: 'POST_CREATE'>, <class 'sqlglot.expressions.properties.NoPrimaryIndexProperty'>: <PropertiesLocation.POST_EXPRESSION: 'POST_EXPRESSION'>, <class 'sqlglot.expressions.properties.OnProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.OnCommitProperty'>: <PropertiesLocation.POST_EXPRESSION: 'POST_EXPRESSION'>, <class 'sqlglot.expressions.query.Order'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.OutputModelProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.PartitionedByProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.PartitionedOfProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.constraints.PrimaryKey'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.Property'>: <PropertiesLocation.POST_WITH: 'POST_WITH'>, <class 'sqlglot.expressions.properties.RefreshTriggerProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.RemoteWithConnectionModelProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.ReturnsProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.RollupProperty'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.RowAccessProperty'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.RowFormatProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.RowFormatDelimitedProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.RowFormatSerdeProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.SampleProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.SchemaCommentProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.SecureProperty'>: <PropertiesLocation.POST_CREATE: 'POST_CREATE'>, <class 'sqlglot.expressions.properties.SecurityIntegrationProperty'>: <PropertiesLocation.POST_CREATE: 'POST_CREATE'>, <class 'sqlglot.expressions.properties.SerdeProperties'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.ddl.Set'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.SettingsProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.SetProperty'>: <PropertiesLocation.POST_CREATE: 'POST_CREATE'>, <class 'sqlglot.expressions.properties.SetConfigProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.SharingProperty'>: <PropertiesLocation.POST_EXPRESSION: 'POST_EXPRESSION'>, <class 'sqlglot.expressions.ddl.SequenceProperties'>: <PropertiesLocation.POST_EXPRESSION: 'POST_EXPRESSION'>, <class 'sqlglot.expressions.ddl.TriggerProperties'>: <PropertiesLocation.POST_EXPRESSION: 'POST_EXPRESSION'>, <class 'sqlglot.expressions.properties.SortKeyProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.SqlReadWriteProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.SqlSecurityProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.StabilityProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.StorageHandlerProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.StreamingTableProperty'>: <PropertiesLocation.POST_CREATE: 'POST_CREATE'>, <class 'sqlglot.expressions.properties.StrictProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.Tags'>: <PropertiesLocation.POST_WITH: 'POST_WITH'>, <class 'sqlglot.expressions.properties.TemporaryProperty'>: <PropertiesLocation.POST_CREATE: 'POST_CREATE'>, <class 'sqlglot.expressions.properties.ToTableProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.TransientProperty'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.TransformModelProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.ddl.MergeTreeTTL'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.UnloggedProperty'>: <PropertiesLocation.POST_CREATE: 'POST_CREATE'>, <class 'sqlglot.expressions.properties.UsingProperty'>: <PropertiesLocation.POST_EXPRESSION: 'POST_EXPRESSION'>, <class 'sqlglot.expressions.properties.UsingTemplateProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.ViewAttributeProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.VirtualProperty'>: <PropertiesLocation.POST_CREATE: 'POST_CREATE'>, <class 'sqlglot.expressions.properties.VolatileProperty'>: <PropertiesLocation.UNSUPPORTED: 'UNSUPPORTED'>, <class 'sqlglot.expressions.properties.WithDataProperty'>: <PropertiesLocation.POST_EXPRESSION: 'POST_EXPRESSION'>, <class 'sqlglot.expressions.properties.WithJournalTableProperty'>: <PropertiesLocation.POST_NAME: 'POST_NAME'>, <class 'sqlglot.expressions.properties.WithProcedureOptions'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.WithSchemaBindingProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.WithSystemVersioningProperty'>: <PropertiesLocation.POST_SCHEMA: 'POST_SCHEMA'>, <class 'sqlglot.expressions.properties.ForceProperty'>: <PropertiesLocation.POST_CREATE: 'POST_CREATE'>}
def
schemacommentproperty_sql( self, expression: sqlglot.expressions.properties.SchemaCommentProperty) -> str:
def
commentcolumnconstraint_sql( self, expression: sqlglot.expressions.constraints.CommentColumnConstraint) -> str:
431 def columndef_sql(self, expression: exp.ColumnDef, sep: str = " ") -> str: 432 # PostgreSQL places parameter modes BEFORE parameter name 433 param_constraint = expression.find(exp.InOutColumnConstraint) 434 435 if param_constraint: 436 mode_sql = self.sql(param_constraint) 437 param_constraint.pop() # Remove to prevent double-rendering 438 base_sql = super().columndef_sql(expression, sep) 439 return f"{mode_sql} {base_sql}" 440 441 return super().columndef_sql(expression, sep)
443 def unnest_sql(self, expression: exp.Unnest) -> str: 444 if len(expression.expressions) == 1: 445 arg = expression.expressions[0] 446 if isinstance(arg, exp.GenerateDateArray): 447 generate_series: exp.Expr = exp.GenerateSeries(**arg.args) 448 if isinstance(expression.parent, (exp.From, exp.Join)): 449 generate_series = ( 450 exp.select("value::date") 451 .from_(exp.Table(this=generate_series).as_("_t", table=["value"])) 452 .subquery(expression.args.get("alias") or "_unnested_generate_series") 453 ) 454 return self.sql(generate_series) 455 456 from sqlglot.optimizer.annotate_types import annotate_types 457 458 this = annotate_types(arg, dialect=self.dialect) 459 if this.is_type("array<json>"): 460 while isinstance(this, exp.Cast): 461 this = this.this 462 463 arg_as_json = self.sql(exp.cast(this, exp.DType.JSON)) 464 alias = self.sql(expression, "alias") 465 alias = f" AS {alias}" if alias else "" 466 467 if expression.args.get("offset"): 468 self.unsupported("Unsupported JSON_ARRAY_ELEMENTS with offset") 469 470 return f"JSON_ARRAY_ELEMENTS({arg_as_json}){alias}" 471 472 return super().unnest_sql(expression)
474 def bracket_sql(self, expression: exp.Bracket) -> str: 475 """Forms like ARRAY[1, 2, 3][3] aren't allowed; we need to wrap the ARRAY.""" 476 if isinstance(expression.this, exp.Array): 477 expression.set("this", exp.paren(expression.this, copy=False)) 478 479 return super().bracket_sql(expression)
Forms like ARRAY[1, 2, 3][3] aren't allowed; we need to wrap the ARRAY.
487 def alterset_sql(self, expression: exp.AlterSet) -> str: 488 exprs = self.expressions(expression, flat=True) 489 exprs = f"({exprs})" if exprs else "" 490 491 access_method = self.sql(expression, "access_method") 492 access_method = f"ACCESS METHOD {access_method}" if access_method else "" 493 tablespace = self.sql(expression, "tablespace") 494 tablespace = f"TABLESPACE {tablespace}" if tablespace else "" 495 option = self.sql(expression, "option") 496 497 return f"SET {exprs}{access_method}{tablespace}{option}"
499 def datatype_sql(self, expression: exp.DataType) -> str: 500 if expression.is_type(exp.DType.ARRAY): 501 if expression.expressions: 502 values = self.expressions(expression, key="values", flat=True) 503 return f"{self.expressions(expression, flat=True)}[{values}]" 504 return "ARRAY" 505 506 if expression.is_type(exp.DType.ENUM): 507 return f"ENUM ({self.expressions(expression, flat=True)})" 508 509 if expression.is_type(exp.DType.DOUBLE, exp.DType.FLOAT) and expression.expressions: 510 # Postgres doesn't support precision for REAL and DOUBLE PRECISION types 511 return f"FLOAT({self.expressions(expression, flat=True)})" 512 513 return super().datatype_sql(expression)
def
cast_sql( self, expression: sqlglot.expressions.functions.Cast, safe_prefix: str | None = None) -> str:
515 def cast_sql(self, expression: exp.Cast, safe_prefix: str | None = None) -> str: 516 this = expression.this 517 518 # Postgres casts DIV() to decimal for transpilation but when roundtripping it's superfluous 519 if isinstance(this, exp.IntDiv) and expression.to == exp.DType.DECIMAL.into_expr(): 520 return self.sql(this) 521 522 return super().cast_sql(expression, safe_prefix=safe_prefix)
524 def array_sql(self, expression: exp.Array) -> str: 525 exprs = expression.expressions 526 func_name = self.normalize_func("ARRAY") 527 528 if isinstance(seq_get(exprs, 0), exp.Query): 529 return f"{func_name}({self.sql(exprs[0])})" 530 531 return f"{func_name}{inline_array_sql(self, expression)}"
def
computedcolumnconstraint_sql( self, expression: sqlglot.expressions.constraints.ComputedColumnConstraint) -> str:
@unsupported_args('this')
def
currentschema_sql(self, expression: sqlglot.expressions.functions.CurrentSchema) -> str:
553 def interval_sql(self, expression: exp.Interval) -> str: 554 unit = expression.text("unit").lower() 555 556 this = expression.this 557 if unit.startswith("quarter") and isinstance(this, exp.Literal): 558 this.replace(exp.Literal.string(int(this.to_py()) * 3)) 559 expression.args["unit"].replace(exp.var("MONTH")) 560 561 return super().interval_sql(expression)
570 def arraycontains_sql(self, expression: exp.ArrayContains) -> str: 571 # Convert DuckDB's LIST_CONTAINS(array, value) to PostgreSQL 572 # DuckDB behavior: 573 # - LIST_CONTAINS([1,2,3], 2) -> true 574 # - LIST_CONTAINS([1,2,3], 4) -> false 575 # - LIST_CONTAINS([1,2,NULL], 4) -> false (not NULL) 576 # - LIST_CONTAINS([1,2,3], NULL) -> NULL 577 # 578 # PostgreSQL equivalent: CASE WHEN value IS NULL THEN NULL 579 # ELSE COALESCE(value = ANY(array), FALSE) END 580 value = expression.expression 581 array = expression.this 582 583 coalesce_expr = exp.Coalesce( 584 this=value.eq(exp.Any(this=exp.paren(expression=array, copy=False))), 585 expressions=[exp.false()], 586 ) 587 588 case_expr = ( 589 exp.Case() 590 .when(exp.Is(this=value, expression=exp.null()), exp.null(), copy=False) 591 .else_(coalesce_expr, copy=False) 592 ) 593 594 return self.sql(case_expr)
Inherited Members
- sqlglot.generator.Generator
- Generator
- NULL_ORDERING_SUPPORTED
- WINDOW_FUNCS_WITH_NULL_ORDERING
- IGNORE_NULLS_IN_FUNC
- IGNORE_NULLS_BEFORE_ORDER
- EXCEPT_INTERSECT_SUPPORT_ALL_CLAUSE
- WRAP_DERIVED_VALUES
- CREATE_FUNCTION_RETURN_AS
- MATCHED_BY_SOURCE
- SUPPORTS_MERGE_WHERE
- INTERVAL_ALLOWS_PLURAL_FORM
- AUTO_REFRESH_BARE_INTERVALS
- LIMIT_FETCH
- LIMIT_ONLY_LITERALS
- GROUPINGS_SEP
- INDEX_ON
- 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_KEYWORDS
- TABLESAMPLE_WITH_METHOD
- 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_TABLE_ALIAS_COLUMNS
- SUPPORTS_NAMED_CTE_COLUMNS
- UNPIVOT_ALIASES_ARE_IDENTIFIERS
- PIVOT_ALIAS_WITH_AS
- JSON_KEY_VALUE_PAIR_SEP
- INSERT_OVERWRITE
- SUPPORTS_CREATE_TABLE_LIKE
- SUPPORTS_MODIFY_COLUMN
- SUPPORTS_CHANGE_COLUMN
- JSON_PATH_BRACKETED_KEY_SUPPORTED
- JSON_PATH_SINGLE_QUOTE_ESCAPE
- JSON_PATH_KEY_QUOTED_FORCES_BRACKETS
- SUPPORTS_TO_NUMBER
- SET_OP_MODIFIERS
- COPY_PARAMS_ARE_WRAPPED
- COPY_PARAMS_EQ_REQUIRED
- SUPPORTS_UESCAPE
- UNICODE_SUBSTITUTE
- STAR_EXCEPT
- HEX_FUNC
- WITH_PROPERTIES_PREFIX
- QUOTE_JSON_PATH
- PAD_FILL_PATTERN_IS_REQUIRED
- SUPPORTS_EXPLODING_PROJECTIONS
- SUPPORTS_CONVERT_TIMEZONE
- SUPPORTS_UNIX_SECONDS
- ALTER_SET_WRAPPED
- NORMALIZE_EXTRACT_DATE_PARTS
- PARSE_JSON_NAME
- ARRAY_SIZE_NAME
- ALTER_SET_TYPE
- 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
- TOKEN_MAPPING
- STRUCT_DELIMITER
- 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
- 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
- columnconstraint_sql
- autoincrementcolumnconstraint_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
- 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
- insert_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
- 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
- subquery_sql
- qualify_sql
- prewhere_sql
- where_sql
- window_sql
- partition_by_sql
- windowspec_sql
- withingroup_sql
- between_sql
- bracket_offset_expressions
- 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
- 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
- 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
- transaction_sql
- commit_sql
- rollback_sql
- altercolumn_sql
- modifycolumn_sql
- alterindex_sql
- alterdiststyle_sql
- altersortkey_sql
- alterrename_sql
- renamecolumn_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
- 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
- dateadd_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
- whileblock_sql
- execute_sql
- executesql_sql
- altermodifysqlsecurity_sql
- usingproperty_sql
- renameindex_sql