Skip to content

fix(postgres)!: map ISO week format patterns IYYY and IW [CLAUDE] - #8672

Merged
georgesittas merged 1 commit into
tobymao:mainfrom
vidigoat:fix/postgres-iso-week-format
Oct 19, 2026
Merged

georgesittas merged 1 commit into
tobymao:mainfrom
vidigoat:fix/postgres-iso-week-format

Conversation

@vidigoat

Copy link
Copy Markdown
Contributor

Postgres' TIME_MAPPING has no entries for the ISO 8601 patterns IYYY (week-numbering year) and IW (ISO week), so the format trie splits IYYY into I + YYY and leaves IW untouched. The output is a format string that no target understands, and the reverse direction leaks %G/%V into TO_CHAR. This adds both patterns (upper and lower case, like the existing ww/WW) mapped to %G and %V, matching what Exasol already does.

sqlglot.transpile("SELECT TO_CHAR(x, 'IYYY-IW')", read="postgres", write="duckdb")
# before: SELECT STRFTIME(x, 'I%Ythree-IW')
# after:  SELECT STRFTIME(x, '%G-%V')

sqlglot.transpile("SELECT STRFTIME(x, '%G-%V')", read="duckdb", write="postgres")
# before: SELECT TO_CHAR(x, '%G-%V')
# after:  SELECT TO_CHAR(x, 'IYYY-IW')

I checked the results on PostgreSQL 17.11 and DuckDB 1.5.6: for 2021-01-01, 2024-12-30 and 2023-01-01, TO_CHAR(d, 'IYYY-IW') and STRFTIME(d, '%G-%V') both return 2020-53, 2025-01 and 2022-52. Before the fix, DuckDB returned I2021three-IW for the first date. Docs: https://www.postgresql.org/docs/current/functions-formatting.html (Redshift, which inherits this mapping, documents the same patterns: https://docs.aws.amazon.com/redshift/latest/dg/r_FORMAT_strings.html). The new validate_all case is in tests/dialects/test_postgres.py.

Developed with Claude Code (AI) under my direction; tests and make check pass locally.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@georgesittas georgesittas changed the title fix(postgres): map ISO week format patterns IYYY and IW [CLAUDE] fix(postgres)!: map ISO week format patterns IYYY and IW [CLAUDE] Oct 19, 2026
@georgesittas
georgesittas merged commit 1e5c649 into tobymao:main Oct 19, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants