diff --git a/sqlglot/dialects/postgres.py b/sqlglot/dialects/postgres.py index 30a7cdeb5f..812afc9a8a 100644 --- a/sqlglot/dialects/postgres.py +++ b/sqlglot/dialects/postgres.py @@ -44,6 +44,10 @@ class Postgres(Dialect): "FMSS": "%-S", # Second "HH12": "%I", # 09 "HH24": "%H", # 09 + "iw": "%V", # ISO 8601 week of year + "IW": "%V", # ISO 8601 week of year + "iyyy": "%G", # ISO 8601 week-numbering year + "IYYY": "%G", # ISO 8601 week-numbering year "mi": "%M", # zero padded minute "MI": "%M", # zero padded minute "mm": "%m", # 01 diff --git a/tests/dialects/test_postgres.py b/tests/dialects/test_postgres.py index cb94d67574..6fdc6fdb0c 100644 --- a/tests/dialects/test_postgres.py +++ b/tests/dialects/test_postgres.py @@ -1073,6 +1073,17 @@ def test_postgres(self): "postgres": "SELECT TO_DATE('01/01/2000', 'MM/DD/YYYY')", }, ) + self.validate_all( + "SELECT TO_CHAR(x, 'IYYY-IW')", + read={ + "duckdb": "SELECT STRFTIME(x, '%G-%V')", + "postgres": "SELECT TO_CHAR(x, 'iyyy-iw')", + }, + write={ + "duckdb": "SELECT STRFTIME(x, '%G-%V')", + "postgres": "SELECT TO_CHAR(x, 'IYYY-IW')", + }, + ) self.validate_identity( 'SELECT js, js IS JSON AS "json?", js IS JSON VALUE AS "scalar?", js IS JSON SCALAR AS "scalar?", js IS JSON OBJECT AS "object?", js IS JSON ARRAY AS "array?" FROM t'