Skip to content

Commit a6d84fb

Browse files
authored
feat(postgres): Parse TO_DATE as exp.StrToDate (#3799)
1 parent 44d6506 commit a6d84fb

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

sqlglot/dialects/postgres.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,7 @@ class Parser(parser.Parser):
365365
"NOW": exp.CurrentTimestamp.from_arg_list,
366366
"REGEXP_REPLACE": _build_regexp_replace,
367367
"TO_CHAR": build_formatted_time(exp.TimeToStr, "postgres"),
368+
"TO_DATE": build_formatted_time(exp.StrToDate, "postgres"),
368369
"TO_TIMESTAMP": _build_to_timestamp,
369370
"UNNEST": exp.Explode.from_arg_list,
370371
"SHA256": lambda args: exp.SHA2(this=seq_get(args, 0), length=exp.Literal.number(256)),

tests/dialects/test_postgres.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -759,6 +759,14 @@ def test_postgres(self):
759759
},
760760
)
761761

762+
self.validate_all(
763+
"SELECT TO_DATE('01/01/2000', 'MM/DD/YYYY')",
764+
write={
765+
"duckdb": "SELECT CAST(STRPTIME('01/01/2000', '%m/%d/%Y') AS DATE)",
766+
"postgres": "SELECT TO_DATE('01/01/2000', 'MM/DD/YYYY')",
767+
},
768+
)
769+
762770
def test_ddl(self):
763771
# Checks that user-defined types are parsed into DataType instead of Identifier
764772
self.parse_one("CREATE TABLE t (a udt)").this.expressions[0].args["kind"].assert_is(

0 commit comments

Comments
 (0)