sqlglotc 30.26.0__tar.gz → 30.29.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.26.0/sqlglotc.egg-info → sqlglotc-30.29.0}/PKG-INFO +2 -2
  2. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/setup.py +5 -1
  3. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglot/expressions/builders.py +8 -1
  4. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglot/expressions/core.py +4 -1
  5. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglot/expressions/datatypes.py +1 -0
  6. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglot/expressions/properties.py +5 -1
  7. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglot/expressions/query.py +1 -0
  8. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglot/expressions/temporal.py +8 -1
  9. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglot/generator.py +11 -3
  10. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglot/generators/bigquery.py +42 -0
  11. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglot/generators/duckdb.py +13 -8
  12. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglot/generators/oracle.py +6 -2
  13. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglot/generators/snowflake.py +5 -0
  14. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglot/generators/sqlite.py +29 -14
  15. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglot/parser.py +11 -1
  16. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglot/parsers/duckdb.py +12 -1
  17. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglot/parsers/oracle.py +11 -2
  18. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglot/parsers/snowflake.py +5 -0
  19. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglot/parsers/sqlite.py +33 -0
  20. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglot/tokenizer_core.py +1 -0
  21. {sqlglotc-30.26.0 → sqlglotc-30.29.0/sqlglotc.egg-info}/PKG-INFO +2 -2
  22. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglotc.egg-info/requires.txt +1 -1
  23. sqlglotc-30.29.0/sqlglotc.egg-info/scm_version.json +8 -0
  24. sqlglotc-30.26.0/sqlglotc.egg-info/scm_version.json +0 -8
  25. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/MANIFEST.in +0 -0
  26. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/pyproject.toml +0 -0
  27. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/setup.cfg +0 -0
  28. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglot/anonymize.py +0 -0
  29. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglot/errors.py +0 -0
  30. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglot/executor/table.py +0 -0
  31. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglot/expressions/aggregate.py +0 -0
  32. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglot/expressions/array.py +0 -0
  33. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglot/expressions/constraints.py +0 -0
  34. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglot/expressions/ddl.py +0 -0
  35. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglot/expressions/dml.py +0 -0
  36. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglot/expressions/functions.py +0 -0
  37. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglot/expressions/json.py +0 -0
  38. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglot/expressions/math.py +0 -0
  39. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglot/expressions/string.py +0 -0
  40. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglot/generators/athena.py +0 -0
  41. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglot/generators/clickhouse.py +0 -0
  42. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglot/generators/databricks.py +0 -0
  43. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglot/generators/dax.py +0 -0
  44. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglot/generators/doris.py +0 -0
  45. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglot/generators/dremio.py +0 -0
  46. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglot/generators/drill.py +0 -0
  47. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglot/generators/druid.py +0 -0
  48. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglot/generators/dune.py +0 -0
  49. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglot/generators/exasol.py +0 -0
  50. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglot/generators/fabric.py +0 -0
  51. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglot/generators/hive.py +0 -0
  52. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglot/generators/materialize.py +0 -0
  53. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglot/generators/mysql.py +0 -0
  54. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglot/generators/postgres.py +0 -0
  55. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglot/generators/presto.py +0 -0
  56. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglot/generators/prql.py +0 -0
  57. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglot/generators/python.py +0 -0
  58. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglot/generators/redshift.py +0 -0
  59. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglot/generators/risingwave.py +0 -0
  60. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglot/generators/singlestore.py +0 -0
  61. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglot/generators/solr.py +0 -0
  62. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglot/generators/spark.py +0 -0
  63. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglot/generators/spark2.py +0 -0
  64. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglot/generators/starrocks.py +0 -0
  65. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglot/generators/tableau.py +0 -0
  66. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglot/generators/teradata.py +0 -0
  67. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglot/generators/trino.py +0 -0
  68. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglot/generators/tsql.py +0 -0
  69. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglot/helper.py +0 -0
  70. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglot/lineage.py +0 -0
  71. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglot/optimizer/annotate_types.py +0 -0
  72. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglot/optimizer/canonicalize_internal_names.py +0 -0
  73. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglot/optimizer/isolate_table_selects.py +0 -0
  74. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglot/optimizer/normalize_identifiers.py +0 -0
  75. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglot/optimizer/qualify.py +0 -0
  76. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglot/optimizer/qualify_columns.py +0 -0
  77. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglot/optimizer/qualify_tables.py +0 -0
  78. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglot/optimizer/resolver.py +0 -0
  79. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglot/optimizer/scope.py +0 -0
  80. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglot/optimizer/simplify.py +0 -0
  81. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglot/parsers/athena.py +0 -0
  82. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglot/parsers/base.py +0 -0
  83. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglot/parsers/bigquery.py +0 -0
  84. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglot/parsers/clickhouse.py +0 -0
  85. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglot/parsers/databricks.py +0 -0
  86. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglot/parsers/dax.py +0 -0
  87. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglot/parsers/doris.py +0 -0
  88. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglot/parsers/dremio.py +0 -0
  89. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglot/parsers/drill.py +0 -0
  90. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglot/parsers/druid.py +0 -0
  91. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglot/parsers/dune.py +0 -0
  92. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglot/parsers/exasol.py +0 -0
  93. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglot/parsers/fabric.py +0 -0
  94. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglot/parsers/hive.py +0 -0
  95. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglot/parsers/materialize.py +0 -0
  96. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglot/parsers/mysql.py +0 -0
  97. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglot/parsers/postgres.py +0 -0
  98. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglot/parsers/presto.py +0 -0
  99. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglot/parsers/prql.py +0 -0
  100. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglot/parsers/redshift.py +0 -0
  101. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglot/parsers/risingwave.py +0 -0
  102. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglot/parsers/singlestore.py +0 -0
  103. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglot/parsers/solr.py +0 -0
  104. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglot/parsers/spark.py +0 -0
  105. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglot/parsers/spark2.py +0 -0
  106. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglot/parsers/starrocks.py +0 -0
  107. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglot/parsers/tableau.py +0 -0
  108. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglot/parsers/teradata.py +0 -0
  109. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglot/parsers/trino.py +0 -0
  110. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglot/parsers/tsql.py +0 -0
  111. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglot/serde.py +0 -0
  112. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglot/time.py +0 -0
  113. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglot/trie.py +0 -0
  114. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglotc.egg-info/SOURCES.txt +0 -0
  115. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglotc.egg-info/dependency_links.txt +0 -0
  116. {sqlglotc-30.26.0 → sqlglotc-30.29.0}/sqlglotc.egg-info/scm_file_list.json +0 -0
  117. {sqlglotc-30.26.0 → sqlglotc-30.29.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.26.0
3
+ Version: 30.29.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.26.0
10
+ Requires-Dist: sqlglot==30.29.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"
@@ -189,7 +189,11 @@ setup(
189
189
  packages=[],
190
190
  install_requires=_sqlglot_requirement(),
191
191
  ext_modules=mypycify(
192
- _source_paths(), opt_level=os.environ.get("MYPYC_OPT", "2"), separate=True, verbose=True
192
+ _source_paths(),
193
+ opt_level=os.environ.get("MYPYC_OPT", "2"),
194
+ debug_level="0",
195
+ separate=True,
196
+ verbose=True,
193
197
  ),
194
198
  cmdclass={"build_ext": build_ext, "sdist": sdist},
195
199
  )
@@ -824,7 +824,7 @@ def normalize_table_name(table: str | Table, dialect: DialectType = None, copy:
824
824
  def replace_tables(
825
825
  expression: E, mapping: dict[str, str], dialect: DialectType = None, copy: bool = True
826
826
  ) -> E:
827
- """Replace all tables in expression according to the mapping.
827
+ """Replace all FROM sources (tables, views, table functions...) in expression according to the mapping.
828
828
 
829
829
  Args:
830
830
  expression: expression node to be transformed and replaced.
@@ -845,6 +845,10 @@ def replace_tables(
845
845
 
846
846
  def _replace_tables(node: Expr) -> Expr:
847
847
  if isinstance(node, Table) and node.meta_get("replace") is not False:
848
+ call = node.this
849
+ if isinstance(call, Func) and not isinstance(call, Anonymous):
850
+ return node
851
+
848
852
  original = normalize_table_name(node, dialect=dialect)
849
853
  new_name = mapping.get(original)
850
854
 
@@ -854,6 +858,9 @@ def replace_tables(
854
858
  **{k: v for k, v in node.args.items() if k not in TABLE_PARTS},
855
859
  dialect=dialect,
856
860
  )
861
+ if isinstance(call, Anonymous):
862
+ call.set("this", table.this)
863
+ table.set("this", call)
857
864
  table.add_comments([original])
858
865
  return table
859
866
  return node
@@ -933,7 +933,10 @@ class Expression(Expr):
933
933
 
934
934
  @property
935
935
  def is_int(self) -> bool:
936
- return self.is_number and isinstance(self.to_py(), int)
936
+ try:
937
+ return self.is_number and isinstance(self.to_py(), int)
938
+ except ValueError:
939
+ return False
937
940
 
938
941
  @property
939
942
  def is_star(self) -> bool:
@@ -117,6 +117,7 @@ class DType(AutoName):
117
117
  NVARCHAR = auto()
118
118
  OBJECT = auto()
119
119
  RANGE = auto()
120
+ REF = auto()
120
121
  ROWVERSION = auto()
121
122
  SERIAL = auto()
122
123
  SET = auto()
@@ -222,6 +222,10 @@ class OutputModelProperty(Property):
222
222
  arg_types = {"this": True}
223
223
 
224
224
 
225
+ class InteractiveProperty(Property):
226
+ arg_types = {}
227
+
228
+
225
229
  class IsolatedLoadingProperty(Property):
226
230
  arg_types = {"no": False, "concurrent": False, "target": False}
227
231
 
@@ -520,7 +524,7 @@ class UsingProperty(Property):
520
524
 
521
525
 
522
526
  class TemporaryProperty(Property):
523
- arg_types = {"this": False}
527
+ arg_types = {"this": False, "scoped": False}
524
528
 
525
529
 
526
530
  class VirtualProperty(Property):
@@ -1168,6 +1168,7 @@ class Values(Expression, UDTF):
1168
1168
  "order": False,
1169
1169
  "limit": False,
1170
1170
  "offset": False,
1171
+ "pivots": False,
1171
1172
  }
1172
1173
 
1173
1174
 
@@ -454,7 +454,13 @@ class ParseTime(Expression, Func):
454
454
 
455
455
 
456
456
  class StrToDate(Expression, Func):
457
- arg_types = {"this": True, "format": False, "safe": False, "default_year": False}
457
+ arg_types = {
458
+ "this": True,
459
+ "format": False,
460
+ "safe": False,
461
+ "default_year": False,
462
+ "nlsparam": False,
463
+ }
458
464
 
459
465
 
460
466
  class StrToTime(Expression, Func):
@@ -465,6 +471,7 @@ class StrToTime(Expression, Func):
465
471
  "safe": False,
466
472
  "target_type": False,
467
473
  "default_year": False,
474
+ "nlsparam": False,
468
475
  }
469
476
 
470
477
 
@@ -765,6 +765,7 @@ class Generator:
765
765
  exp.IcebergProperty: exp.Properties.Location.POST_CREATE,
766
766
  exp.IncludeProperty: exp.Properties.Location.POST_SCHEMA,
767
767
  exp.InputModelProperty: exp.Properties.Location.POST_SCHEMA,
768
+ exp.InteractiveProperty: exp.Properties.Location.UNSUPPORTED,
768
769
  exp.IsolatedLoadingProperty: exp.Properties.Location.POST_NAME,
769
770
  exp.JournalProperty: exp.Properties.Location.POST_NAME,
770
771
  exp.LanguageProperty: exp.Properties.Location.POST_SCHEMA,
@@ -2862,7 +2863,8 @@ class Generator:
2862
2863
  else values
2863
2864
  )
