diff options
Diffstat (limited to 'sqlglot/dialects/bigquery.py')
-rw-r--r-- | sqlglot/dialects/bigquery.py | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/sqlglot/dialects/bigquery.py b/sqlglot/dialects/bigquery.py index a75e802..32b5147 100644 --- a/sqlglot/dialects/bigquery.py +++ b/sqlglot/dialects/bigquery.py @@ -38,7 +38,10 @@ def _date_add_sql( ) -> t.Callable[[generator.Generator, exp.Expression], str]: def func(self, expression): this = self.sql(expression, "this") - return f"{data_type}_{kind}({this}, {self.sql(exp.Interval(this=expression.expression, unit=expression.args.get('unit') or exp.Literal.string('day')))})" + unit = expression.args.get("unit") + unit = exp.var(unit.name.upper() if unit else "DAY") + interval = exp.Interval(this=expression.expression, unit=unit) + return f"{data_type}_{kind}({this}, {self.sql(interval)})" return func @@ -235,6 +238,7 @@ class BigQuery(Dialect): exp.TimestampSub: _date_add_sql("TIMESTAMP", "SUB"), exp.TimeStrToTime: timestrtotime_sql, exp.TsOrDsToDate: ts_or_ds_to_date_sql("bigquery"), + exp.TsOrDsAdd: _date_add_sql("DATE", "ADD"), exp.PartitionedByProperty: lambda self, e: f"PARTITION BY {self.sql(e, 'this')}", exp.VariancePop: rename_func("VAR_POP"), exp.Values: _derived_table_values_to_unnest, |