summaryrefslogtreecommitdiffstats
path: root/sqlglot/executor/python.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2023-06-02 23:59:40 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2023-06-02 23:59:46 +0000
commit20739a12c39121a9e7ad3c9a2469ec5a6876199d (patch)
treec000de91c59fd29b2d9beecf9f93b84e69727f37 /sqlglot/executor/python.py
parentReleasing debian version 12.2.0-1. (diff)
downloadsqlglot-20739a12c39121a9e7ad3c9a2469ec5a6876199d.tar.xz
sqlglot-20739a12c39121a9e7ad3c9a2469ec5a6876199d.zip
Merging upstream version 15.0.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
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)}",