2864
2865
  values = self.query_modifiers(expression, values)
2865
- return f"{values} AS {alias}" if alias else values
2866
+ pivots = self.expressions(expression, key="pivots", sep="", flat=True)
2867
+ return f"{values} AS {alias}{pivots}" if alias else f"{values}{pivots}"
2866
2868
 
2867
2869
  # Converts `VALUES...` expression into a series of select unions.
2868
2870
  alias_node = expression.args.get("alias")
@@ -2885,11 +2887,17 @@ class Generator:
2885
2887
  # the deep nesting of the resulting exp.Unions. If this is a problem, either increase
2886
2888
  # `sys.setrecursionlimit` to avoid RecursionErrors, or don't set `pretty`.
2887
2889
  query = reduce(lambda x, y: exp.union(x, y, distinct=False, copy=False), selects)
2888
- return self.subquery_sql(query.subquery(alias_node and alias_node.this, copy=False))
2890
+ for key in ("order", "limit", "offset"):
2891
+ if value := expression.args.get(key):
2892
+ query.set(key, value.pop())
2893
+ subquery = query.subquery(alias_node and alias_node.this, copy=False)
2894
+ subquery.set("pivots", expression.args.pop("pivots", None))
2895
+ return self.subquery_sql(subquery)
2889
2896
 
