summaryrefslogtreecommitdiffstats
path: root/sqlglot/executor/python.py
diff options
context:
space:
mode:
Diffstat (limited to 'sqlglot/executor/python.py')
-rw-r--r--sqlglot/executor/python.py19
1 files changed, 14 insertions, 5 deletions
diff --git a/sqlglot/executor/python.py b/sqlglot/executor/python.py
index b71cc6a..f114e5c 100644
--- a/sqlglot/executor/python.py
+++ b/sqlglot/executor/python.py
@@ -360,11 +360,19 @@ def _ordered_py(self, expression):
def _rename(self, e):
try:
- if "expressions" in e.args:
- this = self.sql(e, "this")
- this = f"{this}, " if this else ""
- return f"{e.key.upper()}({this}{self.expressions(e)})"
- return self.func(e.key, *e.args.values())
+ values = list(e.args.values())
+
+ if len(values) == 1:
+ values = values[0]
+ if not isinstance(values, list):
+ return self.func(e.key, values)
+ return self.func(e.key, *values)
+
+ if isinstance(e, exp.Func) and e.is_var_len_args:
+ *head, tail = values
+ return self.func(e.key, *head, *tail)
+
+ return self.func(e.key, *values)
except Exception as ex:
raise Exception(f"Could not rename {repr(e)}") from ex
@@ -413,6 +421,7 @@ class Python(Dialect):
exp.Distinct: lambda self, e: f"set({self.sql(e, 'this')})",
exp.Extract: lambda self, e: f"EXTRACT('{e.name.lower()}', {self.sql(e, 'expression')})",
exp.In: lambda self, e: f"{self.sql(e, 'this')} in ({self.expressions(e, flat=True)})",
+ exp.Interval: lambda self, e: f"INTERVAL({self.sql(e.this)}, '{self.sql(e.unit)}')",
exp.Is: lambda self, e: self.binary(e, "is"),
exp.Lambda: _lambda_sql,
exp.Not: lambda self, e: f"not {self.sql(e.this)}",