Skip to content

Commit 4584935

Browse files
authored
feat(snowflake): Transpile exp.StrToDate (#4348)
1 parent 1689dc7 commit 4584935

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

sqlglot/dialects/snowflake.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -839,6 +839,7 @@ class Generator(generator.Generator):
839839
exp.StrPosition: lambda self, e: self.func(
840840
"POSITION", e.args.get("substr"), e.this, e.args.get("position")
841841
),
842+
exp.StrToDate: lambda self, e: self.func("DATE", e.this, self.format_time(e)),
842843
exp.Stuff: rename_func("INSERT"),
843844
exp.TimeAdd: date_delta_sql("TIMEADD"),
844845
exp.Timestamp: no_timestamp_sql,

tests/dialects/test_bigquery.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1517,6 +1517,14 @@ def test_bigquery(self):
15171517
"duckdb": "SELECT CAST(STRPTIME('Thursday Dec 25 2008', '%A %b %-d %Y') AS DATE)",
15181518
},
15191519
)
1520+
self.validate_all(
1521+
"SELECT PARSE_DATE('%Y%m%d', '20081225')",
1522+
write={
1523+
"bigquery": "SELECT PARSE_DATE('%Y%m%d', '20081225')",
1524+
"duckdb": "SELECT CAST(STRPTIME('20081225', '%Y%m%d') AS DATE)",
1525+
"snowflake": "SELECT DATE('20081225', 'yyyymmDD')",
1526+
},
1527+
)
15201528
self.validate_all(
15211529
"SELECT ARRAY_TO_STRING(['cake', 'pie', NULL], '--') AS text",
15221530
write={

0 commit comments

Comments
 (0)