sqlglotc 30.33.0__tar.gz → 30.34.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.33.0/sqlglotc.egg-info → sqlglotc-30.34.0}/PKG-INFO +2 -2
  2. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglot/anonymize.py +12 -1
  3. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglot/expressions/array.py +8 -0
  4. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglot/expressions/constraints.py +2 -2
  5. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglot/expressions/core.py +29 -7
  6. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglot/expressions/datatypes.py +1 -0
  7. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglot/expressions/dml.py +2 -0
  8. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglot/expressions/query.py +1 -1
  9. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglot/expressions/string.py +5 -1
  10. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglot/expressions/temporal.py +1 -1
  11. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglot/generator.py +41 -14
  12. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglot/generators/bigquery.py +38 -4
  13. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglot/generators/clickhouse.py +26 -1
  14. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglot/generators/databricks.py +3 -3
  15. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglot/generators/duckdb.py +52 -24
  16. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglot/generators/exasol.py +1 -0
  17. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglot/generators/hive.py +1 -2
  18. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglot/generators/materialize.py +5 -0
  19. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglot/generators/postgres.py +68 -3
  20. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglot/generators/presto.py +23 -0
  21. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglot/generators/redshift.py +4 -0
  22. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglot/generators/snowflake.py +7 -2
  23. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglot/generators/spark.py +7 -0
  24. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglot/generators/spark2.py +10 -3
  25. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglot/generators/sqlite.py +155 -38
  26. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglot/generators/teradata.py +8 -0
  27. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglot/helper.py +18 -0
  28. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglot/optimizer/annotate_types.py +19 -14
  29. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglot/optimizer/qualify_columns.py +63 -4
  30. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglot/optimizer/simplify.py +91 -45
  31. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglot/parser.py +105 -48
  32. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglot/parsers/databricks.py +17 -10
  33. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglot/parsers/drill.py +0 -2
  34. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglot/parsers/duckdb.py +12 -7
  35. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglot/parsers/hive.py +3 -1
  36. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglot/parsers/materialize.py +2 -0
  37. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglot/parsers/mysql.py +1 -0
  38. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglot/parsers/postgres.py +9 -7
  39. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglot/parsers/redshift.py +10 -1
  40. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglot/parsers/snowflake.py +27 -2
  41. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglot/parsers/sqlite.py +124 -12
  42. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglot/parsers/teradata.py +211 -57
  43. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglot/tokenizer_core.py +117 -9
  44. {sqlglotc-30.33.0 → sqlglotc-30.34.0/sqlglotc.egg-info}/PKG-INFO +2 -2
  45. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglotc.egg-info/requires.txt +1 -1
  46. sqlglotc-30.34.0/sqlglotc.egg-info/scm_version.json +8 -0
  47. sqlglotc-30.33.0/sqlglotc.egg-info/scm_version.json +0 -8
  48. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/MANIFEST.in +0 -0
  49. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/pyproject.toml +0 -0
  50. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/setup.cfg +0 -0
  51. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/setup.py +0 -0
  52. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglot/errors.py +0 -0
  53. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglot/executor/table.py +0 -0
  54. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglot/expressions/aggregate.py +0 -0
  55. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglot/expressions/builders.py +0 -0
  56. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglot/expressions/ddl.py +0 -0
  57. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglot/expressions/functions.py +0 -0
  58. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglot/expressions/json.py +0 -0
  59. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglot/expressions/math.py +0 -0
  60. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglot/expressions/properties.py +0 -0
  61. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglot/generators/athena.py +0 -0
  62. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglot/generators/dax.py +0 -0
  63. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglot/generators/doris.py +0 -0
  64. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglot/generators/dremio.py +0 -0
  65. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglot/generators/drill.py +0 -0
  66. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglot/generators/druid.py +0 -0
  67. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglot/generators/dune.py +0 -0
  68. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglot/generators/fabric.py +0 -0
  69. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglot/generators/mysql.py +0 -0
  70. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglot/generators/oracle.py +0 -0
  71. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglot/generators/prql.py +0 -0
  72. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglot/generators/python.py +0 -0
  73. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglot/generators/risingwave.py +0 -0
  74. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglot/generators/singlestore.py +0 -0
  75. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglot/generators/solr.py +0 -0
  76. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglot/generators/starrocks.py +0 -0
  77. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglot/generators/tableau.py +0 -0
  78. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglot/generators/trino.py +0 -0
  79. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglot/generators/tsql.py +0 -0
  80. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglot/lineage.py +0 -0
  81. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglot/optimizer/canonicalize_internal_names.py +0 -0
  82. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglot/optimizer/isolate_table_selects.py +0 -0
  83. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglot/optimizer/normalize_identifiers.py +0 -0
  84. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglot/optimizer/qualify.py +0 -0
  85. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglot/optimizer/qualify_tables.py +0 -0
  86. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglot/optimizer/resolver.py +0 -0
  87. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglot/optimizer/scope.py +0 -0
  88. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglot/parsers/athena.py +0 -0
  89. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglot/parsers/base.py +0 -0
  90. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglot/parsers/bigquery.py +0 -0
  91. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglot/parsers/clickhouse.py +0 -0
  92. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglot/parsers/dax.py +0 -0
  93. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglot/parsers/doris.py +0 -0
  94. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglot/parsers/dremio.py +0 -0
  95. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglot/parsers/druid.py +0 -0
  96. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglot/parsers/dune.py +0 -0
  97. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglot/parsers/exasol.py +0 -0
  98. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglot/parsers/fabric.py +0 -0
  99. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglot/parsers/oracle.py +0 -0
  100. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglot/parsers/presto.py +0 -0
  101. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglot/parsers/prql.py +0 -0
  102. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglot/parsers/risingwave.py +0 -0
  103. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglot/parsers/singlestore.py +0 -0
  104. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglot/parsers/solr.py +0 -0
  105. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglot/parsers/spark.py +0 -0
  106. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglot/parsers/spark2.py +0 -0
  107. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglot/parsers/starrocks.py +0 -0
  108. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglot/parsers/tableau.py +0 -0
  109. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglot/parsers/trino.py +0 -0
  110. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglot/parsers/tsql.py +0 -0
  111. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglot/serde.py +0 -0
  112. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglot/time.py +0 -0
  113. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglot/trie.py +0 -0
  114. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglotc.egg-info/SOURCES.txt +0 -0
  115. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglotc.egg-info/dependency_links.txt +0 -0
  116. {sqlglotc-30.33.0 → sqlglotc-30.34.0}/sqlglotc.egg-info/scm_file_list.json +0 -0
  117. {sqlglotc-30.33.0 → sqlglotc-30.34.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.33.0
3
+ Version: 30.34.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.33.0
10
+ Requires-Dist: sqlglot==30.34.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"
@@ -21,6 +21,7 @@ ANONYMIZED_TYPES = {
21
21
  TokenType.RAW_STRING,
22
22
  TokenType.STRING,
23
23
  TokenType.UNICODE_STRING,
24
+ TokenType.UNICODE_IDENTIFIER,
24
25
  TokenType.VAR,
25
26
  }
26
27
  QUOTED_TYPES = ANONYMIZED_TYPES - {TokenType.NUMBER, TokenType.VAR}
@@ -152,8 +153,9 @@ def render(sql: str, tokens: list[Token], dialect: DialectType = None) -> str:
152
153
 
153
154
  result = []
154
155
  prev = 0
156
+ uescape_alias = ""
155
157
 
156
- for token in tokens:
158
+ for i, token in enumerate(tokens):
157
159
  result.append(_redact(sql[prev : token.start], comments, nested))
158
160
  prev = token.end + 1
159
161
  span = sql[token.start : prev]
@@ -162,6 +164,13 @@ def render(sql: str, tokens: list[Token], dialect: DialectType = None) -> str:
162
164
  result.append(token.text)
163
165
  elif token.token_type in ANONYMIZED_TYPES:
164
166
  result.append(_fit(span, token.text, quotes, token.token_type))
167
+ elif token.token_type == TokenType.UESCAPE:
168
+ if token.text.upper() == "UESCAPE":
169
+ uescape_alias = tokens[i - 1].text
170
+ elif token.text and token.text in uescape_alias:
171
+ # Keep the alias literal when it contains the clause's escape character.
172
+ span = "'!'".ljust(len(span))
173
+ result.append(span)
165
174
  else:
166
175
  result.append(span)
167
176
 
@@ -251,6 +260,8 @@ def _fit(span: str, alias: str, quotes: list[tuple[str, str]], token_type: Token
251
260
  break
252
261
 
253
262
  width = len(span) - start - end
263
+ if token_type == TokenType.IDENTIFIER and end and len(alias) < width:
264
+ return (span[:start] + alias + span[-end:]).ljust(len(span))
254
265
  pad = "0" if token_type == TokenType.NUMBER else "a"
255
266
 
256
267
  return span[:start] + alias[:width].rjust(width, pad) + span[len(span) - end :]
@@ -397,3 +397,11 @@ class StDistance(Expression, Func):
397
397
  class StPoint(Expression, Func):
398
398
  arg_types = {"this": True, "expression": True, "z": False, "m": False}
399
399
  _sql_names = ["ST_POINT", "ST_MAKEPOINT"]
400
+
401
+
402
+ class StX(Expression, Func):
403
+ arg_types = {"this": True, "expression": False}
404
+
405
+
406
+ class StY(Expression, Func):
407
+ arg_types = {"this": True, "expression": False}
@@ -153,7 +153,7 @@ class MaskingPolicyColumnConstraint(Expression, ColumnConstraintKind):
153
153
 
154
154
 
155
155
  class NotNullColumnConstraint(Expression, ColumnConstraintKind):
156
- arg_types = {"allow_null": False}
156
+ arg_types = {"allow_null": False, "on_conflict": False}
157
157
 
158
158
 
159
159
  class OnUpdateColumnConstraint(Expression, ColumnConstraintKind):
@@ -161,7 +161,7 @@ class OnUpdateColumnConstraint(Expression, ColumnConstraintKind):
161
161
 
162
162
 
163
163
  class PrimaryKeyColumnConstraint(Expression, ColumnConstraintKind):
164
- arg_types = {"desc": False, "options": False, "include": False}
164
+ arg_types = {"desc": False, "options": False, "include": False, "on_conflict": False}
165
165
 
166
166
 
167
167
  class TitleColumnConstraint(Expression, ColumnConstraintKind):
@@ -1405,14 +1405,20 @@ class Expression(Expr):
1405
1405
  return alias_(self, alias, quoted=quoted, dialect=dialect, copy=copy, table=table, **opts)
1406
1406
 
1407
1407
  def _binop(self, klass: Type[E], other: t.Any, reverse: bool = False) -> E:
1408
- this = self.copy()
1409
- other = convert(other, copy=True)
1410
- if not isinstance(this, klass) and not isinstance(other, klass):
1411
- this = _wrap(this, Binary)
1412
- other = _wrap(other, Binary)
1408
+ left: Expr = self.copy()
1409
+ right = convert(other, copy=True)
1413
1410
  if reverse:
1414
- return klass(this=other, expression=this)
1415
- return klass(this=this, expression=other)
1411
+ left, right = right, left
1412
+
1413
+ # NOT binds more tightly than AND and OR, but more loosely than comparisons and arithmetic.
1414
+ if not issubclass(klass, Connector):
1415
+ left = _wrap(left, Not)
1416
+ right = _wrap(right, Not)
1417
+
1418
+ # A repeated operator can chain on the left, but SQL may reject chained predicates.
1419
+ if not isinstance(left, klass) or isinstance(left, Predicate):
1420
+ left = _wrap(left, Binary)
1421
+ return klass(this=left, expression=_wrap(right, Binary))
1416
1422
 
1417
1423
  def __getitem__(self, other: ExpOrStr | tuple[ExpOrStr, ...]) -> Bracket:
1418
1424
  return Bracket(
@@ -1900,6 +1906,8 @@ class Boolean(Expression, Condition):
1900
1906
 
1901
1907
 
1902
1908
  class Dot(Expression, Binary):
1909
+ arg_types = {"this": True, "expression": True, "subcolumn_depth": False}
1910
+
1903
1911
  @property
1904
1912
  def is_star(self) -> bool:
1905
1913
  return self.expression.is_star
@@ -2336,6 +2344,20 @@ class FormatPhrase(Expression):
2336
2344
  return self.this.output_name
2337
2345
 
2338
2346
 
2347
+ class TeradataConversion(Expression):
2348
+ """A postfix type conversion with Teradata-specific conversion or formatting semantics."""
2349
+
2350
+ arg_types = {"this": True, "to": True, "format": False}
2351
+
2352
+ @property
2353
+ def name(self) -> str:
2354
+ return self.this.name
2355
+
2356
+ @property
2357
+ def output_name(self) -> str:
2358
+ return self.this.output_name
2359
+
2360
+
2339
2361
  class TeradataTitle(Expression):
2340
2362
  """A Teradata TITLE display heading, which does not rename the expression."""
2341
2363
 
@@ -74,6 +74,7 @@ class DType(AutoName):
74
74
  GEOGRAPHY = auto()
75
75
  GEOGRAPHYPOINT = auto()
76
76
  GEOMETRY = auto()
77
+ HASHTYPE = auto()
77
78
  POINT = auto()
78
79
  RING = auto()
79
80
  LINESTRING = auto()
@@ -305,6 +305,7 @@ class Update(Expression, DML):
305
305
  "limit": False,
306
306
  "options": False,
307
307
  "hint": False,
308
+ "alternative": False,
308
309
  }
309
310
 
310
311
  def table(
@@ -515,6 +516,7 @@ class Merge(Expression, DML):
515
516
  "whens": True,
516
517
  "with_": False,
517
518
  "returning": False,
519
+ "schema_evolution": False,
518
520
  }
519
521
 
520
522
 
@@ -1976,7 +1976,7 @@ class Where(Expression):
1976
1976
 
1977
1977
 
1978
1978
  class Optimize(Expression):
1979
- pass
1979
+ arg_types = {"this": True, "full": False, "where": False, "zorder": False}
1980
1980
 
1981
1981
 
1982
1982
  class Analyze(Expression):
@@ -45,6 +45,10 @@ class Elt(Expression, Func):
45
45
  is_var_len_args = True
46
46
 
47
47
 
48
+ class FindInSet(Expression, Func):
49
+ arg_types = {"this": True, "expression": True}
50
+
51
+
48
52
  class EndsWith(Expression, Func):
49
53
  _sql_names = ["ENDS_WITH", "ENDSWITH"]
50
54
  arg_types = {"this": True, "expression": True}
@@ -70,7 +74,7 @@ class Left(Expression, Func):
70
74
 
71
75
 
72
76
  class Length(Expression, Func):
73
- arg_types = {"this": True, "binary": False, "encoding": False}
77
+ arg_types = {"this": True, "binary": False, "encoding": False, "null_terminated": False}
74
78
  _sql_names = ["LENGTH", "LEN", "CHAR_LENGTH", "CHARACTER_LENGTH"]
75
79
 
76
80
 
@@ -239,7 +239,7 @@ class Dayname(Expression, Func):
239
239
 
240
240
 
241
241
  class Extract(Expression, Func):
242
- arg_types = {"this": True, "expression": True}
242
+ arg_types = {"this": True, "expression": True, "date_part": False}
243
243
 
244
244
 
245
245
  class GetExtract(Expression, Func):
@@ -332,6 +332,9 @@ class Generator:
332
332
  # Whether MERGE ... WHEN MATCHED/NOT MATCHED THEN UPDATE/INSERT ... WHERE is supported
333
333
  SUPPORTS_MERGE_WHERE = False
334
334
 
335
+ # First version supporting MERGE WITH SCHEMA EVOLUTION
336
+ MERGE_SCHEMA_EVOLUTION_MIN_VERSION: t.ClassVar[tuple[int, ...] | None] = None
337
+
335
338
  # Whether MERGE uses ALL BY NAME instead of a star to update or insert all columns
336
339
  MERGE_ALL_BY_NAME = False
337
340
 
@@ -500,6 +503,8 @@ class Generator:
500
503
  # Whether the SELECT .. INTO syntax is used instead of CTAS
501
504
  SUPPORTS_SELECT_INTO = False
502
505
 
506
+ SUPPORTS_OPTIMIZE = False
507
+
503
508
  # Whether UNLOGGED tables can be created
504
509
  SUPPORTS_UNLOGGED_TABLES = False
505
510
 
@@ -1353,16 +1358,20 @@ class Generator:
1353
1358
  return f"PERIOD FOR SYSTEM_TIME ({self.sql(expression, 'this')}, {self.sql(expression, 'expression')})"
1354
1359
 
1355
1360
  def notnullcolumnconstraint_sql(self, expression: exp.NotNullColumnConstraint) -> str:
1356
- return f"{'' if expression.args.get('allow_null') else 'NOT '}NULL"
1361
+ on_conflict = self.sql(expression, "on_conflict")
1362
+ on_conflict = f" {on_conflict}" if on_conflict else ""
1363
+ return f"{'' if expression.args.get('allow_null') else 'NOT '}NULL{on_conflict}"
1357
1364
 
1358
1365
  def primarykeycolumnconstraint_sql(self, expression: exp.PrimaryKeyColumnConstraint) -> str:
1366
+ on_conflict = self.sql(expression, "on_conflict")
1367
+ on_conflict = f" {on_conflict}" if on_conflict else ""
1359
1368
  desc = expression.args.get("desc")
1360
1369
  if desc is not None:
1361
- return f"PRIMARY KEY{' DESC' if desc else ' ASC'}"
1370
+ return f"PRIMARY KEY{' DESC' if desc else ' ASC'}{on_conflict}"
1362
1371
  options = self.expressions(expression, key="options", flat=True, sep=" ")
1363
1372
  options = f" {options}" if options else ""
1364
1373
  include = self.sql(expression, "include")
1365
- return f"PRIMARY KEY{include}{options}"
1374
+ return f"PRIMARY KEY{on_conflict}{include}{options}"
1366
1375
 
1367
1376
  def uniquecolumnconstraint_sql(self, expression: exp.UniqueColumnConstraint) -> str:
1368
1377
  this = self.sql(expression, "this")
@@ -2063,13 +2072,7 @@ class Generator:
2063
2072
  and node.args.get("limit")
2064
2073
  ):
2065
2074
  node = node.subquery(copy=False)
2066
- if not self.SET_OP_PARENTHESIZED_OPERANDS:
2067
- node = exp.select("*").from_(node, copy=False)
2068
- elif (
2069
- not self.SET_OP_PARENTHESIZED_OPERANDS
2070
- and isinstance(node, exp.Subquery)
2071
- and isinstance(node.unnest(), exp.SetOperation)
2072
- ):
2075
+ if not self.SET_OP_PARENTHESIZED_OPERANDS and isinstance(node, exp.Subquery):
2073
2076
  node = exp.select("*").from_(node, copy=False)
2074
2077
  sqls.append(open_parens + self.indent(self.sql(node), level=depth, pad=0))
2075
2078
  open_parens = ""
@@ -2874,6 +2877,13 @@ class Generator:
2874
2877
 
2875
2878
  def update_sql(self, expression: exp.Update) -> str:
2876
2879
  hint = self.sql(expression, "hint")
2880
+ alternative = self.sql(expression, "alternative")
2881
+ if alternative:
2882
+ if self.dialect.SUPPORTS_UPDATE_OR or self.dialect == "":
2883
+ alternative = f" OR {alternative}"
2884
+ else:
2885
+ self.unsupported(f"UPDATE OR {alternative} is not supported")
2886
+ alternative = ""
2877
2887
  this = self.sql(expression, "this")
2878
2888
  join_sql, from_sql = self._update_from_joins_sql(expression)
2879
2889
  set_sql = self.expressions(expression, flat=True)
@@ -2887,7 +2897,7 @@ class Generator:
2887
2897
  expression_sql = f"{returning}{from_sql}{where_sql}"
2888
2898
  options = self.expressions(expression, key="options")
2889
2899
  options = f" OPTION({options})" if options else ""
2890
- sql = f"UPDATE{hint} {this}{join_sql} SET {set_sql}{expression_sql}{order}{limit}{options}"
2900
+ sql = f"UPDATE{hint}{alternative} {this}{join_sql} SET {set_sql}{expression_sql}{order}{limit}{options}"
2891
2901
  return self.prepend_ctes(expression, sql)
2892
2902
 
2893
2903
  def values_sql(self, expression: exp.Values, values_as_table: bool = True) -> str:
@@ -4138,6 +4148,10 @@ class Generator:
4138
4148
  fmt = self.sql(expression, "format")
4139
4149
  return f"{this} (FORMAT {fmt})"
4140
4150
 
4151
+ def teradataconversion_sql(self, expression: exp.TeradataConversion) -> str:
4152
+ self.unsupported("Teradata postfix conversion semantics are not supported")
4153
+ return self.sql(exp.cast(expression.this, expression.args["to"]))
4154
+
4141
4155
  def teradatatitle_sql(self, expression: exp.TeradataTitle) -> str:
4142
4156
  self.unsupported("Teradata TITLE display headings are not supported")
4143
4157
  return self.sql(expression, "this")
@@ -4487,8 +4501,13 @@ class Generator:
4487
4501
  return f"{self.sql(expression, 'this')} {expression.text('expression').strip()}"
4488
4502
 
4489
4503
  def optimize_sql(self, expression: exp.Optimize) -> str:
4490
- self.unsupported("OPTIMIZE is only supported in Databricks")
4491
- return f"OPTIMIZE {self.sql(expression, 'this')}"
4504
+ if not self.SUPPORTS_OPTIMIZE:
4505
+ self.unsupported("OPTIMIZE is only supported in Databricks")
4506
+ full = " FULL" if expression.args.get("full") else ""
4507
+ where = self.sql(expression, "where")
4508
+ columns = self.expressions(expression, key="zorder", flat=True)
4509
+ zorder = self.seg(f"ZORDER BY ({columns})") if columns else ""
4510
+ return f"OPTIMIZE {self.sql(expression, 'this')}{full}{where}{zorder}"
4492
4511
 
4493
4512
  def comment_sql(self, expression: exp.Comment) -> str:
4494
4513
  this = self.sql(expression, "this")
@@ -5235,6 +5254,14 @@ class Generator:
5235
5254
  return self.expressions(expression, sep=" ", indent=False)
5236
5255
 
5237
5256
  def merge_sql(self, expression: exp.Merge) -> str:
5257
+ schema_evolution = ""
5258
+ if expression.args.get("schema_evolution"):
5259
+ min_version = self.MERGE_SCHEMA_EVOLUTION_MIN_VERSION
5260
+ if min_version and self.dialect.version >= min_version:
5261
+ schema_evolution = " WITH SCHEMA EVOLUTION"
5262
+ else:
5263
+ self.unsupported("MERGE WITH SCHEMA EVOLUTION is not supported")
5264
+
5238
5265
  table = expression.this
5239
5266
  table_alias = ""
5240
5267
 
@@ -5262,7 +5289,7 @@ class Generator:
5262
5289
 
5263
5290
  return self.prepend_ctes(
5264
5291
  expression,
5265
- f"MERGE INTO {this}{table_alias}{sep}{using}{sep}{on}{sep}{whens}",
5292
+ f"MERGE{schema_evolution} INTO {this}{table_alias}{sep}{using}{sep}{on}{sep}{whens}",
5266
5293
  )
5267
5294
 
5268
5295
  @unsupported_args("format")
@@ -223,6 +223,10 @@ def _array_agg_fold_sql(
223
223
 
224
224
  order = array_sort_order(sort) if sort else None
225
225
 
226
+ condition = None
227
+ if isinstance(agg, exp.Filter):
228
+ condition, agg = agg.expression.this, agg.this
229
+
226
230
  # An ARRAY_AGG with its own ORDER BY or LIMIT can't take another
227
231
  if (
228
232
  not isinstance(agg, exp.ArrayAgg)
@@ -237,14 +241,35 @@ def _array_agg_fold_sql(
237
241
  value = agg.this
238
242
  if isinstance(value, exp.Distinct):
239
243
  distinct, value = True, value.expressions[0]
244
+ kept_nulls: exp.Expr | None = None
245
+ if condition is not None:
246
+ if not ignore_nulls and not agg.args.get("nulls_excluded"):
247
+ # A kept NULL contributes [NULL], a kept value contributes [], and a rejected row
248
+ # contributes no array. ARRAY_CONCAT_AGG returns NULL when no rows qualify.
249
+ nulls = exp.If(
250
+ this=value.is_(exp.null()),
251
+ true=exp.Array(expressions=[value.copy()], value_constructor=True),
252
+ false=exp.array(),
253
+ )
254
+ kept_nulls = exp.ArrayConcatAgg(
255
+ this=exp.If(this=condition.copy(), true=nulls, false=exp.null())
256
+ )
257
+ if distinct:
258
+ kept_nulls = exp.func("ARRAY_SLICE", kept_nulls, 0, 0)
259
+
260
+ # With DISTINCT, BigQuery only orders by the aggregated value, so the keys take the IF too
261
+ value = exp.If(this=condition, true=value, false=exp.null())
262
+ agg.set("nulls_excluded", None)
240
263
 
241
264
  folded: exp.Expr = exp.Distinct(expressions=[value]) if distinct else value
265
+ nulls_first = False
242
266
  if order is not None:
243
- asc, nulls_first = order
267
+ asc, placement = order
268
+ nulls_first = asc if placement is None else placement
244
269
  keys = [exp.Ordered(this=value.copy(), desc=not asc or None, nulls_first=asc)]
245
270
 
246
271
  # Aggregate ORDER BY only puts NULLs first when ascending, so other placements need a key
247
- if not ignore_nulls and nulls_first is not None and nulls_first != asc:
272
+ if not ignore_nulls and condition is None and nulls_first != asc:
248
273
  if distinct:
249
274
  self.unsupported("ARRAY_AGG(DISTINCT) only puts NULLs first when ascending")
250
275
  else:
@@ -257,13 +282,19 @@ def _array_agg_fold_sql(
257
282
  )
258
283
  folded = exp.Order(this=folded, expressions=keys)
259
284
  agg.set("this", folded)
285
+ if ignore_nulls or condition is not None:
286
+ agg = exp.func("COALESCE", exp.IgnoreNulls(this=agg), exp.array())
260
287
  if ignore_nulls:
261
288
  # All-NULL input yields [], but an empty input still yields NULL.
289
+ rows = exp.CountIf(this=condition.copy()) if condition else exp.Count(this=exp.Star())
262
290
  agg = exp.If(
263
- this=exp.Count(this=exp.Star()).eq(0),
291
+ this=rows.eq(0),
264
292
  true=exp.null(),
265
- false=exp.func("COALESCE", exp.IgnoreNulls(this=agg), exp.array()),
293
+ false=agg,
266
294
  )
295
+ elif kept_nulls is not None:
296
+ arrays = (kept_nulls, agg) if nulls_first else (agg, kept_nulls)
297
+ return self.func("ARRAY_CONCAT", *arrays)
267
298
  return self.sql(agg)
268
299
 
269
300
 
@@ -426,6 +457,9 @@ class BigQueryGenerator(generator.Generator):
426
457
  exp.Cast: transforms.preprocess(
427
458
  [_widen_decimal, transforms.remove_precision_parameterized_types]
428
459
  ),
460
+ exp.TryCast: transforms.preprocess(
461
+ [_widen_decimal, transforms.remove_precision_parameterized_types]
462
+ ),
429
463
  exp.CollateProperty: lambda self, e: (
430
464
  f"DEFAULT COLLATE {self.sql(e, 'this')}"
431
465
  if e.args.get("default")
@@ -303,7 +303,6 @@ class ClickHouseGenerator(generator.Generator):
303
303
  exp.ArrayContains: rename_func("has"),
304
304
  exp.ArrayFilter: lambda self, e: self.func("arrayFilter", e.expression, e.this),
305
305
  exp.Transform: lambda self, e: self.func("arrayMap", e.expression, e.this),
306
- exp.ArrayRemove: remove_from_array_using_filter,
307
306
  exp.ArrayReverse: rename_func("arrayReverse"),
308
307
  exp.ArraySort: _array_sort_sql,
309
308
  exp.ArraySlice: rename_func("arraySlice"),
@@ -450,6 +449,32 @@ class ClickHouseGenerator(generator.Generator):
450
449
  exp.DType.MULTIPOLYGON,
451
450
  }
452
451
 
452
+ def arrayremove_sql(self, expression: exp.ArrayRemove) -> str:
453
+ return remove_from_array_using_filter(
454
+ self,
455
+ expression,
456
+ keep=lambda element, target: exp.ArrayContains(
457
+ this=exp.array(target), expression=element
458
+ ).not_(),
459
+ supports_nullable_arrays=False,
460
+ )
461
+
462
+ def dot_sql(self, expression: exp.Dot) -> str:
463
+ if depth := expression.args.get("subcolumn_depth"):
464
+ root: exp.Expr = expression
465
+ fields: list[str] = []
466
+ while isinstance(root, exp.Dot) and len(fields) < depth:
467
+ fields.append(root.expression.name)
468
+ root = root.this
469
+
470
+ # expr.a.b performs two lookups, while a column path resolves the entire subcolumn.
471
+ if len(fields) == depth and not isinstance(root, exp.Column):
472
+ return self.func(
473
+ "getSubcolumn", root, exp.Literal.string(".".join(reversed(fields)))
474
+ )
475
+
476
+ return super().dot_sql(expression)
477
+
453
478
  @unsupported_args("json_scope")
454
479
  def contains_sql(self, expression: exp.Contains) -> str:
455
480
  # ClickHouse has no CONTAINS; keep the parentheses only where the parent needs them
@@ -30,6 +30,9 @@ class DatabricksGenerator(SparkGenerator):
30
30
  QUOTE_JSON_PATH = False
31
31
  PARSE_JSON_NAME: str | None = "PARSE_JSON"
32
32
  SUPPORTS_TEMPORAL_PRECISION = True
33
+ SUPPORTS_OPTIMIZE = True
34
+ MERGE_SCHEMA_EVOLUTION_MIN_VERSION = (15, 2)
35
+ ORDERED_PERCENTILE_MIN_VERSIONS = {exp.PercentileCont: (10, 4), exp.PercentileDisc: (11, 3)}
33
36
 
34
37
  # Known limitation: with no partition keys to order by, CUME_DIST() OVER () becomes
35
38
  # CUME_DIST() OVER (ORDER BY NULL), which Databricks still rejects with
@@ -212,6 +215,3 @@ class DatabricksGenerator(SparkGenerator):
212
215
  def clusterproperty_sql(self, expression):
213
216
  this = self.sql(expression, "this") or f"({self.expressions(expression, flat=True)})"
214
217
  return f"CLUSTER BY {this}"
215
-
216
- def optimize_sql(self, expression: exp.Optimize) -> str:
217
- return f"OPTIMIZE {self.sql(expression, 'this')}"
@@ -41,10 +41,12 @@ from sqlglot.dialects.dialect import (
41
41
  WEEK_START_DAY_TO_DOW,
42
42
  )
43
43
  from sqlglot.generator import unsupported_args
44
- from sqlglot.helper import find_new_name, is_date_unit, seq_get
44
+ from sqlglot.helper import decode_unicode_escapes, find_new_name, is_date_unit, seq_get
45
45
  from sqlglot.optimizer.scope import find_all_in_scope
46
46
  from builtins import type as Type
47
47
 
48
+ _SIMILAR_TO_REGEX_CHARS = frozenset(r"\|*+?{}()[]")
49
+
48
50
  _CONNECT_BY_ARGS_TO_SKIP = frozenset({"connect", "where", "from_", "with_", "expressions"})
49
51
 
50
52
  # Regex to detect time zones in timestamps of the form [+|-]TT[:tt]
@@ -1593,6 +1595,15 @@ def _sha_sql(
1593
1595
  return self.func("UNHEX", result) if is_binary else result
1594
1596
 
1595
1597
 
1598
+ def _unqualify_pivot_columns(expression: exp.Expr) -> exp.Expr:
1599
+ # DuckDB requires unqualified pivot expressions. The source and CTEs have their own scope.
1600
+ # https://github.com/duckdb/duckdb/blob/671faf92411182f81dce42ac43de8bfb05d9909e/src/planner/binder/tableref/bind_pivot.cpp#L61-L62
1601
+ for clause in expression.iter_expressions():
1602
+ if clause.arg_key not in ("this", "with_"):
1603
+ transforms.unqualify_columns(clause)
1604
+ return expression
1605
+
1606
+
1596
1607
  class DuckDBGenerator(generator.Generator):
1597
1608
  PARAMETER_TOKEN = "$"
1598
1609
  NAMED_PLACEHOLDER_TOKEN = "$"
@@ -1787,9 +1798,7 @@ class DuckDBGenerator(generator.Generator):
1787
1798
  exp.NextDay: _day_navigation_sql,
1788
1799
  exp.PercentileCont: rename_func("QUANTILE_CONT"),
1789
1800
  exp.PercentileDisc: rename_func("QUANTILE_DISC"),
1790
- # DuckDB doesn't allow qualified columns inside of PIVOT expressions.
1791
- # See: https://github.com/duckdb/duckdb/blob/671faf92411182f81dce42ac43de8bfb05d9909e/src/planner/binder/tableref/bind_pivot.cpp#L61-L62
1792
- exp.Pivot: transforms.preprocess([transforms.unqualify_columns]),
1801
+ exp.Pivot: transforms.preprocess([_unqualify_pivot_columns]),
1793
1802
  exp.PreviousDay: _day_navigation_sql,
1794
1803
  exp.RegexpILike: lambda self, e: self.func(
1795
1804
  "REGEXP_MATCHES", e.this, e.expression, exp.Literal.string("i")
@@ -2470,19 +2479,8 @@ class DuckDBGenerator(generator.Generator):
2470
2479
  # are decoded into the characters, e.g. U&'d\0061t\0061' and U&'d!+000061ta' UESCAPE '!'
2471
2480
  # are both 'data'
2472
2481
  escape = expression.args.get("escape")
2473
- escape_char = re.escape(escape.name if isinstance(escape, exp.Expr) else "\\")
2474
- pattern = re.compile(
2475
- rf"{escape_char}(?:\+([0-9a-fA-F]{{6}})|([0-9a-fA-F]{{4}})|({escape_char}))"
2476
- )
2477
-
2478
- def decode(match: re.Match[str]) -> str:
2479
- if match.group(3):
2480
- return match.group(3)
2481
- return chr(int(match.group(1) or match.group(2), 16))
2482
-
2483
- # A character outside the BMP can be written as a UTF-16 surrogate pair
2484
- text = (
2485
- pattern.sub(decode, expression.name).encode("utf-16", "surrogatepass").decode("utf-16")
2482
+ text = decode_unicode_escapes(
2483
+ expression.name, escape.name if isinstance(escape, exp.Expr) else "\\"
2486
2484
  )
2487
2485
  return self.sql(exp.Literal.string(text))
2488
2486
 
@@ -2866,6 +2864,18 @@ class DuckDBGenerator(generator.Generator):
2866
2864
 
2867
2865
  return strposition_sql(self, expression)
2868
2866
 
2867
+ def similarto_sql(self, expression: exp.SimilarTo) -> str:
2868
+ pattern = expression.expression.unnest()
2869
+ if (
2870
+ pattern.is_string
2871
+ and not isinstance(expression.parent, exp.Escape)
2872
+ and _SIMILAR_TO_REGEX_CHARS.isdisjoint(pattern.name)
2873
+ ):
2874
+ return self.sql(expression.this.like(pattern))
2875
+
2876
+ self.unsupported("Cannot translate this SIMILAR TO pattern to DuckDB LIKE")
2877
+ return super().similarto_sql(expression)
2878
+
2869
2879
  def substring_sql(self, expression: exp.Substring) -> str:
2870
2880
  if expression.args.get("zero_start"):
2871
2881
  start = expression.args.get("start")
@@ -3397,17 +3407,29 @@ class DuckDBGenerator(generator.Generator):
3397
3407
  func.set("expression", func.this)
3398
3408
  func.set("this", order_col.this)
3399
3409
 
3400
- this = self.sql(expression, "this").rstrip(")")
3410
+ this = self.sql(expression, "this").removesuffix(")")
3401
3411
 
3402
3412
  return f"{this}{expression_sql})"
3403
3413
 
3404
3414
  def length_sql(self, expression: exp.Length) -> str:
3405
3415
  arg = expression.this
3406
3416
 
3407
- # Dialects like BQ and Snowflake also accept binary values as args, so
3417
+ def text_arg(value: exp.Expr) -> exp.Expr:
3418
+ if expression.args.get("null_terminated"):
3419
+ return exp.SplitPart(
3420
+ this=value.copy(),
3421
+ delimiter=exp.Chr(expressions=[exp.Literal.number(0)]),
3422
+ part_index=exp.Literal.number(1),
3423
+ )
3424
+ return value
3425
+
3426
+ # SQLite, BQ and Snowflake also accept binary values as args, so
3408
3427
  # DDB will attempt to infer the type or resort to case/when resolution
3409
- if not expression.args.get("binary") or arg.is_string:
3410
- return self.func("LENGTH", arg)
3428
+ if (
3429
+ not (expression.args.get("binary") or expression.args.get("null_terminated"))
3430
+ or arg.is_string
3431
+ ):
3432
+ return self.func("LENGTH", text_arg(arg))
3411
3433
 
3412
3434
  if not arg.type:
3413
3435
  from sqlglot.optimizer.annotate_types import annotate_types
@@ -3415,16 +3437,16 @@ class DuckDBGenerator(generator.Generator):
3415
3437
  arg = annotate_types(arg, dialect=self.dialect)
3416
3438
 
3417
3439
  if arg.is_type(*exp.DataType.TEXT_TYPES):
3418
- return self.func("LENGTH", arg)
3440
+ return self.func("LENGTH", text_arg(arg))
3419
3441
 
3420
3442
  # We need these casts to make duckdb's static type checker happy
3421
3443
  blob = exp.cast(arg, exp.DType.VARBINARY)
3422
3444
  varchar = exp.cast(arg, exp.DType.VARCHAR)
3423
3445
 
3424
3446
  case = (
3425
- exp.case(exp.Anonymous(this="TYPEOF", expressions=[arg]))
3447
+ exp.case(exp.Typeof(this=arg.copy()))
3426
3448
  .when(exp.Literal.string("BLOB"), exp.ByteLength(this=blob))
3427
- .else_(exp.Anonymous(this="LENGTH", expressions=[varchar]))
3449
+ .else_(exp.Length(this=text_arg(varchar)))
3428
3450
  )
3429
3451
  return self.sql(case)
3430
3452
 
@@ -4562,6 +4584,12 @@ class DuckDBGenerator(generator.Generator):
4562
4584
  self.unsupported("The AUTOINCREMENT column constraint is not supported by DuckDB")
4563
4585
  return ""
4564
4586
 
4587
+ def onconflict_sql(self, expression: exp.OnConflict) -> str:
4588
+ if expression.arg_key == "on_conflict":
4589
+ self.unsupported("DuckDB does not support ON CONFLICT on table or column constraints")
4590
+ return ""
4591
+ return super().onconflict_sql(expression)
4592
+
4565
4593
  def aliases_sql(self, expression: exp.Aliases) -> str:
4566
4594
  this = expression.this
4567
4595
  if isinstance(this, exp.Posexplode):
@@ -266,6 +266,7 @@ def _group_by_all(expression: exp.Expr) -> exp.Expr:
266
266
 
267
267
 
268
268
  class ExasolGenerator(generator.Generator):
269
+ DATA_TYPE_SPECIFIERS_ALLOWED = True
269
270
  SELECT_KINDS = ()
270
271
  TRY_SUPPORTED = False
271
272
  SUPPORTS_UESCAPE = False
@@ -18,7 +18,6 @@ from sqlglot.dialects.dialect import (
18
18
  min_or_least,
19
19
  no_ilike_sql,
20
20
  no_recursive_cte_sql,
21
- no_trycast_sql,
22
21
  regexp_extract_sql,
23
22
  regexp_replace_sql,
24
23
  rename_func,
@@ -370,7 +369,7 @@ class HiveGenerator(generator.Generator):
370
369
  exp.TsOrDsAdd: _add_date_sql,
371
370
  exp.TsOrDsDiff: _date_diff_sql,
372
371
  exp.TsOrDsToDate: _to_date_sql,
373
- exp.TryCast: no_trycast_sql,
372
+ exp.TryCast: lambda self, e: self.cast_sql(e),
374
373
  exp.Trim: trim_sql,
375
374
  exp.Unicode: rename_func("ASCII"),
376
375
  exp.UnixToStr: lambda self, e: self.func(