From e09a9c121d0d1dd51352f2a79be14ff5972e4a34 Mon Sep 17 00:00:00 2001 From: Vidit Patankar Date: Sun, 18 Oct 2026 13:13:18 +0530 Subject: [PATCH] fix(postgres): map ISO week format patterns IYYY and IW [CLAUDE] Co-Authored-By: Claude Opus 5.5 --- sqlglot/dialects/postgres.py | 4 ++++ tests/dialects/test_postgres.py | 11 +++++++++++ 2 files changed, 15 insertions(+) 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'