summaryrefslogtreecommitdiffstats
path: root/sqlglot/dialects/bigquery.py
diff options
context:
space:
mode:
Diffstat (limited to 'sqlglot/dialects/bigquery.py')
-rw-r--r--sqlglot/dialects/bigquery.py8
1 files changed, 5 insertions, 3 deletions
diff --git a/sqlglot/dialects/bigquery.py b/sqlglot/dialects/bigquery.py
index d3db319..9ceeacc 100644
--- a/sqlglot/dialects/bigquery.py
+++ b/sqlglot/dialects/bigquery.py
@@ -13,6 +13,7 @@ from sqlglot.dialects.dialect import (
date_add_interval_sql,
datestrtodate_sql,
build_formatted_time,
+ build_timestamp_from_parts,
filter_array_using_unnest,
if_sql,
inline_array_unless_query,
@@ -22,6 +23,7 @@ from sqlglot.dialects.dialect import (
build_date_delta_with_interval,
regexp_replace_sql,
rename_func,
+ sha256_sql,
timestrtotime_sql,
ts_or_ds_add_cast,
unit_to_var,
@@ -321,6 +323,7 @@ class BigQuery(Dialect):
unit=exp.Literal.string(str(seq_get(args, 1))),
this=seq_get(args, 0),
),
+ "DATETIME": build_timestamp_from_parts,
"DATETIME_ADD": build_date_delta_with_interval(exp.DatetimeAdd),
"DATETIME_SUB": build_date_delta_with_interval(exp.DatetimeSub),
"DIV": binary_from_function(exp.IntDiv),
@@ -637,9 +640,7 @@ class BigQuery(Dialect):
]
),
exp.SHA: rename_func("SHA1"),
- exp.SHA2: lambda self, e: self.func(
- "SHA256" if e.text("length") == "256" else "SHA512", e.this
- ),
+ exp.SHA2: sha256_sql,
exp.StabilityProperty: lambda self, e: (
"DETERMINISTIC" if e.name == "IMMUTABLE" else "NOT DETERMINISTIC"
),
@@ -649,6 +650,7 @@ class BigQuery(Dialect):
),
exp.TimeAdd: date_add_interval_sql("TIME", "ADD"),
exp.TimeFromParts: rename_func("TIME"),
+ exp.TimestampFromParts: rename_func("DATETIME"),
exp.TimeSub: date_add_interval_sql("TIME", "SUB"),
exp.TimestampAdd: date_add_interval_sql("TIMESTAMP", "ADD"),
exp.TimestampDiff: rename_func("TIMESTAMP_DIFF"),