sqlglotc 30.29.0__tar.gz → 30.31.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (117) hide show
  1. {sqlglotc-30.29.0/sqlglotc.egg-info → sqlglotc-30.31.0}/PKG-INFO +2 -2
  2. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglot/expressions/aggregate.py +2 -2
  3. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglot/expressions/core.py +23 -1
  4. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglot/expressions/properties.py +12 -0
  5. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglot/expressions/query.py +21 -9
  6. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglot/expressions/string.py +3 -1
  7. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglot/expressions/temporal.py +1 -1
  8. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglot/generator.py +51 -10
  9. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglot/generators/bigquery.py +1 -0
  10. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglot/generators/clickhouse.py +13 -0
  11. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglot/generators/databricks.py +21 -0
  12. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglot/generators/druid.py +2 -2
  13. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglot/generators/duckdb.py +50 -21
  14. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglot/generators/exasol.py +2 -1
  15. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglot/generators/oracle.py +2 -1
  16. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglot/generators/postgres.py +7 -1
  17. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglot/generators/redshift.py +7 -0
  18. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglot/generators/snowflake.py +7 -8
  19. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglot/generators/spark2.py +5 -1
  20. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglot/generators/sqlite.py +30 -1
  21. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglot/generators/teradata.py +10 -0
  22. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglot/optimizer/annotate_types.py +11 -5
  23. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglot/optimizer/qualify_columns.py +128 -26
  24. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglot/optimizer/resolver.py +46 -10
  25. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglot/optimizer/scope.py +21 -1
  26. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglot/optimizer/simplify.py +15 -2
  27. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglot/parser.py +76 -28
  28. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglot/parsers/base.py +2 -0
  29. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglot/parsers/bigquery.py +5 -1
  30. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglot/parsers/duckdb.py +12 -0
  31. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglot/parsers/hive.py +5 -7
  32. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglot/parsers/mysql.py +2 -0
  33. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglot/parsers/postgres.py +2 -0
  34. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglot/parsers/presto.py +10 -1
  35. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglot/parsers/snowflake.py +13 -1
  36. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglot/parsers/spark.py +5 -0
  37. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglot/parsers/spark2.py +13 -0
  38. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglot/parsers/sqlite.py +8 -0
  39. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglot/parsers/starrocks.py +3 -0
  40. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglot/parsers/teradata.py +56 -12
  41. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglot/tokenizer_core.py +16 -2
  42. {sqlglotc-30.29.0 → sqlglotc-30.31.0/sqlglotc.egg-info}/PKG-INFO +2 -2
  43. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglotc.egg-info/requires.txt +1 -1
  44. sqlglotc-30.31.0/sqlglotc.egg-info/scm_version.json +8 -0
  45. sqlglotc-30.29.0/sqlglotc.egg-info/scm_version.json +0 -8
  46. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/MANIFEST.in +0 -0
  47. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/pyproject.toml +0 -0
  48. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/setup.cfg +0 -0
  49. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/setup.py +0 -0
  50. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglot/anonymize.py +0 -0
  51. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglot/errors.py +0 -0
  52. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglot/executor/table.py +0 -0
  53. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglot/expressions/array.py +0 -0
  54. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglot/expressions/builders.py +0 -0
  55. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglot/expressions/constraints.py +0 -0
  56. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglot/expressions/datatypes.py +0 -0
  57. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglot/expressions/ddl.py +0 -0
  58. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglot/expressions/dml.py +0 -0
  59. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglot/expressions/functions.py +0 -0
  60. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglot/expressions/json.py +0 -0
  61. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglot/expressions/math.py +0 -0
  62. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglot/generators/athena.py +0 -0
  63. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglot/generators/dax.py +0 -0
  64. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglot/generators/doris.py +0 -0
  65. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglot/generators/dremio.py +0 -0
  66. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglot/generators/drill.py +0 -0
  67. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglot/generators/dune.py +0 -0
  68. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglot/generators/fabric.py +0 -0
  69. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglot/generators/hive.py +0 -0
  70. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglot/generators/materialize.py +0 -0
  71. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglot/generators/mysql.py +0 -0
  72. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglot/generators/presto.py +0 -0
  73. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglot/generators/prql.py +0 -0
  74. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglot/generators/python.py +0 -0
  75. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglot/generators/risingwave.py +0 -0
  76. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglot/generators/singlestore.py +0 -0
  77. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglot/generators/solr.py +0 -0
  78. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglot/generators/spark.py +0 -0
  79. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglot/generators/starrocks.py +0 -0
  80. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglot/generators/tableau.py +0 -0
  81. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglot/generators/trino.py +0 -0
  82. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglot/generators/tsql.py +0 -0
  83. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglot/helper.py +0 -0
  84. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglot/lineage.py +0 -0
  85. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglot/optimizer/canonicalize_internal_names.py +0 -0
  86. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglot/optimizer/isolate_table_selects.py +0 -0
  87. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglot/optimizer/normalize_identifiers.py +0 -0
  88. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglot/optimizer/qualify.py +0 -0
  89. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglot/optimizer/qualify_tables.py +0 -0
  90. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglot/parsers/athena.py +0 -0
  91. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglot/parsers/clickhouse.py +0 -0
  92. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglot/parsers/databricks.py +0 -0
  93. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglot/parsers/dax.py +0 -0
  94. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglot/parsers/doris.py +0 -0
  95. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglot/parsers/dremio.py +0 -0
  96. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglot/parsers/drill.py +0 -0
  97. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglot/parsers/druid.py +0 -0
  98. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglot/parsers/dune.py +0 -0
  99. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglot/parsers/exasol.py +0 -0
  100. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglot/parsers/fabric.py +0 -0
  101. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglot/parsers/materialize.py +0 -0
  102. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglot/parsers/oracle.py +0 -0
  103. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglot/parsers/prql.py +0 -0
  104. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglot/parsers/redshift.py +0 -0
  105. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglot/parsers/risingwave.py +0 -0
  106. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglot/parsers/singlestore.py +0 -0
  107. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglot/parsers/solr.py +0 -0
  108. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglot/parsers/tableau.py +0 -0
  109. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglot/parsers/trino.py +0 -0
  110. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglot/parsers/tsql.py +0 -0
  111. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglot/serde.py +0 -0
  112. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglot/time.py +0 -0
  113. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglot/trie.py +0 -0
  114. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglotc.egg-info/SOURCES.txt +0 -0
  115. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglotc.egg-info/dependency_links.txt +0 -0
  116. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglotc.egg-info/scm_file_list.json +0 -0
  117. {sqlglotc-30.29.0 → sqlglotc-30.31.0}/sqlglotc.egg-info/top_level.txt +0 -0
