diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2023-02-27 10:46:33 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2023-02-27 10:46:33 +0000 |
commit | aa1d1f1ea72887a3efb78f4950e27bc79dfa3766 (patch) | |
tree | a9f5bf5ab14c69d011e21d40f8504c4f94a8de72 /sqlglot/dialects/bigquery.py | |
parent | Adding upstream version 11.2.0. (diff) | |
download | sqlglot-aa1d1f1ea72887a3efb78f4950e27bc79dfa3766.tar.xz sqlglot-aa1d1f1ea72887a3efb78f4950e27bc79dfa3766.zip |
Adding upstream version 11.2.3.upstream/11.2.3
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
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, |