2890
2897
  alias = f" AS {self.sql(alias_node, 'this')}" if alias_node else ""
2891
2898
  unions = " UNION ALL ".join(self.sql(select) for select in selects)
2892
- return f"({unions}){alias}"
2899
+ pivots = self.expressions(expression, key="pivots", sep="", flat=True)
2900
+ return f"({self.query_modifiers(expression, unions)}){alias}{pivots}"
2893
2901
 
2894
2902
  def var_sql(self, expression: exp.Var) -> str:
2895
2903
  return self.sql(expression, "this")
@@ -30,9 +30,13 @@ from sqlglot.dialects.dialect import (
30
30
  groupconcat_sql,
31
31
  sha2_digest_sql,
32
32
  )
33
+ from sqlglot.errors import ErrorLevel
33
34
  from sqlglot.generator import unsupported_args
34
35
  from sqlglot.helper import seq_get
35
36
 
37
+ if t.TYPE_CHECKING:
38
+ from sqlglot.dialects.dialect import DialectType
39
+
36
40
  logger = logging.getLogger("sqlglot")
37
41
 
38
42
  JSON_EXTRACT_TYPE = t.Union[exp.JSONExtract, exp.JSONExtractScalar, exp.JSONExtractArray]
@@ -683,6 +687,44 @@ class BigQueryGenerator(generator.Generator):
683
687
  "within",