@@ -1,13 +1,13 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sqlglotc
3
- Version: 30.29.0
3
+ Version: 30.31.0
4
4
  Summary: mypyc-compiled extensions for sqlglot
5
5
  Author-email: Toby Mao <toby.mao@gmail.com>
6
6
  License-Expression: MIT
7
7
  Project-URL: Homepage, https://sqlglot.com/
8
8
  Project-URL: Repository, https://github.com/tobymao/sqlglot
9
9
  Requires-Python: >=3.10
10
- Requires-Dist: sqlglot==30.29.0
10
+ Requires-Dist: sqlglot==30.31.0
11
11
  Provides-Extra: dev
12
12
  Requires-Dist: setuptools>=61.0; extra == "dev"
13
13
  Requires-Dist: setuptools_scm>=10.2; extra == "dev"
@@ -180,7 +180,7 @@ class LogicalOr(Expression, AggFunc):
180
180
 
181
181
 
182
182
  class Max(Expression, AggFunc):
183
- arg_types = {"this": True, "expressions": False}
183
+ arg_types = {"this": True, "expressions": False, "count": False}
184
184
  is_var_len_args = True
185
185
 
186
186
 
@@ -189,7 +189,7 @@ class Median(Expression, AggFunc):
189
189
 
190
190
 
191
191
  class Min(Expression, AggFunc):
192
- arg_types = {"this": True, "expressions": False}
192
+ arg_types = {"this": True, "expressions": False, "count": False}
193
193
  is_var_len_args = True
194
194
 
195
195
 
@@ -2240,7 +2240,7 @@ class LTE(Expression, Binary, Predicate):
2240
2240
 
2241
2241
 
2242
2242
  class Mod(Expression, Binary):
2243
- pass
2243
+ arg_types = {"this": True, "expression": True, "safe": False}
2244
2244
 
2245
2245
 
2246
2246
  class Mul(Expression, Binary):
@@ -2317,6 +2317,28 @@ class FormatPhrase(Expression):
2317
2317
 
2318
2318
  arg_types = {"this": True, "format": True}
2319
2319
 
2320
+ @property
2321
+ def name(self) -> str:
2322
+ return self.this.name
2323
+
2324
+ @property
2325
+ def output_name(self) -> str:
2326
+ return self.this.output_name
2327
+
2328
+
2329
+ class TeradataTitle(Expression):
2330
+ """A Teradata TITLE display heading, which does not rename the expression."""
2331
+
2332
+ arg_types = {"this": True, "title": True}
2333
+
2334
+ @property
2335
+ def name(self) -> str:
2336
+ return self.this.name
2337
+
2338
+ @property
2339
+ def output_name(self) -> str:
2340
+ return self.this.output_name
2341
+
2320
2342
 
2321
2343
  class Between(Expression, Predicate):
2322
2344
  arg_types = {"this": True, "low": True, "high": True, "symmetric": False}
@@ -210,6 +210,10 @@ class IcebergProperty(Property):
210
210
  arg_types = {}
211
211
 
212
212
 
213
+ class IgnoreGrantsProperty(Property):
214
+ arg_types = {}
215
+
216
+
213
217
  class InheritsProperty(Property):
214
218
  arg_types = {"expressions": True}
215
219
 
@@ -334,6 +338,10 @@ class OnCommitProperty(Property):
334
338
  arg_types = {"delete": False}
335
339
 
336
340
 
341
+ class OptionsProperty(Property):
342
+ arg_types = {"expressions": True}
343
+
344
+
337
345
  class PartitionedByProperty(Property):
338
346
  arg_types = {"this": True}
339
347
 
@@ -423,6 +431,10 @@ class StrictProperty(Property):
423
431
  arg_types = {}
424
432
 
425
433
 
434
+ class WithoutRowidProperty(Property):
435
+ arg_types = {}
436
+
437
+
426
438
  class RowFormatProperty(Property):
