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 ensure_list, 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 path = expression.expression 188 # Single non-literal segment: render as infix, not JSON_EXTRACT_PATH[_TEXT] (jsonb-unsafe). 189 if not isinstance(path, (exp.JSONPath, exp.Variadic)) and not ensure_list( 190 expression.args.get("expressions") 191 ): 192 return self.binary(expression, op) 193 194 if expression.args.get("only_json_types"): 195 return json_extract_segments(name, quoted_index=False, op=op)(self, expression) 196 return json_extract_segments(name)(self, expression) 197 198 return _generate 199 200 201def _unix_to_time_sql(self: PostgresGenerator, expression: exp.UnixToTime) -> str: 202 scale = expression.args.get("scale") 203 timestamp = expression.this 204 205 if scale in (None, exp.UnixToTime.SECONDS): 206 return self.func("TO_TIMESTAMP", timestamp, self.format_time(expression)) 207 208 return self.func( 209 "TO_TIMESTAMP", 210 exp.Div(this=timestamp, expression=exp.func("POW", 10, scale)), 211 self.format_time(expression), 212 ) 213 214 215def _levenshtein_sql(self: PostgresGenerator, expression: exp.Levenshtein) -> str: 216 name = "LEVENSHTEIN_LESS_EQUAL" if expression.args.get("max_dist") else "LEVENSHTEIN" 217 218 return rename_func(name)(self, expression) 219 220 221def _versioned_anyvalue_sql(self: PostgresGenerator, expression: exp.AnyValue) -> str: 222 # https://www.postgresql.org/docs/16/functions-aggregate.html 223 # https://www.postgresql.org/about/featurematrix/ 224 if self.dialect.version < (16,): 225 return any_value_to_max_sql(self, expression) 226 227 return rename_func("ANY_VALUE")(self, expression) 228 229 230def _round_sql(self: PostgresGenerator, expression: exp.Round) -> str: 231 this = self.sql(expression, "this") 232 decimals = self.sql(expression, "decimals") 233 234 if not decimals: 235 return self.func("ROUND", this) 236 237 if not expression.type: 238 from sqlglot.optimizer.annotate_types import annotate_types 239 240 expression = annotate_types(expression, dialect=self.dialect) 241 242 # ROUND(double precision, integer) is not permitted in Postgres 243 # so it's necessary to cast to decimal before rounding. 244 if expression.this.is_type(exp.DType.DOUBLE): 245 decimal_type = exp.DType.DECIMAL.into_expr(expressions=expression.expressions) 246 this = self.sql(exp.Cast(this=this, to=decimal_type)) 247 248 return self.func("ROUND", this, decimals) 249 250 251class PostgresGenerator(generator.Generator): 252 SELECT_KINDS: tuple[str, ...] = () 253 TRY_SUPPORTED = False 254 SUPPORTS_DECODE_CASE = False 255 256 AFTER_HAVING_MODIFIER_TRANSFORMS = generator.AFTER_HAVING_MODIFIER_TRANSFORMS 257 258 SINGLE_STRING_INTERVAL = True 259 RENAME_TABLE_WITH_DB = False 260 LOCKING_READS_SUPPORTED = True 261 JOIN_HINTS = False 262 TABLE_HINTS = False 263 QUERY_HINTS = False 264 NVL2_SUPPORTED = False 265 PARAMETER_TOKEN = "$" 266 NAMED_PLACEHOLDER_TOKEN = "%" 267 TABLESAMPLE_SIZE_IS_ROWS = False 268 TABLESAMPLE_SEED_KEYWORD = "REPEATABLE" 269 SUPPORTS_SELECT_INTO = True 270 JSON_TYPE_REQUIRED_FOR_EXTRACTION = True 271 SUPPORTS_UNLOGGED_TABLES = True 272 LIKE_PROPERTY_INSIDE_SCHEMA = True 273 MULTI_ARG_DISTINCT = False 274 CAN_IMPLEMENT_ARRAY_ANY = True 275 SUPPORTS_WINDOW_EXCLUDE = True 276 COPY_HAS_INTO_KEYWORD = False 277 ARRAY_CONCAT_IS_VAR_LEN = False 278 SUPPORTS_MEDIAN = False 279 ARRAY_SIZE_DIM_REQUIRED: bool | None = True 280 SUPPORTS_BETWEEN_FLAGS = True 281 INOUT_SEPARATOR = "" # PostgreSQL uses "INOUT" (no space) 282 283 SUPPORTED_JSON_PATH_PARTS = { 284 exp.JSONPathKey, 285 exp.JSONPathRoot, 286 exp.JSONPathSubscript, 287 } 288 289 def lateral_sql(self, expression: exp.Lateral) -> str: 290 sql = super().lateral_sql(expression) 291 292 if expression.args.get("cross_apply") is not None: 293 sql = f"{sql} ON TRUE" 294 295 return sql 296 297 TYPE_MAPPING = { 298 **generator.Generator.TYPE_MAPPING, 299 exp.DType.TINYINT: "SMALLINT", 300 exp.DType.FLOAT: "REAL", 301 exp.DType.DOUBLE: "DOUBLE PRECISION", 302 exp.DType.BINARY: "BYTEA", 303 exp.DType.VARBINARY: "BYTEA", 304 exp.DType.ROWVERSION: "BYTEA", 305 exp.DType.DATETIME: "TIMESTAMP", 306 exp.DType.TIMESTAMPNTZ: "TIMESTAMP", 307 exp.DType.BLOB: "BYTEA", 308 } 309 310 TRANSFORMS = { 311 **{ 312 k: v 313 for k, v in generator.Generator.TRANSFORMS.items() 314 if k != exp.CommentColumnConstraint 315 }, 316 exp.AnyValue: _versioned_anyvalue_sql, 317 exp.ArrayConcat: array_concat_sql("ARRAY_CAT"), 318 exp.ArrayFilter: filter_array_using_unnest, 319 exp.ArrayAppend: array_append_sql("ARRAY_APPEND"), 320 exp.ArrayPrepend: array_append_sql("ARRAY_PREPEND", swap_params=True), 321 exp.BitwiseAndAgg: rename_func("BIT_AND"), 322 exp.BitwiseOrAgg: rename_func("BIT_OR"), 323 exp.BitwiseXor: lambda self, e: self.binary(e, "#"), 324 exp.BitwiseXorAgg: rename_func("BIT_XOR"), 325 exp.ColumnDef: transforms.preprocess([_auto_increment_to_serial, _serial_to_generated]), 326 exp.CurrentDate: no_paren_current_date_sql, 327 exp.CurrentTimestamp: lambda *_: "CURRENT_TIMESTAMP", 328 exp.CurrentUser: lambda *_: "CURRENT_USER", 329 exp.CurrentVersion: rename_func("VERSION"), 330 exp.DateAdd: _date_add_sql("+"), 331 exp.DateDiff: _date_diff_sql, 332 exp.DateStrToDate: datestrtodate_sql, 333 exp.DateSub: _date_add_sql("-"), 334 exp.Day: _day_month_year_sql, 335 exp.Explode: rename_func("UNNEST"), 336 exp.ExplodingGenerateSeries: rename_func("GENERATE_SERIES"), 337 exp.GenerateSeries: generate_series_sql("GENERATE_SERIES"), 338 exp.Getbit: getbit_sql, 339 exp.GroupConcat: lambda self, e: groupconcat_sql( 340 self, e, func_name="STRING_AGG", within_group=False 341 ), 342 exp.IntDiv: rename_func("DIV"), 343 exp.JSONArrayAgg: lambda self, e: self.func( 344 "JSON_AGG", 345 self.sql(e, "this"), 346 suffix=f"{self.sql(e, 'order')})", 347 ), 348 exp.JSONExtract: _json_extract_sql("JSON_EXTRACT_PATH", "->"), 349 exp.JSONExtractScalar: _json_extract_sql("JSON_EXTRACT_PATH_TEXT", "->>"), 350 exp.JSONBExtract: lambda self, e: self.binary(e, "#>"), 351 exp.JSONBExtractScalar: lambda self, e: self.binary(e, "#>>"), 352 exp.JSONBContains: lambda self, e: self.binary(e, "?"), 353 exp.ParseJSON: lambda self, e: self.sql(exp.cast(e.this, exp.DType.JSON)), 354 exp.JSONPathKey: json_path_key_only_name, 355 exp.JSONPathRoot: lambda *_: "", 356 exp.JSONPathSubscript: lambda self, e: self.json_path_part(e.this), 357 exp.LastDay: no_last_day_sql, 358 exp.LogicalOr: rename_func("BOOL_OR"), 359 exp.LogicalAnd: rename_func("BOOL_AND"), 360 exp.Max: max_or_greatest, 361 exp.MapFromEntries: no_map_from_entries_sql, 362 exp.Min: min_or_least, 363 exp.Merge: merge_without_target_sql, 364 exp.Month: _day_month_year_sql, 365 exp.PartitionedByProperty: lambda self, e: f"PARTITION BY {self.sql(e, 'this')}", 366 exp.PercentileCont: transforms.preprocess([transforms.add_within_group_for_percentiles]), 367 exp.PercentileDisc: transforms.preprocess([transforms.add_within_group_for_percentiles]), 368 exp.Pivot: no_pivot_sql, 369 exp.Rand: rename_func("RANDOM"), 370 exp.RegexpLike: lambda self, e: self.binary(e, "~"), 371 exp.RegexpILike: lambda self, e: self.binary(e, "~*"), 372 exp.RegexpReplace: lambda self, e: self.func( 373 "REGEXP_REPLACE", 374 e.this, 375 e.expression, 376 e.args.get("replacement"), 377 e.args.get("position"), 378 e.args.get("occurrence"), 379 regexp_replace_global_modifier(e), 380 ), 381 exp.Round: _round_sql, 382 exp.Select: transforms.preprocess( 383 [ 384 transforms.eliminate_semi_and_anti_joins, 385 transforms.eliminate_qualify, 386 ] 387 ), 388 exp.SHA2: sha256_sql, 389 exp.SHA2Digest: sha2_digest_sql, 390 exp.StrPosition: lambda self, e: strposition_sql(self, e, func_name="POSITION"), 391 exp.StrToDate: lambda self, e: self.func("TO_DATE", e.this, self.format_time(e)), 392 exp.StrToTime: lambda self, e: self.func("TO_TIMESTAMP", e.this, self.format_time(e)), 393 exp.StructExtract: struct_extract_sql, 394 exp.Substring: _substring_sql, 395 exp.TimeFromParts: rename_func("MAKE_TIME"), 396 exp.TimestampFromParts: rename_func("MAKE_TIMESTAMP"), 397 exp.TimestampTrunc: timestamptrunc_sql(zone=True), 398 exp.TimeStrToTime: timestrtotime_sql, 399 exp.TimeToStr: lambda self, e: self.func("TO_CHAR", e.this, self.format_time(e)), 400 exp.ToChar: lambda self, e: ( 401 self.function_fallback_sql(e) if e.args.get("format") else self.tochar_sql(e) 402 ), 403 exp.Trim: trim_sql, 404 exp.TryCast: no_trycast_sql, 405 exp.TsOrDsAdd: _date_add_sql("+"), 406 exp.TsOrDsDiff: _date_diff_sql, 407 exp.UnixToTime: lambda self, e: self.func("TO_TIMESTAMP", e.this), 408 exp.Uuid: lambda *_: "GEN_RANDOM_UUID()", 409 exp.TimeToUnix: lambda self, e: self.func("DATE_PART", exp.Literal.string("epoch"), e.this), 410 exp.VariancePop: rename_func("VAR_POP"), 411 exp.Variance: rename_func("VAR_SAMP"), 412 exp.Xor: bool_xor_sql, 413 exp.Year: _day_month_year_sql, 414 exp.Unicode: rename_func("ASCII"), 415 exp.UnixToTime: _unix_to_time_sql, 416 exp.Levenshtein: _levenshtein_sql, 417 exp.JSONObjectAgg: rename_func("JSON_OBJECT_AGG"), 418 exp.JSONBObjectAgg: rename_func("JSONB_OBJECT_AGG"), 419 exp.CountIf: count_if_to_sum, 420 } 421 422 PROPERTIES_LOCATION = { 423 **generator.Generator.PROPERTIES_LOCATION, 424 exp.PartitionedByProperty: exp.Properties.Location.POST_SCHEMA, 425 exp.TransientProperty: exp.Properties.Location.UNSUPPORTED, 426 exp.VolatileProperty: exp.Properties.Location.UNSUPPORTED, 427 } 428 429 def schemacommentproperty_sql(self, expression: exp.SchemaCommentProperty) -> str: 430 self.unsupported("Table comments are not supported in the CREATE statement") 431 return "" 432 433 def commentcolumnconstraint_sql(self, expression: exp.CommentColumnConstraint) -> str: 434 self.unsupported("Column comments are not supported in the CREATE statement") 435 return "" 436 437 def columndef_sql(self, expression: exp.ColumnDef, sep: str = " ") -> str: 438 # PostgreSQL places parameter modes BEFORE parameter name 439 param_constraint = expression.find(exp.InOutColumnConstraint) 440 441 if param_constraint: 442 mode_sql = self.sql(param_constraint) 443 param_constraint.pop() # Remove to prevent double-rendering 444 base_sql = super().columndef_sql(expression, sep) 445 return f"{mode_sql} {base_sql}" 446 447 return super().columndef_sql(expression, sep) 448 449 def unnest_sql(self, expression: exp.Unnest) -> str: 450 if len(expression.expressions) == 1: 451 arg = expression.expressions[0] 452 if isinstance(arg, exp.GenerateDateArray): 453 generate_series: exp.Expr = exp.GenerateSeries(**arg.args) 454 if isinstance(expression.parent, (exp.From, exp.Join)): 455 generate_series = ( 456 exp.select("value::date") 457 .from_(exp.Table(this=generate_series).as_("_t", table=["value"])) 458 .subquery(expression.args.get("alias") or "_unnested_generate_series") 459 ) 460 return self.sql(generate_series) 461 462 from sqlglot.optimizer.annotate_types import annotate_types 463 464 this = annotate_types(arg, dialect=self.dialect) 465 if this.is_type("array<json>"): 466 while isinstance(this, exp.Cast): 467 this = this.this 468 469 arg_as_json = self.sql(exp.cast(this, exp.DType.JSON)) 470 alias = self.sql(expression, "alias") 471 alias = f" AS {alias}" if alias else "" 472 473 if expression.args.get("offset"): 474 self.unsupported("Unsupported JSON_ARRAY_ELEMENTS with offset") 475 476 return f"JSON_ARRAY_ELEMENTS({arg_as_json}){alias}" 477 478 return super().unnest_sql(expression) 479 480 def bracket_sql(self, expression: exp.Bracket) -> str: 481 """Forms like ARRAY[1, 2, 3][3] aren't allowed; we need to wrap the ARRAY.""" 482 if isinstance(expression.this, exp.Array): 483 expression.set("this", exp.paren(expression.this, copy=False)) 484 485 return super().bracket_sql(expression) 486 487 def matchagainst_sql(self, expression: exp.MatchAgainst) -> str: 488 this = self.sql(expression, "this") 489 expressions = [f"{self.sql(e)} @@ {this}" for e in expression.expressions] 490 sql = " OR ".join(expressions) 491 return f"({sql})" if len(expressions) > 1 else sql 492 493 def alterset_sql(self, expression: exp.AlterSet) -> str: 494 exprs = self.expressions(expression, flat=True) 495 exprs = f"({exprs})" if exprs else "" 496 497 access_method = self.sql(expression, "access_method") 498 access_method = f"ACCESS METHOD {access_method}" if access_method else "" 499 tablespace = self.sql(expression, "tablespace") 500 tablespace = f"TABLESPACE {tablespace}" if tablespace else "" 501 option = self.sql(expression, "option") 502 503 return f"SET {exprs}{access_method}{tablespace}{option}" 504 505 def datatype_sql(self, expression: exp.DataType) -> str: 506 if expression.is_type(exp.DType.ARRAY): 507 if expression.expressions: 508 values = self.expressions(expression, key="values", flat=True) 509 return f"{self.expressions(expression, flat=True)}[{values}]" 510 return "ARRAY" 511 512 if expression.is_type(exp.DType.ENUM): 513 return f"ENUM ({self.expressions(expression, flat=True)})" 514 515 if expression.is_type(exp.DType.DOUBLE, exp.DType.FLOAT) and expression.expressions: 516 # Postgres doesn't support precision for REAL and DOUBLE PRECISION types 517 return f"FLOAT({self.expressions(expression, flat=True)})" 518 519 return super().datatype_sql(expression) 520 521 def cast_sql(self, expression: exp.Cast, safe_prefix: str | None = None) -> str: 522 this = expression.this 523 524 # Postgres casts DIV() to decimal for transpilation but when roundtripping it's superfluous 525 if isinstance(this, exp.IntDiv) and expression.to == exp.DType.DECIMAL.into_expr(): 526 return self.sql(this) 527 528 return super().cast_sql(expression, safe_prefix=safe_prefix) 529 530 def array_sql(self, expression: exp.Array) -> str: 531 exprs = expression.expressions 532 func_name = self.normalize_func("ARRAY") 533 534 if isinstance(seq_get(exprs, 0), exp.Query): 535 return f"{func_name}({self.sql(exprs[0])})" 536 537 return f"{func_name}{inline_array_sql(self, expression)}" 538 539 def computedcolumnconstraint_sql(self, expression: exp.ComputedColumnConstraint) -> str: 540 return f"GENERATED ALWAYS AS ({self.sql(expression, 'this')}) STORED" 541 542 def isascii_sql(self, expression: exp.IsAscii) -> str: 543 return f"({self.sql(expression.this)} ~ '^[[:ascii:]]*$')" 544 545 def ignorenulls_sql(self, expression: exp.IgnoreNulls) -> str: 546 # https://www.postgresql.org/docs/current/functions-window.html 547 self.unsupported("PostgreSQL does not support IGNORE NULLS.") 548 return self.sql(expression.this) 549 550 def respectnulls_sql(self, expression: exp.RespectNulls) -> str: 551 # https://www.postgresql.org/docs/current/functions-window.html 552 self.unsupported("PostgreSQL does not support RESPECT NULLS.") 553 return self.sql(expression.this) 554 555 @unsupported_args("this") 556 def currentschema_sql(self, expression: exp.CurrentSchema) -> str: 557 return "CURRENT_SCHEMA" 558 559 def interval_sql(self, expression: exp.Interval) -> str: 560 unit = expression.text("unit").lower() 561 562 this = expression.this 563 if unit.startswith("quarter") and isinstance(this, exp.Literal): 564 this.replace(exp.Literal.string(int(this.to_py()) * 3)) 565 expression.args["unit"].replace(exp.var("MONTH")) 566 567 return super().interval_sql(expression) 568 569 def placeholder_sql(self, expression: exp.Placeholder) -> str: 570 if expression.args.get("jdbc"): 571 return "?" 572 573 this = f"({expression.name})" if expression.this else "" 574 return f"{self.NAMED_PLACEHOLDER_TOKEN}{this}s" 575 576 def arraycontains_sql(self, expression: exp.ArrayContains) -> str: 577 # Convert DuckDB's LIST_CONTAINS(array, value) to PostgreSQL 578 # DuckDB behavior: 579 # - LIST_CONTAINS([1,2,3], 2) -> true 580 # - LIST_CONTAINS([1,2,3], 4) -> false 581 # - LIST_CONTAINS([1,2,NULL], 4) -> false (not NULL) 582 # - LIST_CONTAINS([1,2,3], NULL) -> NULL 583 # 584 # PostgreSQL equivalent: CASE WHEN value IS NULL THEN NULL 585 # ELSE COALESCE(value = ANY(array), FALSE) END 586 value = expression.expression 587 array = expression.this 588 589 coalesce_expr = exp.Coalesce( 590 this=value.eq(exp.Any(this=exp.paren(expression=array, copy=False))), 591 expressions=[exp.false()], 592 ) 593 594 case_expr = ( 595 exp.Case() 596 .when(exp.Is(this=value, expression=exp.null()), exp.null(), copy=False) 597 .else_(coalesce_expr, copy=False) 598 ) 599 600 return self.sql(case_expr)
DATE_DIFF_FACTOR =
{'MICROSECOND': ' * 1000000', 'MILLISECOND': ' * 1000', 'SECOND': '', 'MINUTE': ' / 60', 'HOUR': ' / 3600', 'DAY': ' / 86400'}
252class PostgresGenerator(generator.Generator): 253 SELECT_KINDS: tuple[str, ...] = () 254 TRY_SUPPORTED = False 255 SUPPORTS_DECODE_CASE = False 256 257 AFTER_HAVING_MODIFIER_TRANSFORMS = generator.AFTER_HAVING_MODIFIER_TRANSFORMS 258 259 SINGLE_STRING_INTERVAL = True 260 RENAME_TABLE_WITH_DB = False 261 LOCKING_READS_SUPPORTED = True 262 JOIN_HINTS = False 263 TABLE_HINTS = False 264 QUERY_HINTS = False 265 NVL2_SUPPORTED = False 266 PARAMETER_TOKEN = "$" 267 NAMED_PLACEHOLDER_TOKEN = "%" 268 TABLESAMPLE_SIZE_IS_ROWS = False 269 TABLESAMPLE_SEED_KEYWORD = "REPEATABLE" 270 SUPPORTS_SELECT_INTO = True 271 JSON_TYPE_REQUIRED_FOR_EXTRACTION = True 272 SUPPORTS_UNLOGGED_TABLES = True 273 LIKE_PROPERTY_INSIDE_SCHEMA = True 274 MULTI_ARG_DISTINCT = False 275 CAN_IMPLEMENT_ARRAY_ANY = True 276 SUPPORTS_WINDOW_EXCLUDE = True 277 COPY_HAS_INTO_KEYWORD = False 278 ARRAY_CONCAT_IS_VAR_LEN = False 279 SUPPORTS_MEDIAN = False 280 ARRAY_SIZE_DIM_REQUIRED: bool | None = True 281 SUPPORTS_BETWEEN_FLAGS = True 282 INOUT_SEPARATOR = "" # PostgreSQL uses "INOUT" (no space) 283 284 SUPPORTED_JSON_PATH_PARTS = { 285 exp.JSONPathKey, 286 exp.JSONPathRoot, 287 exp.JSONPathSubscript, 288 } 289 290 def lateral_sql(self, expression: exp.Lateral) -> str: 291 sql = super().lateral_sql(expression) 292 293 if expression.args.get("cross_apply") is not None: 294 sql = f"{sql} ON TRUE" 295 296 return sql 297 298 TYPE_MAPPING = { 299 **generator.Generator.TYPE_MAPPING, 300 exp.DType.TINYINT: "SMALLINT", 301 exp.DType.FLOAT: "REAL", 302 exp.DType.DOUBLE: "DOUBLE PRECISION", 303 exp.DType.BINARY: "BYTEA", 304 exp.DType.VARBINARY: "BYTEA", 305 exp.DType.ROWVERSION: "BYTEA", 306 exp.DType.DATETIME: "TIMESTAMP", 307 exp.DType.TIMESTAMPNTZ: "TIMESTAMP", 308 exp.DType.BLOB: "BYTEA", 309 } 310 311 TRANSFORMS = { 312 **{ 313 k: v 314 for k, v in generator.Generator.TRANSFORMS.items() 315 if k != exp.CommentColumnConstraint 316 }, 317 exp.AnyValue: _versioned_anyvalue_sql, 318 exp.ArrayConcat: array_concat_sql("ARRAY_CAT"), 319 exp.ArrayFilter: filter_array_using_unnest, 320 exp.ArrayAppend: array_append_sql("ARRAY_APPEND"), 321 exp.ArrayPrepend: array_append_sql("ARRAY_PREPEND", swap_params=True), 322 exp.BitwiseAndAgg: rename_func("BIT_AND"), 323 exp.BitwiseOrAgg: rename_func("BIT_OR"), 324 exp.BitwiseXor: lambda self, e: self.binary(e, "#"), 325 exp.BitwiseXorAgg: rename_func("BIT_XOR"), 326 exp.ColumnDef: transforms.preprocess([_auto_increment_to_serial, _serial_to_generated]), 327 exp.CurrentDate: no_paren_current_date_sql, 328 exp.CurrentTimestamp: lambda *_: "CURRENT_TIMESTAMP", 329 exp.CurrentUser: lambda *_: "CURRENT_USER", 330 exp.CurrentVersion: rename_func("VERSION"), 331 exp.DateAdd: _date_add_sql("+"), 332 exp.DateDiff: _date_diff_sql, 333 exp.DateStrToDate: datestrtodate_sql, 334 exp.DateSub: _date_add_sql("-"), 335 exp.Day: _day_month_year_sql, 336 exp.Explode: rename_func("UNNEST"), 337 exp.ExplodingGenerateSeries: rename_func("GENERATE_SERIES"), 338 exp.GenerateSeries: generate_series_sql("GENERATE_SERIES"), 339 exp.Getbit: getbit_sql, 340 exp.GroupConcat: lambda self, e: groupconcat_sql( 341 self, e, func_name="STRING_AGG", within_group=False 342 ), 343 exp.IntDiv: rename_func("DIV"), 344 exp.JSONArrayAgg: lambda self, e: self.func( 345 "JSON_AGG", 346 self.sql(e, "this"), 347 suffix=f"{self.sql(e, 'order')})", 348 ), 349 exp.JSONExtract: _json_extract_sql("JSON_EXTRACT_PATH", "->"), 350 exp.JSONExtractScalar: _json_extract_sql("JSON_EXTRACT_PATH_TEXT", "->>"), 351 exp.JSONBExtract: lambda self, e: self.binary(e, "#>"), 352 exp.JSONBExtractScalar: lambda self, e: self.binary(e, "#>>"), 353 exp.JSONBContains: lambda self, e: self.binary(e, "?"), 354 exp.ParseJSON: lambda self, e: self.sql(exp.cast(e.this, exp.DType.JSON)), 355 exp.JSONPathKey: json_path_key_only_name, 356 exp.JSONPathRoot: lambda *_: "", 357 exp.JSONPathSubscript: lambda self, e: self.json_path_part(e.this), 358 exp.LastDay: no_last_day_sql, 359 exp.LogicalOr: rename_func("BOOL_OR"), 360 exp.LogicalAnd: rename_func("BOOL_AND"), 361 exp.Max: max_or_greatest, 362 exp.MapFromEntries: no_map_from_entries_sql, 363 exp.Min: min_or_least, 364 exp.Merge: merge_without_target_sql, 365 exp.Month: _day_month_year_sql, 366 exp.PartitionedByProperty: lambda self, e: f"PARTITION BY {self.sql(e, 'this')}", 367 exp.PercentileCont: transforms.preprocess([transforms.add_within_group_for_percentiles]), 368 exp.PercentileDisc: transforms.preprocess([transforms.add_within_group_for_percentiles]), 369 exp.Pivot: no_pivot_sql, 370 exp.Rand: rename_func("RANDOM"), 371 exp.RegexpLike: lambda self, e: self.binary(e, "~"), 372 exp.RegexpILike: lambda self, e: self.binary(e, "~*"), 373 exp.RegexpReplace: lambda self, e: self.func( 374 "REGEXP_REPLACE", 375 e.this, 376 e.expression, 377 e.args.get("replacement"), 378 e.args.get("position"), 379 e.args.get("occurrence"), 380 regexp_replace_global_modifier(e), 381 ), 382 exp.Round: _round_sql, 383 exp.Select: transforms.preprocess( 384 [ 385 transforms.eliminate_semi_and_anti_joins, 386 transforms.eliminate_qualify, 387 ] 388 ), 389 exp.SHA2: sha256_sql, 390 exp.SHA2Digest: sha2_digest_sql, 391 exp.StrPosition: lambda self, e: strposition_sql(self, e, func_name="POSITION"), 392 exp.StrToDate: lambda self, e: self.func("TO_DATE", e.this, self.format_time(e)), 393 exp.StrToTime: lambda self, e: self.func("TO_TIMESTAMP", e.this, self.format_time(e)), 394 exp.StructExtract: struct_extract_sql, 395 exp.Substring: _substring_sql, 396 exp.TimeFromParts: rename_func("MAKE_TIME"), 397 exp.TimestampFromParts: rename_func("MAKE_TIMESTAMP"), 398 exp.TimestampTrunc: timestamptrunc_sql(zone=True), 399 exp.TimeStrToTime: timestrtotime_sql, 400 exp.TimeToStr: lambda self, e: self.func("TO_CHAR", e.this, self.format_time(e)), 401 exp.ToChar: lambda self, e: ( 402 self.function_fallback_sql(e) if e.args.get("format") else self.tochar_sql(e) 403 ), 404 exp.Trim: trim_sql, 405 exp.TryCast: no_trycast_sql, 406 exp.TsOrDsAdd: _date_add_sql("+"), 407 exp.TsOrDsDiff: _date_diff_sql, 408 exp.UnixToTime: lambda self, e: self.func("TO_TIMESTAMP", e.this), 409 exp.Uuid: lambda *_: "GEN_RANDOM_UUID()", 410 exp.TimeToUnix: lambda self, e: self.func("DATE_PART", exp.Literal.string("epoch"), e.this), 411 exp.VariancePop: rename_func("VAR_POP"), 412 exp.Variance: rename_func("VAR_SAMP"), 413 exp.Xor: bool_xor_sql, 414 exp.Year: _day_month_year_sql, 415 exp.Unicode: rename_func("ASCII"), 416 exp.UnixToTime: _unix_to_time_sql, 417 exp.Levenshtein: _levenshtein_sql, 418 exp.JSONObjectAgg: rename_func("JSON_OBJECT_AGG"), 419 exp.JSONBObjectAgg: rename_func("JSONB_OBJECT_AGG"), 420 exp.CountIf: count_if_to_sum, 421 } 422 423 PROPERTIES_LOCATION = { 424 **generator.Generator.PROPERTIES_LOCATION, 425 exp.PartitionedByProperty: exp.Properties.Location.POST_SCHEMA, 426 exp.TransientProperty: exp.Properties.Location.UNSUPPORTED, 427 exp.VolatileProperty: exp.Properties.Location.UNSUPPORTED, 428 } 429 430 def schemacommentproperty_sql(self, expression: exp.SchemaCommentProperty) -> str: 431 self.unsupported("Table comments are not supported in the CREATE statement") 432 return "" 433 434 def commentcolumnconstraint_sql(self, expression: exp.CommentColumnConstraint) -> str: 435 self.unsupported("Column comments are not supported in the CREATE statement") 436 return "" 437 438 def columndef_sql(self, expression: exp.ColumnDef, sep: str = " ") -> str: 439 # PostgreSQL places parameter modes BEFORE parameter name 440 param_constraint = expression.find(exp.InOutColumnConstraint) 441 442 if param_constraint: 443 mode_sql = self.sql(param_constraint) 444 param_constraint.pop() # Remove to prevent double-rendering 445 base_sql = super().columndef_sql(expression, sep) 446 return f"{mode_sql} {base_sql}" 447 448 return super().columndef_sql(expression, sep) 449 450 def unnest_sql(self, expression: exp.Unnest) -> str: 451 if len(expression.expressions) == 1: 452 arg = expression.expressions[0] 453 if isinstance(arg, exp.GenerateDateArray): 454 generate_series: exp.Expr = exp.GenerateSeries(**arg.args) 455 if isinstance(expression.parent, (exp.From, exp.Join)): 456 generate_series = ( 457 exp.select("value::date") 458 .from_(exp.Table(this=generate_series).as_("_t", table=["value"])) 459 .subquery(expression.args.get("alias") or "_unnested_generate_series") 460 ) 461 return self.sql(generate_series) 462 463 from sqlglot.optimizer.annotate_types import annotate_types 464 465 this = annotate_types(arg, dialect=self.dialect) 466 if this.is_type("array<json>"): 467 while isinstance(this, exp.Cast): 468 this = this.this 469 470 arg_as_json = self.sql(exp.cast(this, exp.DType.JSON)) 471 alias = self.sql(expression, "alias") 472 alias = f" AS {alias}" if alias else "" 473 474 if expression.args.get("offset"): 475 self.unsupported("Unsupported JSON_ARRAY_ELEMENTS with offset") 476 477 return f"JSON_ARRAY_ELEMENTS({arg_as_json}){alias}" 478 479 return super().unnest_sql(expression) 480 481 def bracket_sql(self, expression: exp.Bracket) -> str: 482 """Forms like ARRAY[1, 2, 3][3] aren't allowed; we need to wrap the ARRAY.""" 483 if isinstance(expression.this, exp.Array): 484 expression.set("this", exp.paren(expression.this, copy=False)) 485 486 return super().bracket_sql(expression) 487 488 def matchagainst_sql(self, expression: exp.MatchAgainst) -> str: 489 this = self.sql(expression, "this") 490 expressions = [f"{self.sql(e)} @@ {this}" for e in expression.expressions] 491 sql = " OR ".join(expressions) 492 return f"({sql})" if len(expressions) > 1 else sql 493 494 def alterset_sql(self, expression: exp.AlterSet) -> str: 495 exprs = self.expressions(expression, flat=True) 496 exprs = f"({exprs})" if exprs else "" 497 498 access_method = self.sql(expression, "access_method") 499 access_method = f"ACCESS METHOD {access_method}" if access_method else "" 500 tablespace = self.sql(expression, "tablespace") 501 tablespace = f"TABLESPACE {tablespace}" if tablespace else "" 502 option = self.sql(expression, "option") 503 504 return f"SET {exprs}{access_method}{tablespace}{option}" 505 506 def datatype_sql(self, expression: exp.DataType) -> str: 507 if expression.is_type(exp.DType.ARRAY): 508 if expression.expressions: 509 values = self.expressions(expression, key="values", flat=True) 510 return f"{self.expressions(expression, flat=True)}[{values}]" 511 return "ARRAY" 512 513 if expression.is_type(exp.DType.ENUM): 514 return f"ENUM ({self.expressions(expression, flat=True)})" 515 516 if expression.is_type(exp.DType.DOUBLE, exp.DType.FLOAT) and expression.expressions: 517 # Postgres doesn't support precision for REAL and DOUBLE PRECISION types 518 return f"FLOAT({self.expressions(expression, flat=True)})" 519 520 return super().datatype_sql(expression) 521 522 def cast_sql(self, expression: exp.Cast, safe_prefix: str | None = None) -> str: 523 this = expression.this 524 525 # Postgres casts DIV() to decimal for transpilation but when roundtripping it's superfluous 526 if isinstance(this, exp.IntDiv) and expression.to == exp.DType.DECIMAL.into_expr(): 527 return self.sql(this) 528 529 return super().cast_sql(expression, safe_prefix=safe_prefix) 530 531 def array_sql(self, expression: exp.Array) -> str: 532 exprs = expression.expressions 533 func_name = self.normalize_func("ARRAY") 534 535 if isinstance(seq_get(exprs, 0), exp.Query): 536 return f"{func_name}({self.sql(exprs[0])})" 537 538 return f"{func_name}{inline_array_sql(self, expression)}" 539 540 def computedcolumnconstraint_sql(self, expression: exp.ComputedColumnConstraint) -> str: 541 return f"GENERATED ALWAYS AS ({self.sql(expression, 'this')}) STORED" 542 543 def isascii_sql(self, expression: exp.IsAscii) -> str: 544 return f"({self.sql(expression.this)} ~ '^[[:ascii:]]*$')" 545 546 def ignorenulls_sql(self, expression: exp.IgnoreNulls) -> str: 547 # https://www.postgresql.org/docs/current/functions-window.html 548 self.unsupported("PostgreSQL does not support IGNORE NULLS.") 549 return self.sql(expression.this) 550 551 def respectnulls_sql(self, expression: exp.RespectNulls) -> str: 552 # https://www.postgresql.org/docs/current/functions-window.html 553 self.unsupported("PostgreSQL does not support RESPECT NULLS.") 554 return self.sql(expression.this) 555 556 @unsupported_args("this") 557 def currentschema_sql(self, expression: exp.CurrentSchema) -> str: 558 return "CURRENT_SCHEMA" 559 560 def interval_sql(self, expression: exp.Interval) -> str: 561 unit = expression.text("unit").lower() 562 563 this = expression.this 564 if unit.startswith("quarter") and isinstance(this, exp.Literal): 565 this.replace(exp.Literal.string(int(this.to_py()) * 3)) 566 expression.args["unit"].replace(exp.var("MONTH")) 567 568 return super().interval_sql(expression) 569 570 def placeholder_sql(self, expression: exp.Placeholder) -> str: 571 if expression.args.get("jdbc"): 572 return "?" 573 574 this = f"({expression.name})" if expression.this else "" 575 return f"{self.NAMED_PLACEHOLDER_TOKEN}{this}s" 576 577 def arraycontains_sql(self, expression: exp.ArrayContains) -> str: 578 # Convert DuckDB's LIST_CONTAINS(array, value) to PostgreSQL 579 # DuckDB behavior: 580 # - LIST_CONTAINS([1,2,3], 2) -> true 581 # - LIST_CONTAINS([1,2,3], 4) -> false 582 # - LIST_CONTAINS([1,2,NULL], 4) -> false (not NULL) 583 # - LIST_CONTAINS([1,2,3], NULL) -> NULL 584 # 585 # PostgreSQL equivalent: CASE WHEN value IS NULL THEN NULL 586 # ELSE COALESCE(value = ANY(array), FALSE) END 587 value = expression.expression 588 array = expression.this 589 590 coalesce_expr = exp.Coalesce( 591 this=value.eq(exp.Any(this=exp.paren(expression=array, copy=False))), 592 expressions=[exp.false()], 593 ) 594 595 case_expr = ( 596 exp.Case() 597 .when(exp.Is(this=value, expression=exp.null()), exp.null(), copy=False) 598 .else_(coalesce_expr, copy=False) 599 ) 600 601 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.JSONPathSubscript'>, <class 'sqlglot.expressions.query.JSONPathRoot'>}
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:
438 def columndef_sql(self, expression: exp.ColumnDef, sep: str = " ") -> str: 439 # PostgreSQL places parameter modes BEFORE parameter name 440 param_constraint = expression.find(exp.InOutColumnConstraint) 441 442 if param_constraint: 443 mode_sql = self.sql(param_constraint) 444 param_constraint.pop() # Remove to prevent double-rendering 445 base_sql = super().columndef_sql(expression, sep) 446 return f"{mode_sql} {base_sql}" 447 448 return super().columndef_sql(expression, sep)
450 def unnest_sql(self, expression: exp.Unnest) -> str: 451 if len(expression.expressions) == 1: 452 arg = expression.expressions[0] 453 if isinstance(arg, exp.GenerateDateArray): 454 generate_series: exp.Expr = exp.GenerateSeries(**arg.args) 455 if isinstance(expression.parent, (exp.From, exp.Join)): 456 generate_series = ( 457 exp.select("value::date") 458 .from_(exp.Table(this=generate_series).as_("_t", table=["value"])) 459 .subquery(expression.args.get("alias") or "_unnested_generate_series") 460 ) 461 return self.sql(generate_series) 462 463 from sqlglot.optimizer.annotate_types import annotate_types 464 465 this = annotate_types(arg, dialect=self.dialect) 466 if this.is_type("array<json>"): 467 while isinstance(this, exp.Cast): 468 this = this.this 469 470 arg_as_json = self.sql(exp.cast(this, exp.DType.JSON)) 471 alias = self.sql(expression, "alias") 472 alias = f" AS {alias}" if alias else "" 473 474 if expression.args.get("offset"): 475 self.unsupported("Unsupported JSON_ARRAY_ELEMENTS with offset") 476 477 return f"JSON_ARRAY_ELEMENTS({arg_as_json}){alias}" 478 479 return super().unnest_sql(expression)
481 def bracket_sql(self, expression: exp.Bracket) -> str: 482 """Forms like ARRAY[1, 2, 3][3] aren't allowed; we need to wrap the ARRAY.""" 483 if isinstance(expression.this, exp.Array): 484 expression.set("this", exp.paren(expression.this, copy=False)) 485 486 return super().bracket_sql(expression)
Forms like ARRAY[1, 2, 3][3] aren't allowed; we need to wrap the ARRAY.
494 def alterset_sql(self, expression: exp.AlterSet) -> str: 495 exprs = self.expressions(expression, flat=True) 496 exprs = f"({exprs})" if exprs else "" 497 498 access_method = self.sql(expression, "access_method") 499 access_method = f"ACCESS METHOD {access_method}" if access_method else "" 500 tablespace = self.sql(expression, "tablespace") 501 tablespace = f"TABLESPACE {tablespace}" if tablespace else "" 502 option = self.sql(expression, "option") 503 504 return f"SET {exprs}{access_method}{tablespace}{option}"
506 def datatype_sql(self, expression: exp.DataType) -> str: 507 if expression.is_type(exp.DType.ARRAY): 508 if expression.expressions: 509 values = self.expressions(expression, key="values", flat=True) 510 return f"{self.expressions(expression, flat=True)}[{values}]" 511 return "ARRAY" 512 513 if expression.is_type(exp.DType.ENUM): 514 return f"ENUM ({self.expressions(expression, flat=True)})" 515 516 if expression.is_type(exp.DType.DOUBLE, exp.DType.FLOAT) and expression.expressions: 517 # Postgres doesn't support precision for REAL and DOUBLE PRECISION types 518 return f"FLOAT({self.expressions(expression, flat=True)})" 519 520 return super().datatype_sql(expression)
def
cast_sql( self, expression: sqlglot.expressions.functions.Cast, safe_prefix: str | None = None) -> str:
522 def cast_sql(self, expression: exp.Cast, safe_prefix: str | None = None) -> str: 523 this = expression.this 524 525 # Postgres casts DIV() to decimal for transpilation but when roundtripping it's superfluous 526 if isinstance(this, exp.IntDiv) and expression.to == exp.DType.DECIMAL.into_expr(): 527 return self.sql(this) 528 529 return super().cast_sql(expression, safe_prefix=safe_prefix)
531 def array_sql(self, expression: exp.Array) -> str: 532 exprs = expression.expressions 533 func_name = self.normalize_func("ARRAY") 534 535 if isinstance(seq_get(exprs, 0), exp.Query): 536 return f"{func_name}({self.sql(exprs[0])})" 537 538 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:
560 def interval_sql(self, expression: exp.Interval) -> str: 561 unit = expression.text("unit").lower() 562 563 this = expression.this 564 if unit.startswith("quarter") and isinstance(this, exp.Literal): 565 this.replace(exp.Literal.string(int(this.to_py()) * 3)) 566 expression.args["unit"].replace(exp.var("MONTH")) 567 568 return super().interval_sql(expression)
577 def arraycontains_sql(self, expression: exp.ArrayContains) -> str: 578 # Convert DuckDB's LIST_CONTAINS(array, value) to PostgreSQL 579 # DuckDB behavior: 580 # - LIST_CONTAINS([1,2,3], 2) -> true 581 # - LIST_CONTAINS([1,2,3], 4) -> false 582 # - LIST_CONTAINS([1,2,NULL], 4) -> false (not NULL) 583 # - LIST_CONTAINS([1,2,3], NULL) -> NULL 584 # 585 # PostgreSQL equivalent: CASE WHEN value IS NULL THEN NULL 586 # ELSE COALESCE(value = ANY(array), FALSE) END 587 value = expression.expression 588 array = expression.this 589 590 coalesce_expr = exp.Coalesce( 591 this=value.eq(exp.Any(this=exp.paren(expression=array, copy=False))), 592 expressions=[exp.false()], 593 ) 594 595 case_expr = ( 596 exp.Case() 597 .when(exp.Is(this=value, expression=exp.null()), exp.null(), copy=False) 598 .else_(coalesce_expr, copy=False) 599 ) 600 601 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
- SUPPORTS_ALTER_COLUMN_NULLABILITY
- SUPPORTS_ALTER_COLUMN_IF_EXISTS
- 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
- casestatement_sql
- whileblock_sql
- loopblock_sql
- repeatblock_sql
- leave_sql
- iterate_sql
- execute_sql
- executesql_sql
- altermodifysqlsecurity_sql
- usingproperty_sql
- renameindex_sql