684
688
  }
685
689
 
690
+ def __init__(
691
+ self,
692
+ pretty: bool | int | None = None,
693
+ identify: str | bool = False,
694
+ normalize: bool = False,
695
+ pad: int = 2,
696
+ indent: int = 2,
697
+ normalize_functions: str | bool | None = None,
698
+ unsupported_level: ErrorLevel = ErrorLevel.WARN,
699
+ max_unsupported: int = 3,
700
+ leading_comma: bool = False,
701
+ max_text_width: int = 80,
702
+ comments: bool = True,
703
+ dialect: DialectType = None,
704
+ ) -> None:
705
+ super().__init__(
706
+ pretty=pretty,
707
+ identify=identify,
708
+ normalize=normalize,
709
+ pad=pad,
710
+ indent=indent,
711
+ normalize_functions=normalize_functions,
712
+ unsupported_level=unsupported_level,
713
+ max_unsupported=max_unsupported,
714
+ leading_comma=leading_comma,
715
+ max_text_width=max_text_width,
716
+ comments=comments,
717
+ dialect=dialect,
718
+ )
719
+
720
+ self._escaped_identifier_end = r"\`"
721
+
722
+ # Escape existing backslashes before introducing new escape sequences.
723
+ self._identifier_escaped_sequences = {
724
+ **self._identifier_escaped_sequences,
725
+ **self.dialect.ESCAPED_SEQUENCES,
726
+ }
727
+
686
728
  def frombase_sql(self, expression: exp.FromBase) -> str:
687
729
  # Hex is the only base BigQuery can cast from, and the sign goes before the prefix, e.g. -0xff
688
730
  if expression.expression.name != "16":
@@ -111,7 +111,7 @@ def _apply_base64_alphabet_replacements(
111
111
  reverse: bool = False,
112
112
  ) -> exp.Expr:
113
113
  """
114
- Apply base64 alphabet character replacements.
114
+ Translate base64 alphabet characters without cascading replacements.
115
115
 
116
116
  Base64 alphabet can be 1-3 chars: 1st = index 62 ('+'), 2nd = index 63 ('/'), 3rd = padding ('=').
117
117
  zip truncates to the shorter string, so 1-char alphabet only replaces '+', 2-char replaces '+/', etc.
@@ -123,14 +123,19 @@ def _apply_base64_alphabet_replacements(
123
123
  If True, replace custom with default (decode)
124
124
  """
125
125
  if isinstance(alphabet, exp.Literal) and alphabet.is_string:
126
+ source, target = "", ""
126
127
  for default_char, new_char in zip("+/=", alphabet.this):
127
128
  if new_char != default_char:
128
- find, replace = (new_char, default_char) if reverse else (default_char, new_char)
129
- result = exp.Replace(
130
- this=result,
131
- expression=exp.Literal.string(find),
132
- replacement=exp.Literal.string(replace),
133
- )
129
+ source += default_char
130
+ target += new_char
131
+ if source:
132
+ if reverse:
133
+ source, target = target, source
134
+ result = exp.Translate(
135
+ this=result,
136
+ from_=exp.Literal.string(source),
137
+ to=exp.Literal.string(target),
138
+ )
134
139
  return result
135
140
 
136
141
 
