Skip to content

Commit

Permalink
Fix: postgres date_part type closes #1506
Browse files Browse the repository at this point in the history
  • Loading branch information
tobymao committed Apr 29, 2023
1 parent d1cc191 commit 2e0eee6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion sqlglot/dialects/postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ class Parser(parser.Parser):
}

def _parse_date_part(self) -> exp.Expression:
part = self._parse_var_or_string()
part = self._parse_type()
self._match(TokenType.COMMA)
value = self._parse_bitwise()

Expand Down
6 changes: 6 additions & 0 deletions tests/dialects/test_postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@ def test_postgres(self):
self.validate_identity("x ~ 'y'")
self.validate_identity("x ~* 'y'")

self.validate_all(
"SELECT DATE_PART('isodow'::varchar(6), current_date)",
write={
"postgres": "SELECT EXTRACT(CAST('isodow' AS VARCHAR(6)) FROM CURRENT_DATE)",
},
)
self.validate_all(
"SELECT DATE_PART('minute', timestamp '2023-01-04 04:05:06.789')",
write={
Expand Down

0 comments on commit 2e0eee6

Please sign in to comment.