summaryrefslogtreecommitdiffstats
path: root/sqlglot/dialects/dialect.py
diff options
context:
space:
mode:
Diffstat (limited to 'sqlglot/dialects/dialect.py')
-rw-r--r--sqlglot/dialects/dialect.py28
1 files changed, 27 insertions, 1 deletions
diff --git a/sqlglot/dialects/dialect.py b/sqlglot/dialects/dialect.py
index ff22547..d4811c5 100644
--- a/sqlglot/dialects/dialect.py
+++ b/sqlglot/dialects/dialect.py
@@ -153,6 +153,9 @@ class Dialect(metaclass=_Dialect):
# Determines whether or not CONCAT's arguments must be strings
STRICT_STRING_CONCAT = False
+ # Determines whether or not user-defined data types are supported
+ SUPPORTS_USER_DEFINED_TYPES = True
+
# Determines how function names are going to be normalized
NORMALIZE_FUNCTIONS: bool | str = "upper"
@@ -546,6 +549,19 @@ def date_trunc_to_time(args: t.List) -> exp.DateTrunc | exp.TimestampTrunc:
return exp.TimestampTrunc(this=this, unit=unit)
+def date_add_interval_sql(
+ data_type: str, kind: str
+) -> t.Callable[[Generator, exp.Expression], str]:
+ def func(self: Generator, expression: exp.Expression) -> str:
+ this = self.sql(expression, "this")
+ unit = expression.args.get("unit")
+ unit = exp.var(unit.name.upper() if unit else "DAY")
+ interval = exp.Interval(this=expression.expression.copy(), unit=unit)
+ return f"{data_type}_{kind}({this}, {self.sql(interval)})"
+
+ return func
+
+
def timestamptrunc_sql(self: Generator, expression: exp.TimestampTrunc) -> str:
return self.func(
"DATE_TRUNC", exp.Literal.string(expression.text("unit") or "day"), expression.this
@@ -736,5 +752,15 @@ def any_value_to_max_sql(self: Generator, expression: exp.AnyValue) -> str:
# Used to generate JSON_OBJECT with a comma in BigQuery and MySQL instead of colon
-def json_keyvalue_comma_sql(self, expression: exp.JSONKeyValue) -> str:
+def json_keyvalue_comma_sql(self: Generator, expression: exp.JSONKeyValue) -> str:
return f"{self.sql(expression, 'this')}, {self.sql(expression, 'expression')}"
+
+
+def is_parse_json(expression: exp.Expression) -> bool:
+ return isinstance(expression, exp.ParseJSON) or (
+ isinstance(expression, exp.Cast) and expression.is_type("json")
+ )
+
+
+def isnull_to_is_null(args: t.List) -> exp.Expression:
+ return exp.Paren(this=exp.Is(this=seq_get(args, 0), expression=exp.null()))