427
439
  arg_types = {"this": True}
428
440
 
@@ -1111,15 +1111,27 @@ class SetOperation(Expression, Query):
1111
1111
 
1112
1112
  @property
1113
1113
  def named_selects(self) -> list[str]:
1114
- expr: Expr = self
1115
- while isinstance(expr, SetOperation):
1116
- if expr.args.get("by_name"):
1117
- left = t.cast(Selectable, expr.this.unnest()).named_selects
1118
- right = t.cast(Selectable, expr.expression.unnest()).named_selects
1119
- return list(dict.fromkeys(left + right))
1120
-
1121
- expr = expr.this.unnest()
1122
- return _named_selects(expr)
1114
+ names = []
1115
+ stack: list[Expr] = [self]
1116
+ by_name = False
1117
+
1118
+ while stack:
1119
+ expr = stack.pop()
1120
+ if not isinstance(expr, SetOperation):
1121
+ names.extend(t.cast(Selectable, expr).named_selects)
1122
+ continue
1123
+
1124
+ while isinstance(expr, SetOperation):
1125
+ if expr.args.get("by_name"):
1126
+ by_name = True
1127
+ stack.append(expr.expression.unnest())
1128
+ stack.append(expr.this.unnest())
1129
+ break
1130
+ expr = expr.this.unnest()
1131
+ else:
1132
+ names.extend(_named_selects(expr))
1133
+
1134
+ return list(dict.fromkeys(names)) if by_name else names
1123
1135
 
1124
1136
  @property
1125
1137
  def is_star(self) -> bool:
@@ -435,7 +435,9 @@ class RegexpExtract(Expression, Func):
435
435
  "occurrence": False,
436
436
  "parameters": False,
437
437
  "group": False,
438
- "null_if_pos_overflow": False, # for transpilation target behavior
438
+ "null_if_pos_overflow": False,
439
+ "null_if_no_match": False,
440
+ "empty_if_group_missing": False,
439
441
  }
440
442
 
441
443
 
@@ -192,7 +192,7 @@ class TimestampTrunc(Expression, Func, TimeUnit):
192
192
 
193
193
 
194
194
  class TimeSlice(Expression, Func, TimeUnit):
195
- arg_types = {"this": True, "expression": True, "unit": True, "kind": False}
195
+ arg_types = {"this": True, "expression": True, "unit": True, "kind": False, "origin": False}
196
196
 
197
197
 
198
198
  class TimeTrunc(Expression, Func, TimeUnit):
@@ -202,6 +202,7 @@ class Generator:
202
202
  exp.HeapProperty: lambda *_: "HEAP",
203
203
  exp.HybridProperty: lambda *_: "HYBRID",
204
204
  exp.IcebergProperty: lambda *_: "ICEBERG",
205
+ exp.IgnoreGrantsProperty: lambda *_: "IGNORE GRANTS",
205
206
  exp.InheritsProperty: lambda self, e: f"INHERITS ({self.expressions(e, flat=True)})",
206
207
  exp.InlineLengthColumnConstraint: lambda self, e: f"INLINE LENGTH {self.sql(e, 'this')}",
207
208
  exp.InputModelProperty: lambda self, e: f"INPUT{self.sql(e, 'this')}",
@@ -297,6 +298,7 @@ class Generator:
297
298
  exp.WithProcedureOptions: lambda self, e: f"WITH {self.expressions(e, flat=True)}",
298
299
  exp.WithSchemaBindingProperty: lambda self, e: f"WITH SCHEMA {self.sql(e, 'this')}",
299
300
  exp.WithOperator: lambda self, e: f"{self.sql(e, 'this')} WITH {self.sql(e, 'op')}",
301
+ exp.WithoutRowidProperty: lambda *_: "WITHOUT ROWID",
300
302
  exp.ForceProperty: lambda *_: "FORCE",
301
303
  }
302
304
 
@@ -350,7 +352,7 @@ class Generator:
350
352
  # Whether limit and fetch are supported (possible values: "ALL", "LIMIT", "FETCH")
351
353
  LIMIT_FETCH = "ALL"
352
354
 
353
- # Whether limit and fetch allows expresions or just limits
355
+ # Whether limit and fetch allows expressions or just limits
354
356
  LIMIT_ONLY_LITERALS = False
355
357
 
356
358
  # Whether a table is allowed to be renamed with a db
@@ -745,8 +747,8 @@ class Generator:
745
747
  exp.DictRange: exp.Properties.Location.POST_SCHEMA,
746
748
  exp.DictProperty: exp.Properties.Location.POST_SCHEMA,
747
749
  exp.DynamicProperty: exp.Properties.Location.POST_CREATE,
748
- exp.DistKeyProperty: exp.Properties.Location.POST_SCHEMA,
749
- exp.DistStyleProperty: exp.Properties.Location.POST_SCHEMA,
750
+ exp.DistKeyProperty: exp.Properties.Location.UNSUPPORTED,
751
+ exp.DistStyleProperty: exp.Properties.Location.UNSUPPORTED,
750
752
  exp.EmptyProperty: exp.Properties.Location.POST_SCHEMA,
751
753
  exp.EncodeProperty: exp.Properties.Location.POST_EXPRESSION,
752
754
  exp.EngineProperty: exp.Properties.Location.POST_SCHEMA,
@@ -763,6 +765,7 @@ class Generator:
763
765
  exp.HybridProperty: exp.Properties.Location.POST_CREATE,
764
766
  exp.InheritsProperty: exp.Properties.Location.POST_SCHEMA,
765
767
  exp.IcebergProperty: exp.Properties.Location.POST_CREATE,
768
+ exp.IgnoreGrantsProperty: exp.Properties.Location.POST_SCHEMA,
766
769
  exp.IncludeProperty: exp.Properties.Location.POST_SCHEMA,
767
770
  exp.InputModelProperty: exp.Properties.Location.POST_SCHEMA,
768
771
  exp.InteractiveProperty: exp.Properties.Location.UNSUPPORTED,
@@ -782,6 +785,7 @@ class Generator:
782
785
  exp.NoPrimaryIndexProperty: exp.Properties.Location.POST_EXPRESSION,
783
786
  exp.OnProperty: exp.Properties.Location.POST_SCHEMA,
784
787
  exp.OnCommitProperty: exp.Properties.Location.POST_EXPRESSION,
788
+ exp.OptionsProperty: exp.Properties.Location.UNSUPPORTED,
785
789
  exp.Order: exp.Properties.Location.POST_SCHEMA,
786
790
  exp.OutputModelProperty: exp.Properties.Location.POST_SCHEMA,
787
791
  exp.PartitionedByProperty: exp.Properties.Location.POST_WITH,
@@ -809,7 +813,7 @@ class Generator:
809
813
  exp.SharingProperty: exp.Properties.Location.POST_EXPRESSION,
810
814
  exp.SequenceProperties: exp.Properties.Location.POST_EXPRESSION,
811
815
  exp.TriggerProperties: exp.Properties.Location.POST_EXPRESSION,
812
- exp.SortKeyProperty: exp.Properties.Location.POST_SCHEMA,
816
+ exp.SortKeyProperty: exp.Properties.Location.UNSUPPORTED,
813
817
  exp.SqlReadWriteProperty: exp.Properties.Location.POST_SCHEMA,
814
818
  exp.SqlSecurityProperty: exp.Properties.Location.POST_SCHEMA,
815
819
  exp.StabilityProperty: exp.Properties.Location.POST_SCHEMA,
@@ -835,6 +839,7 @@ class Generator:
835
839
  exp.WithProcedureOptions: exp.Properties.Location.POST_SCHEMA,
836
840
  exp.WithSchemaBindingProperty: exp.Properties.Location.POST_SCHEMA,
837
841
  exp.WithSystemVersioningProperty: exp.Properties.Location.POST_SCHEMA,
842
+ exp.WithoutRowidProperty: exp.Properties.Location.UNSUPPORTED,
838
843
  exp.ForceProperty: exp.Properties.Location.POST_CREATE,
839
844
  }
840
845
 
@@ -2069,7 +2074,13 @@ class Generator:
2069
2074
  return f"{this} FILTER({where})"
2070
2075
 
2071
2076
  def per_sql(self, expression: exp.Per) -> str:
2072
- return f"{self.sql(expression, 'this')} PER ({self.expressions(expression, flat=True)})"
2077
+ keys = ", ".join(
2078
+ f"{self.sql(key, 'this')} {self.sql(key, 'with_fill')}"
2079
+ if isinstance(key, exp.Ordered) and key.args.get("with_fill")
2080
+ else self.sql(key)
2081
+ for key in expression.expressions
2082
+ )
2083
+ return f"{self.sql(expression, 'this')} PER ({keys})"
2073
2084
 
2074
2085
  def hint_sql(self, expression: exp.Hint) -> str:
2075
2086
  if not self.QUERY_HINTS:
@@ -4044,6 +4055,10 @@ class Generator:
4044
4055
  fmt = self.sql(expression, "format")
4045
4056
  return f"{this} (FORMAT {fmt})"
4046
4057
 
4058
+ def teradatatitle_sql(self, expression: exp.TeradataTitle) -> str:
4059
+ self.unsupported("Teradata TITLE display headings are not supported")
4060
+ return self.sql(expression, "this")
4061
+
4047
4062
  def _jsonobject_sql(
4048
4063
  self, expression: exp.JSONObject | exp.JSONObjectAgg, name: str = ""
4049
4064
  ) -> str:
@@ -4682,11 +4697,14 @@ class Generator:
4682
4697
  return self.func("CONCAT", *(exp.cast(e, exp.DType.TEXT) for e in expression.flatten()))
4683
4698
  return self.binary(expression, "||")
4684
4699
 
4700
+ def nullif_zero_divisor(self, expression: exp.Div | exp.Mod) -> None:
4701
+ if not self.dialect.SAFE_DIVISION and expression.args.get("safe"):
4702
+ divisor = expression.right
4703
+ divisor.replace(exp.Nullif(this=divisor.copy(), expression=exp.Literal.number(0)))
4704
+
4685
4705
  def div_sql(self, expression: exp.Div) -> str:
4686
4706
  l, r = expression.left, expression.right
4687
-
4688
- if not self.dialect.SAFE_DIVISION and expression.args.get("safe"):
4689
- r.replace(exp.Nullif(this=r.copy(), expression=exp.Literal.number(0)))
4707
+ self.nullif_zero_divisor(expression)
4690
4708
 
4691
4709
  if self.dialect.TYPED_DIVISION and not expression.args.get("typed"):
4692
4710
  if not l.is_type(*exp.DataType.REAL_TYPES) and not r.is_type(*exp.DataType.REAL_TYPES):
@@ -4700,8 +4718,8 @@ class Generator:
4700
4718
  if all(e.is_int or isinstance(e, exp.Cast) for e in (l, r)) and (
4701
4719
  expression.args.get("safe") or not self.SAFE_INT_DIVISION
4702
4720
  ):
4703
- return self.sql(exp.IntDiv(this=l, expression=r))
4704
- return self._truncated_div_sql(l, r)
4721
+ return self.sql(exp.IntDiv(this=l, expression=expression.right))
4722
+ return self._truncated_div_sql(l, expression.right)
4705
4723
 
4706
4724
  return self.binary(expression, "/")
4707
4725
 
@@ -4825,6 +4843,7 @@ class Generator:
4825
4843
  return self.binary(expression, "<=")
4826
4844
 
4827
4845
  def mod_sql(self, expression: exp.Mod) -> str:
4846
+ self.nullif_zero_divisor(expression)
4828
4847
  this = self.sql(expression, "this")
4829
4848
  expr = self.sql(expression, "expression")
4830
4849
  sql = f"{this} {self.maybe_comment(self.MOD_OPERATOR, comments=expression.comments)} {expr}"
@@ -6053,6 +6072,14 @@ class Generator:
6053
6072
 
6054
6073
  return array_agg_sql
6055
6074
 
6075
+ @unsupported_args("count")
6076
+ def min_sql(self, expression: exp.Min) -> str:
6077
+ return self.function_fallback_sql(expression)
6078
+
6079
+ @unsupported_args("count")
6080
+ def max_sql(self, expression: exp.Max) -> str:
6081
+ return self.function_fallback_sql(expression)
6082
+
6056
6083
  def arrayagg_sql(self, expression: exp.ArrayAgg) -> str:
6057
6084
  array_agg = self.function_fallback_sql(expression)
6058
6085
  column_expr = expression.this
@@ -6061,7 +6088,21 @@ class Generator:
6061
6088
 
6062
6089
  return self._add_arrayagg_null_filter(array_agg, expression, column_expr)
6063
6090
 
6091
+ def timeslice_sql(self, expression: exp.TimeSlice) -> str:
6092
+ # Only the SQLGlot dialect serializes the internal origin for round-tripping.
6093
+ origin = expression.args.get("origin") if self.dialect == "" else None
6094
+ kind = expression.args.get("kind")
6095
+ if origin is not None and kind is None:
6096
+ kind = exp.Literal.string("START")
6097
+
6098
+ return self.func(
6099
+ "TIME_SLICE", expression.this, expression.expression, expression.unit, kind, origin
6100
+ )
6101
+
6064
6102
  def slice_sql(self, expression: exp.Slice) -> str:
6103
+ if "[" in self.dialect.tokenizer_class._IDENTIFIERS:
6104
+ self.unsupported("Slices are not supported")
6105
+
6065
6106
  step = self.sql(expression, "step")
6066
6107
  # An omitted end is written as `-` before a step, since `::` is the cast operator
6067
6108
  end = self.sql(expression.expression) or ("-" if step else "")
@@ -779,6 +779,7 @@ class BigQueryGenerator(generator.Generator):
779
779
  return self.func("DATE_TRUNC", expression.this, unit_sql, expression.args.get("zone"))
780
780
 
781
781
  def mod_sql(self, expression: exp.Mod) -> str:
782
+ self.nullif_zero_divisor(expression)
782
783
  this = expression.this
783
784
  expr = expression.expression
784
785
  return self.func(
@@ -769,6 +769,19 @@ class ClickHouseGenerator(generator.Generator):
769
769
  else:
770
770
  values_as_table = True
771
771
 
772
+ # An unparenthesized VALUES in FROM is the values() table function, which takes a single
773
+ # argument list, so a multi-row VALUES relation must be parenthesized to parse
774
+ if (
775
+ values_as_table
776
+ and len(expression.expressions) > 1
777
+ and (alias or isinstance(expression.parent, (exp.From, exp.Join, exp.Table)))
778
+ ):
779
+ values = f"(VALUES{self.seg('')}{self.expressions(expression)})"
780
+ values = self.query_modifiers(expression, values)
781
+ pivots = self.expressions(expression, key="pivots", sep="", flat=True)
782
+ alias_sql = self.sql(alias)
783
+ return f"{values} AS {alias_sql}{pivots}" if alias_sql else f"{values}{pivots}"
784
+
772
785
  return super().values_sql(expression, values_as_table=values_as_table)
773
786
 
774
787
  def timestamptrunc_sql(self, expression: exp.DateTrunc | exp.TimestampTrunc) -> str:
@@ -10,6 +10,16 @@ from sqlglot.dialects.dialect import (
10
10
  from sqlglot.generators.spark import SparkGenerator
11
11
 
12
12
 
13
+ TIMESTAMP_TYPES = {
14
+ exp.DType.DATETIME,
15
+ exp.DType.TIME,
16
+ exp.DType.TIMESTAMP,
17
+ exp.DType.TIMESTAMPNTZ,
18
+ exp.DType.TIMESTAMPLTZ,
19
+ exp.DType.TIMESTAMPTZ,
20
+ }
21
+
22
+
13
23
  class DatabricksGenerator(SparkGenerator):
14
24
  TABLESAMPLE_SEED_KEYWORD = "REPEATABLE"
15
25
  COPY_PARAMS_ARE_WRAPPED = False
@@ -70,6 +80,17 @@ class DatabricksGenerator(SparkGenerator):
70
80
  exp.DType.NULL: "VOID",
71
81
  }
72
82
 
83
+ def datatype_sql(self, expression: exp.DataType) -> str:
84
+ # Databricks only supports a timestamp precision of 6 (microseconds) or 7 to 9
85
+ # (nanoseconds), so drop any other precision it would reject, e.g. TIMESTAMP(0)
86
+ if expression.this in TIMESTAMP_TYPES and expression.expressions:
87
+ param = expression.expressions[0]
88
+ param = param.this if isinstance(param, exp.DataTypeParam) else param
89
+ if param.is_int and not 6 <= param.to_py() <= 9:
90
+ expression.set("expressions", None)
91
+
92
+ return super().datatype_sql(expression)
93
+
73
94
  def create_sql(self, expression: exp.Create) -> str:
74
95
  body = expression.expression
75
96
  if (
@@ -2,7 +2,7 @@ from __future__ import annotations
2
2
 
3
3
 
4
4
  from sqlglot import exp, generator
5
- from sqlglot.dialects.dialect import rename_func
5
+ from sqlglot.dialects.dialect import mod_func_sql
6
6
 
7
7
 
8
8
  class DruidGenerator(generator.Generator):
@@ -25,6 +25,6 @@ class DruidGenerator(generator.Generator):
25
25
  TRANSFORMS = {
26
26
  **generator.Generator.TRANSFORMS,
27
27
  exp.CurrentTimestamp: lambda *_: "CURRENT_TIMESTAMP",
28
- exp.Mod: rename_func("MOD"),
28
+ exp.Mod: mod_func_sql,
29
29
  exp.Array: lambda self, e: f"ARRAY[{self.expressions(e)}]",
30
30
  }
@@ -24,6 +24,7 @@ from sqlglot.dialects.dialect import (
24
24
  getbit_sql,
25
25
  groupconcat_sql,
26
26
  inline_array_unless_query,
27
+ map_date_part,
27
28
  months_between_sql,
28
29
  no_datetime_sql,
29
30
  no_comment_column_constraint_sql,
@@ -1254,8 +1255,8 @@ def _build_capitalization_sql(
1254
1255
  if delimiters_sql == "''":
1255
1256
  return f"UPPER(LEFT({value_to_split}, 1)) || LOWER(SUBSTRING({value_to_split}, 2))"
1256
1257
 
1257
- delim_regex_sql = f"CONCAT('[', {delimiters_sql}, ']')"
1258
- split_regex_sql = f"CONCAT('([', {delimiters_sql}, ']+|[^', {delimiters_sql}, ']+)')"
1258
+ delim_regex_sql = f"'[' || {delimiters_sql} || ']'"
1259
+ split_regex_sql = f"'([' || {delimiters_sql} || ']+|[^' || {delimiters_sql} || ']+)'"
1259
1260
 
1260
1261
  # REGEXP_EXTRACT_ALL produces a list of string segments, alternating between delimiter and non-delimiter segments.
1261
1262
  # We do not know whether the first segment is a delimiter or not, so we check the first character of the string
@@ -1268,15 +1269,17 @@ def _build_capitalization_sql(
1268
1269
  self.func(
1269
1270
  "LIST_TRANSFORM",
1270
1271
  self.func("REGEXP_EXTRACT_ALL", value_to_split, split_regex_sql),
1271
- "(seg, idx) -> CASE WHEN idx % 2 = 0 THEN UPPER(LEFT(seg, 1)) || LOWER(SUBSTRING(seg, 2)) ELSE seg END",
1272
+ "LAMBDA seg, idx : CASE WHEN idx % 2 = 0 THEN UPPER(LEFT(seg, 1)) || LOWER(SUBSTRING(seg, 2)) ELSE seg END",
1272
1273
  ),
1274
+ dialect=self.dialect,
1273
1275
  )
1274
1276
  .else_(
1275
1277
  self.func(
1276
1278
  "LIST_TRANSFORM",
1277
1279
  self.func("REGEXP_EXTRACT_ALL", value_to_split, split_regex_sql),
1278
- "(seg, idx) -> CASE WHEN idx % 2 = 1 THEN UPPER(LEFT(seg, 1)) || LOWER(SUBSTRING(seg, 2)) ELSE seg END",
1280
+ "LAMBDA seg, idx : CASE WHEN idx % 2 = 1 THEN UPPER(LEFT(seg, 1)) || LOWER(SUBSTRING(seg, 2)) ELSE seg END",
1279
1281
  ),
1282
+ dialect=self.dialect,
1280
1283
  ),
1281
1284
  "''",
1282
1285
  )
@@ -1770,6 +1773,8 @@ class DuckDBGenerator(generator.Generator):
1770
1773
  exp.MakeInterval: lambda self, e: no_make_interval_sql(self, e, sep=" "),
1771
1774
  exp.Initcap: _initcap_sql,
1772
1775
  exp.MD5Digest: lambda self, e: self.func("UNHEX", self.func("MD5", e.this)),
1776
+ exp.Max: rename_func("MAX"),
1777
+ exp.Min: rename_func("MIN"),
1773
1778
  exp.SHA: lambda self, e: _sha_sql(self, e, "SHA1"),
1774
1779
  exp.SHA1Digest: lambda self, e: _sha_sql(self, e, "SHA1", is_binary=True),
1775
1780
  exp.SHA2: lambda self, e: _sha_sql(self, e, "SHA256"),
@@ -2423,32 +2428,37 @@ class DuckDBGenerator(generator.Generator):
2423
2428
  Transform Snowflake's TIME_SLICE to DuckDB's time_bucket.
2424
2429
 
2425
2430
  Snowflake: TIME_SLICE(date_expr, slice_length, 'UNIT' [, 'START'|'END'])
2426
- DuckDB: time_bucket(INTERVAL 'slice_length' UNIT, date_expr)
2431
+ DuckDB: time_bucket(INTERVAL 'slice_length' UNIT, date_expr, origin)
2427
2432
 
2428
- For 'END' kind, add the interval to get the end of the slice.
2429
- For DATE type with 'END', cast result back to DATE to preserve type.
2433
+ Snowflake aligns slices to the 1970-01-01 epoch, so an explicit origin is
2434
+ required because DuckDB's default origin differs. For 'END' kind, add the
2435
+ interval to get the next slice's start; for DATE input, cast back to DATE.
2430
2436
  """
2431
2437
  date_expr = expression.this
2432
2438
  slice_length = expression.expression
2433
- unit = expression.unit
2439
+ # Normalize unit aliases (e.g. W/WK/WOY -> WEEK) so the interval and origin agree
2440
+ unit = map_date_part(expression.unit, self.dialect)
2434
2441
  kind = expression.text("kind").upper()
2435
2442
 
2436
- # Create INTERVAL expression: INTERVAL 'N' UNIT
2437
2443
  interval_expr = exp.Interval(this=slice_length, unit=unit)
2438
2444
 
2439
- # Create base time_bucket expression
2440
- time_bucket_expr = exp.func("time_bucket", interval_expr, date_expr)
2445
+ origin = expression.args.get("origin")
2446
+ if origin is None:
2447
+ # Snowflake aligns to 1970-01-01; WEEK to the Monday of the epoch week (WEEK_START=0)
2448
+ origin = exp.Literal.string(
2449
+ "1969-12-29" if unit and unit.name.upper() == "WEEK" else "1970-01-01"
2450
+ )
2451
+ # A DATE origin keeps a DATE input a DATE; DuckDB widens it for TIMESTAMP inputs
2452
+ time_bucket_expr = exp.func(
2453
+ "time_bucket", interval_expr, date_expr, exp.cast(origin, exp.DType.DATE)
2454
+ )
2441
2455
 
2442
- # Check if we need the end of the slice (default is start)
2443
- if not kind == "END":
2444
- # For 'START', return time_bucket directly
2456
+ if kind != "END":
2445
2457
  return self.sql(time_bucket_expr)
2446
2458
 
2447
- # For 'END', add the interval to get end of slice
2448
2459
  add_expr = exp.Add(this=time_bucket_expr, expression=interval_expr.copy())
2449
2460
 
2450
- # If input is DATE type, cast result back to DATE to preserve type
2451
- # DuckDB converts DATE to TIMESTAMP when adding intervals
2461
+ # DuckDB widens DATE to TIMESTAMP when adding intervals, so cast back
2452
2462
  if date_expr.is_type(exp.DType.DATE):
2453
2463
  return self.sql(exp.cast(add_expr, exp.DType.DATE))
2454
2464
 
@@ -4330,6 +4340,7 @@ class DuckDBGenerator(generator.Generator):
4330
4340
  position = expression.args.get("position")
4331
4341
  occurrence = expression.args.get("occurrence")
4332
4342
  null_if_pos_overflow = expression.args.get("null_if_pos_overflow")
4343
+ null_if_no_match = expression.args.get("null_if_no_match")
4333
4344
 
4334
4345
  # Handle Snowflake's 'e' flag: it enables capture group extraction
4335
4346
  # In DuckDB, this is controlled by the group parameter directly
@@ -4358,7 +4369,7 @@ class DuckDBGenerator(generator.Generator):
4358
4369
  is_extract_all = isinstance(expression, exp.RegexpExtractAll)
4359
4370
  non_single_occurrence = occurrence and (not occurrence.is_int or occurrence.to_py() > 1)
4360
4371
 
4361
- if is_extract_all or non_single_occurrence:
4372
+ if is_extract_all or non_single_occurrence or null_if_no_match:
4362
4373
  name = "REGEXP_EXTRACT_ALL"
4363
4374
  else:
4364
4375
  name = "REGEXP_EXTRACT"
@@ -4370,9 +4381,27 @@ class DuckDBGenerator(generator.Generator):
4370
4381
  # Array slicing for REGEXP_EXTRACT_ALL with occurrence
4371
4382
  if is_extract_all and non_single_occurrence:
4372
4383
  result = exp.Bracket(this=result, expressions=[exp.Slice(this=occurrence)])
4373
- # ARRAY_EXTRACT for REGEXP_EXTRACT with occurrence > 1
4374
- elif non_single_occurrence:
4375
- result = exp.Anonymous(this="ARRAY_EXTRACT", expressions=[result, occurrence])
4384
+ elif not is_extract_all and (non_single_occurrence or null_if_no_match):
4385
+ # Non-participating capture group yields [NULL] in DuckDB; Snowflake returns '' on a match
4386
+ if (
4387
+ expression.args.get("empty_if_group_missing")
4388
+ and group
4389
+ and not (group.is_int and group.to_py() == 0)
4390
+ ):
4391
+ result = exp.Transform(
4392
+ this=result,
4393
+ expression=exp.Lambda(
4394
+ this=exp.Coalesce(
4395
+ this=exp.column("x"), expressions=[exp.Literal.string("")]
4396
+ ),
4397
+ expressions=[exp.to_identifier("x")],
4398
+ ),
4399
+ )
4400
+ return self.func(
4401
+ "ARRAY_EXTRACT",
4402
+ result,
4403
+ occurrence if non_single_occurrence else exp.Literal.number(1),
4404
+ )
4376
4405
 
4377
4406
  return self.sql(result)
4378
4407
 
@@ -7,6 +7,7 @@ from sqlglot.dialects.dialect import (
7
7
  DATE_ADD_OR_SUB,
8
8
  Dialect,
9
9
  groupconcat_sql,
10
+ mod_func_sql,
10
11
  no_last_day_sql,
11
12
  rename_func,
12
13
  strposition_sql,
@@ -356,7 +357,7 @@ class ExasolGenerator(generator.Generator):
356
357
  rename_func("EDIT_DISTANCE")
357
358
  ),
358
359
  # https://docs.exasol.com/db/latest/sql_references/functions/alphabeticallistfunctions/mod.htm
359
- exp.Mod: rename_func("MOD"),
360
+ exp.Mod: mod_func_sql,
360
361
  # https://docs.exasol.com/db/latest/sql_references/functions/alphabeticallistfunctions/from_posix_time.htm
361
362
  exp.UnixToTime: lambda self, e: self.func("FROM_POSIX_TIME", e.this),
362
363
  # https://docs.exasol.com/db/latest/sql_references/functions/alphabeticallistfunctions/rank.htm
@@ -3,6 +3,7 @@ from __future__ import annotations
3
3
  from sqlglot import exp, generator, transforms
4
4
  from sqlglot.dialects.dialect import (
5
5
  groupconcat_sql,
6
+ mod_func_sql,
6
7
  no_ilike_sql,
7
8
  nth_value_from_sql,
8
9
  rename_func,
@@ -77,7 +78,7 @@ class OracleGenerator(generator.Generator):
77
78
  exp.ILike: no_ilike_sql,
78
79
  exp.LogicalOr: rename_func("MAX"),
79
80
  exp.LogicalAnd: rename_func("MIN"),
80
- exp.Mod: rename_func("MOD"),
81
+ exp.Mod: mod_func_sql,
81
82
  exp.NthValue: nth_value_from_sql,
82
83
  exp.Rand: rename_func("DBMS_RANDOM.VALUE"),
83
84
  exp.Select: transforms.preprocess(
@@ -318,6 +318,12 @@ class PostgresGenerator(generator.Generator):
318
318
 
319
319
  return sql
320
320
 
321
+ def star_sql(self, expression: exp.Star) -> str:
322
+ if self.STAR_EXCEPT == "EXCEPT" and expression.args.get("except_"):
323
+ self.unsupported("PostgreSQL does not support EXCEPT in the SELECT projection")
324
+
325
+ return super().star_sql(expression)
326
+
321
327
  TYPE_MAPPING = {
322
328
  **generator.Generator.TYPE_MAPPING,
323
329
  exp.DType.TINYINT: "SMALLINT",
@@ -397,7 +403,7 @@ class PostgresGenerator(generator.Generator):
397
403
  "REGEXP_REPLACE",
398
404
  e.this,
399
405
  e.expression,
400
- e.args.get("replacement"),
406
+ e.args.get("replacement") or exp.Literal.string(""),
401
407
  e.args.get("position"),
402
408
  e.args.get("occurrence"),
403
409
  regexp_replace_global_modifier(e),
@@ -44,6 +44,13 @@ class RedshiftGenerator(PostgresGenerator):
44
44
  # Redshift doesn't have `WITH` as part of their with_properties so we remove it
45
45
  WITH_PROPERTIES_PREFIX = " "
46
46
 
47
+ PROPERTIES_LOCATION = {
48
+ **PostgresGenerator.PROPERTIES_LOCATION,
49
+ exp.DistKeyProperty: exp.Properties.Location.POST_SCHEMA,
50
+ exp.DistStyleProperty: exp.Properties.Location.POST_SCHEMA,
51
+ exp.SortKeyProperty: exp.Properties.Location.POST_SCHEMA,
52
+ }
53
+
47
54
  TYPE_MAPPING = {
48
55
  **PostgresGenerator.TYPE_MAPPING,
49
56
  exp.DType.BINARY: "VARBYTE",