@@ -139,7 +144,7 @@ def _base64_decode_sql(self: DuckDBGenerator, expression: exp.Expr, to_string: b
139
144
  Transpile Snowflake BASE64_DECODE_STRING/BINARY to DuckDB.
140
145
 
141
146
  DuckDB uses FROM_BASE64() which returns BLOB. For string output, wrap with DECODE().
142
- Custom alphabets require REPLACE() calls to convert to standard base64.
147
+ Custom alphabets require TRANSLATE() to convert to standard base64.
143
148
  """
144
149
  input_expr = expression.this
145
150
  alphabet = expression.args.get("alphabet")
@@ -89,8 +89,12 @@ class OracleGenerator(generator.Generator):
89
89
  exp.StrPosition: lambda self, e: strposition_sql(
90
90
  self, e, func_name="INSTR", supports_position=True, supports_occurrence=True
91
91
  ),
92
- exp.StrToTime: lambda self, e: self.func("TO_TIMESTAMP", e.this, self.format_time(e)),
93
- exp.StrToDate: lambda self, e: self.func("TO_DATE", e.this, self.format_time(e)),
92
+ exp.StrToTime: lambda self, e: self.func(
93
+ "TO_TIMESTAMP", e.this, self.format_time(e), e.args.get("nlsparam")
94
+ ),
95
+ exp.StrToDate: lambda self, e: self.func(
96
+ "TO_DATE", e.this, self.format_time(e), e.args.get("nlsparam")
97
+ ),
94
98
  exp.Subquery: lambda self, e: self.subquery_sql(e, sep=" "),
95
99
  exp.Substring: rename_func("SUBSTR"),
96
100
  exp.Table: lambda self, e: self.table_sql(e, sep=" "),
@@ -499,6 +499,7 @@ class SnowflakeGenerator(generator.Generator):
499
499
  exp.GetExtract: rename_func("GET"),
500
500
  exp.GroupConcat: lambda self, e: groupconcat_sql(self, e, sep=""),
501
501
  exp.If: if_sql(name="IFF", false_value="NULL"),
502
+ exp.InteractiveProperty: lambda *_: "INTERACTIVE",
502
503
  exp.JSONArray: lambda self, e: self.func(
503
504
  "TO_VARIANT", self.func("ARRAY_CONSTRUCT", *e.expressions)
504
505
  ),
@@ -577,6 +578,9 @@ class SnowflakeGenerator(generator.Generator):
577
578
  exp.StrtokToArray: rename_func("STRTOK_TO_ARRAY"),
578
579
  exp.Stuff: rename_func("INSERT"),
579
580
  exp.StPoint: rename_func("ST_MAKEPOINT"),
581
+ exp.TemporaryProperty: lambda _, e: (
582
+ "SCOPED TEMPORARY" if e.args.get("scoped") else "TEMPORARY"
583
+ ),
580
584
  exp.TimeAdd: date_delta_sql("TIMEADD"),
581
585
  exp.TimeSlice: lambda self, e: self.func(
582
586
  "TIME_SLICE",
@@ -648,6 +652,7 @@ class SnowflakeGenerator(generator.Generator):
648
652
  PROPERTIES_LOCATION = {
649
653
  **generator.Generator.PROPERTIES_LOCATION,
650
654
  exp.CredentialsProperty: exp.Properties.Location.POST_WITH,
655
+ exp.InteractiveProperty: exp.Properties.Location.POST_CREATE,
651
656
  exp.LocationProperty: exp.Properties.Location.POST_WITH,
652
657
  exp.PartitionedByProperty: exp.Properties.Location.POST_SCHEMA,
653
658
  exp.RowAccessProperty: exp.Properties.Location.POST_SCHEMA,
@@ -81,19 +81,6 @@ def _generated_to_auto_increment(expression: exp.Expr) -> exp.Expr:
81
81
  return expression
82
82
 
83
83
 
84
- def _offset_to_limit(expression: exp.Expr) -> exp.Expr:
85
- if not isinstance(expression, exp.Select):
86
- return expression
87
-
88
- offset = expression.args.get("offset")
89
- limit = expression.args.get("limit")
90
-
91
- if offset and (not limit or (isinstance(limit, exp.Limit) and limit.is_limit_all)):
92
- expression.limit(-1, copy=False)
93
-
94
- return expression
95
-
96
-
97
84
  class SQLiteGenerator(generator.Generator):
98
85
  SELECT_KINDS: tuple[str, ...] = ()
99
86
  TRY_SUPPORTED = False
@@ -141,6 +128,12 @@ class SQLiteGenerator(generator.Generator):
141
128
  exp.DType.VARBINARY: "BLOB",
142
129
  }
143
130
 
131
+ def nullsafeeq_sql(self, expression: exp.NullSafeEQ) -> str:
132
+ return self.binary(expression, "IS")
133
+
134
+ def nullsafeneq_sql(self, expression: exp.NullSafeNEQ) -> str:
135
+ return self.binary(expression, "IS NOT")
136
+
144
137
  TOKEN_MAPPING = {
145
138
  TokenType.AUTO_INCREMENT: "AUTOINCREMENT",
146
139
  }
@@ -173,7 +166,6 @@ class SQLiteGenerator(generator.Generator):
173
166
  exp.RegexpLike: lambda self, e: self.binary(e, "REGEXP"),
174
167
  exp.Select: transforms.preprocess(
175
168
  [
176
- _offset_to_limit,
177
169
  transforms.eliminate_distinct_on,
178
170
  transforms.eliminate_qualify,
179
171
  transforms.eliminate_semi_and_anti_joins,
@@ -204,6 +196,29 @@ class SQLiteGenerator(generator.Generator):
204
196
 
205
197
  LIMIT_FETCH = "LIMIT"
206
198
 
199
+ def offset_limit_modifiers(
200
+ self, expression: exp.Expr, fetch: bool, limit: exp.Fetch | exp.Limit | None
201
+ ) -> list[str]:
202
+ if expression.args.get("offset") and (
203
+ not limit or (isinstance(limit, exp.Limit) and limit.is_limit_all)
204
+ ):
205
+ limit = exp.Limit(expression=exp.Literal.number(-1))
206
+ return super().offset_limit_modifiers(expression, fetch, limit)
207
+
208
+ def subquery_sql(self, expression: exp.Subquery, sep: str = " AS ") -> str:
209
+ if any(expression.args.get(key) for key in ("order", "limit", "offset")):
210
+ query = expression.this
211
+ keys = ("order", "limit", "offset", "with_")
212
+ # Merge grouping modifiers unless doing so would overwrite an inner clause.
213
+ if any(expression.args.get(key) and query.args.get(key) for key in keys):
214
+ query = exp.select("*").from_(query.subquery(copy=False), copy=False)
215
+ for key in keys:
216
+ if value := expression.args.get(key):
217
+ query.set(key, value.pop())
218
+ return self.sql(query)
219
+
220
+ return super().subquery_sql(expression, sep=sep)
221
+
207
222
  def autoincrementcolumnconstraint_sql(
208
223
  self, expression: exp.AutoIncrementColumnConstraint
209
224
  ) -> str:
@@ -646,6 +646,7 @@ class Parser:
646
646
  TokenType.VOID,
647
647
  TokenType.OBJECT,
648
648
  TokenType.OBJECT_IDENTIFIER,
649
+ TokenType.REF,
649
650
  TokenType.INET,
650
651
  TokenType.IPADDRESS,
651
652
  TokenType.IPPREFIX,
@@ -799,6 +800,7 @@ class Parser:
799
800
  TokenType.FULL,
800
801
  TokenType.GET,
801
802
  TokenType.IDENTIFIER,
803
+ TokenType.IN,
802
804
  TokenType.INOUT,
803
805
  TokenType.IS,
804
806
  TokenType.ISNULL,
@@ -3635,7 +3637,7 @@ class Parser:
3635
3637
  style: str | None = (
3636
3638
  self._prev.text.upper() if self._match_texts(self.DESCRIBE_STYLES) else None
3637
3639
  )
3638
- if self._match(TokenType.DOT):
3640
+ if (kind is not None or style is not None) and self._match(TokenType.DOT):
3639
3641
  style = None
3640
3642
  self._retreat(self._index - 2)
3641
3643
 
@@ -5209,6 +5211,7 @@ class Parser:
5209
5211
  return unnest
5210
5212
 
5211
5213
  if values := self._parse_derived_table_values():
5214
+ values.set("pivots", self._parse_pivots())
5212
5215
  return values
5213
5216
 
5214
5217
  if subquery := self._parse_select(table=True, consume_pipe=consume_pipe):
@@ -6869,6 +6872,13 @@ class Parser:
6869
6872
  return this
6870
6873
  elif type_token in self.ENUM_TYPE_TOKENS:
6871
6874
  expressions = self._parse_csv(self._parse_equality)
6875
+ elif type_token == TokenType.REF:
6876
+ # REF(schema.customer) names a target; REF(1) can still be a function call.
6877
+ target = self._try_parse(lambda: self._parse_table_parts(schema=True))
6878
+ if target is None:
6879
+ self._retreat(index)
6880
+ return None
6881
+ expressions = [target]
6872
6882
  elif type_token == TokenType.JSON:
6873
6883
  # ClickHouse JSON type supports arguments: JSON(col Type, SKIP col, param=value)
6874
6884
  # https://clickhouse.com/docs/sql-reference/data-types/newjson
@@ -105,6 +105,10 @@ def _convert_text_type(dtype: exp.DataType) -> exp.DataType:
105
105
  return dtype
106
106
 
107
107
 
108
+ _parse_regexp_like = binary_range_parser(exp.RegexpLike)
109
+ _parse_regexp_full_match = binary_range_parser(exp.RegexpFullMatch)
110
+
111
+
108
112
  class DuckDBParser(parser.Parser):
109
113
  IS_PREDICATE_PRECEDENCE = IsPredicatePrecedence.LOW
110
114
 
@@ -139,7 +143,7 @@ class DuckDBParser(parser.Parser):
139
143
  RANGE_PARSERS = {
140
144
  **parser.Parser.RANGE_PARSERS,
141
145
  TokenType.DAMP: binary_range_parser(exp.ArrayOverlaps),
142
- TokenType.TILDE: binary_range_parser(exp.RegexpFullMatch),
146
+ TokenType.TILDE: lambda self, this: self._parse_tilde(this),
143
147
  }
144
148
 
145
149
  EXPONENT = {
@@ -312,6 +316,13 @@ class DuckDBParser(parser.Parser):
312
316
  SHOW_TRIE = new_trie(key.split(" ") for key in SHOW_PARSERS)
313
317
  SET_TRIE = new_trie(key.split(" ") for key in SET_PARSERS)
314
318
 
319
+ def _parse_tilde(self, this: exp.Expr | None) -> exp.Expr | None:
320
+ # ~ and !~ match anywhere in the string since DuckDB 2.0, and the whole string before it
321
+ # https://duckdb.org/docs/2.0/sql/functions/pattern_matching
322
+ if self.dialect.version >= (2, 0):
323
+ return _parse_regexp_like(self, this)
324
+ return _parse_regexp_full_match(self, this)
325
+
315
326
  def _parse_trigger_execute(self) -> exp.Expr | None:
316
327
  body = self._try_parse(self._parse_statement)
317
328
  return body if not self._curr else None
@@ -13,11 +13,20 @@ if t.TYPE_CHECKING:
13
13
  from sqlglot.dialects.dialect import Dialect
14
14
 
15
15
 
16
+ def _build_str_to_time(exp_class: type[E]) -> t.Callable[[list, Dialect], E]:
17
+ def _builder(args: list, dialect: Dialect) -> E:
18
+ expression = build_formatted_time(exp_class)(args, dialect)
19
+ expression.set("nlsparam", seq_get(args, 2))
20
+ return expression
21
+
22
+ return _builder
23
+
24
+
16
25
  def _build_to_timestamp(args: list, dialect: Dialect) -> exp.StrToTime | exp.Anonymous:
17
26
  if len(args) == 1:
18
27
  return exp.Anonymous(this="TO_TIMESTAMP", expressions=args)
19
28
 
20
- return build_formatted_time(exp.StrToTime)(args, dialect)
29
+ return _build_str_to_time(exp.StrToTime)(args, dialect)
21
30
 
22
31
 
23
32
  class OracleParser(parser.Parser):
@@ -59,7 +68,7 @@ class OracleParser(parser.Parser):
59
68
  "SQUARE": lambda args: exp.Pow(this=seq_get(args, 0), expression=exp.Literal.number(2)),
60
69
  "TO_CHAR": build_timetostr_or_tochar,
61
70
  "TO_TIMESTAMP": _build_to_timestamp,
62
- "TO_DATE": build_formatted_time(exp.StrToDate),
71
+ "TO_DATE": _build_str_to_time(exp.StrToDate),
63
72
  "TRUNC": lambda args, dialect: build_trunc(
64
73
  args, dialect, date_trunc_unabbreviate=False, default_date_trunc_unit="DD"
65
74
  ),
@@ -785,12 +785,17 @@ class SnowflakeParser(parser.Parser):
785
785
  **parser.Parser.PROPERTY_PARSERS,
786
786
  "CREDENTIALS": lambda self: self._parse_credentials_property(),
787
787
  "FILE_FORMAT": lambda self: self._parse_file_format_property(),
788
+ "INTERACTIVE": lambda self: self.expression(exp.InteractiveProperty()),
788
789
  "LOCATION": lambda self: self._parse_location_property(),
789
790
  "ROW": lambda self: (
790
791
  self._parse_row_access_policy()
791
792
  if self._match_text_seq("ACCESS", "POLICY")
792
793
  else self._parse_row()
793
794
  ),
795
+ "SCOPED": lambda self: (
796
+ self._match_texts(("TEMP", "TEMPORARY"))
797
+ and self.expression(exp.TemporaryProperty(scoped=True))
798
+ ),
794
799
  "TAG": lambda self: self._parse_tag(),
795
800
  "USING": lambda self: (
796
801
  self._match_text_seq("TEMPLATE")
@@ -7,6 +7,12 @@ from sqlglot.parser import IsPredicatePrecedence, binary_range_parser
7
7
  from sqlglot.tokens import Token, TokenType
8
8
 
9
9
 
10
+ def _build_date(args: list) -> exp.Date | exp.Anonymous:
11
+ if len(args) <= 1:
12
+ return exp.Date.from_arg_list(args)
13
+ return exp.Anonymous(this="DATE", expressions=args)
14
+
15
+
10
16
  def _build_strftime(args: list) -> exp.Anonymous | exp.TimeToStr:
11
17
  if len(args) == 1:
12
18
  args.append(exp.CurrentTimestamp())
@@ -89,6 +95,7 @@ class SQLiteParser(parser.Parser):
89
95
 
90
96
  FUNCTIONS = {
91
97
  **parser.Parser.FUNCTIONS,
98
+ "DATE": _build_date,
92
99
  "DATETIME": lambda args: exp.Anonymous(this="DATETIME", expressions=args),
93
100
  "EDITDIST3": exp.Levenshtein.from_arg_list,
94
101
  "JSON_EXTRACT": _build_json_extract,
@@ -125,6 +132,32 @@ class SQLiteParser(parser.Parser):
125
132
  TokenType.MATCH: binary_range_parser(exp.Match),
126
133
  }
127
134
 
135
+ def _parse_is(self, this: exp.Expr | None) -> exp.Expr | None:
136
+ """SQLite's IS / IS NOT is a null-safe equality against any expression.
137
+
138
+ Other dialects only accept NULL, TRUE, FALSE or UNKNOWN on the right
139
+ side, so anything else is parsed as IS [NOT] DISTINCT FROM; each
140
+ transpiler then emits the syntax it supports (SQLite keeps IS / IS
141
+ NOT) (#8855).
142
+ """
143
+ this = super()._parse_is(this)
144
+
145
+ is_node = this
146
+ wrapped_in_not = False
147
+ if isinstance(this, exp.Not) and isinstance(this.this, exp.Is):
148
+ is_node = this.this
149
+ wrapped_in_not = True
150
+
151
+ if isinstance(is_node, exp.Is):
152
+ rhs = is_node.expression.unnest()
153
+ if isinstance(rhs, (exp.Null, exp.Boolean)):
154
+ is_node.set("expression", rhs)
155
+ else:
156
+ cls = exp.NullSafeNEQ if wrapped_in_not else exp.NullSafeEQ
157
+ this = cls(this=is_node.this, expression=is_node.expression)
158
+
159
+ return this
160
+
128
161
  def _parse_is_rhs(self, distinct: bool = False) -> exp.Expr | None:
129
162
  # Ordering comparisons bind above IS, but range predicates bind below it.
130
163
  this = self._parse_bitwise()
@@ -219,6 +219,7 @@ class TokenType(IntEnum):
219
219
  IMAGE = auto()
220
220
  VARIANT = auto()
221
221
  OBJECT = auto()
222
+ REF = auto()
222
223
  INET = auto()
223
224
  IPADDRESS = auto()
224
225
  IPPREFIX = auto()
@@ -1,13 +1,13 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sqlglotc
3
- Version: 30.26.0
3
+ Version: 30.29.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.26.0
10
+ Requires-Dist: sqlglot==30.29.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"
@@ -1,4 +1,4 @@
1
- sqlglot==30.26.0
1
+ sqlglot==30.29.0
2
2
 
3
3
  [dev]
4
4
  setuptools>=61.0
@@ -0,0 +1,8 @@
1
+ {
2
+ "tag": "30.29.0",
3
+ "distance": 0,
4
+ "node": "g2fe25297af5b0f44f5c9e5d03e1b296424b7acbe",
5
+ "dirty": false,
6
+ "branch": "HEAD",
7
+ "node_date": "2026-11-03"
8
+ }
@@ -1,8 +0,0 @@
1
- {
2
- "tag": "30.26.0",
3
- "distance": 0,
4
- "node": "gb0842a1ee0be2cc9345d7312724dbf2ee32e325a",
5
- "dirty": false,
6
- "branch": "HEAD",
7
- "node_date": "2026-10-29"
8
- }
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes