fix(postgres): add missing TO_CHAR format tokens (Mon, Month, Day, Dy, AM/PM, HH)#7477
Open
mwade0118 wants to merge 1 commit intotobymao:mainfrom
Open
fix(postgres): add missing TO_CHAR format tokens (Mon, Month, Day, Dy, AM/PM, HH)#7477mwade0118 wants to merge 1 commit intotobymao:mainfrom
mwade0118 wants to merge 1 commit intotobymao:mainfrom
Conversation
…, AM/PM, HH) Add bare (non-TM-prefixed) month names, weekday names, AM/PM meridiem indicators, and bare HH to Postgres TIME_MAPPING. These tokens are standard PostgreSQL TO_CHAR format specifiers but were not being converted during transpilation, causing issues when targeting dialects like ClickHouse. Previously, `Day` was mangled to `%uay` because the single-char `D` rule matched first. The trie correctly handles longer matches, so `Day` → `%A`, `Dy` → `%a` now take precedence over `D` → `%u`. Add INVERSE_TIME_MAPPING to prefer the canonical bare forms (Mon, Day, Dy, Month, AM, HH12) when generating Postgres SQL from the internal strftime representation. Fixes tobymao#7476
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds bare (non-TM-prefixed) PostgreSQL
TO_CHARformat tokens toPostgres.TIME_MAPPING:Mon/mon/MON→%b,Month/month/MONTH→%BDay/day/DAY→%A,Dy/dy/DY→%aAM/PM/am/pm/A.M./P.M./a.m./p.m.→%pHH/hh→%I(PostgreSQL defaults to 12-hour when no suffix)Also adds
INVERSE_TIME_MAPPINGto prefer canonical bare forms (Mon,Day,Dy,Month,HH12,AM) when generating Postgres SQL.Problem
Previously, these tokens were either left as unconverted literals or partially mangled:
Mon%bMon(literal)Month%BMonth(literal)Day%A%uayD→%umatched first,ayleft as literalDy%a%uyD→%umatched first,yleft as literalAM/PM%pThe TM-prefixed versions (
TMDay,TMDy,TMMon,TMMonth) were already mapped. This PR adds the standard bare forms which are far more commonly used in practice.The trie-based
format_time()correctly prioritizes longer matches, soDay→%Atakes precedence overD→%uwithout affecting the existing single-characterDmapping.Note: Redshift already extended Postgres with
"MON": "%b"(line 27 ofredshift.py), which is now redundant but harmless.Fixes #7476
Test plan
validate_alltests intest_postgres.pycovering all new format tokensTMDy→Dyfor postgres write target)