pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
missing possibility to use alternative translated month names in to_char function
18+ messages / 5 participants
[nested] [flat]

* missing possibility to use alternative translated month names in to_char function
@ 2026-08-11 15:06  Pavel Stehule <pavel.stehule@gmail.com>
  0 siblings, 1 reply; 18+ messages in thread

From: Pavel Stehule @ 2026-08-11 15:06 UTC (permalink / raw)
  To: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>

Hi

My customer reported an interesting issue. He needs translated month name,
and then he use
to_char(current_date, 'tmmonth');

Unfortunately, glibc returns nouns in the genitive case instead of the
nominative case.

This is a glibc feature from the 2.28 release. Genitive case makes sense,
when the result holds a day, but without it, it is messy.

glibc has alternative month names, that can be taken by usage placeholder
'%OB'  of function strftime.
https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/V1_chap07.html -
see alt_mon.

Can we enhance prefixes (maybe tmo) to be possible to use alternative names?

Regards

Pavel

^ permalink  raw  reply  [nested|flat] 18+ messages in thread

* Re: missing possibility to use alternative translated month names in to_char function
@ 2026-08-11 15:14  Pavel Stehule <pavel.stehule@gmail.com>
  parent: Pavel Stehule <pavel.stehule@gmail.com>
  0 siblings, 1 reply; 18+ messages in thread

From: Pavel Stehule @ 2026-08-11 15:14 UTC (permalink / raw)
  To: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>

út 11. 8. 2026 v 17:06 odesílatel Pavel Stehule <pavel.stehule@gmail.com>
napsal:

> Hi
>
> My customer reported an interesting issue. He needs translated month name,
> and then he use
> to_char(current_date, 'tmmonth');
>
> Unfortunately, glibc returns nouns in the genitive case instead of the
> nominative case.
>
> This is a glibc feature from the 2.28 release. Genitive case makes sense,
> when the result holds a day, but without it, it is messy.
>
> glibc has alternative month names, that can be taken by usage placeholder
> '%OB'  of function strftime.
> https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/V1_chap07.html
> - see alt_mon.
>
> Can we enhance prefixes (maybe tmo) to be possible to use alternative
> names?
>

example:

pavel@nemesis:~/src/orafce$ date +'%B'
srpna
pavel@nemesis:~/src/orafce$ date +'%OB'
srpen
pavel@nemesis:~/src/orafce$ LANG=C date +'%OB'
August



>
> Regards
>
> Pavel
>
>
>
>
>
>

^ permalink  raw  reply  [nested|flat] 18+ messages in thread

* Re: missing possibility to use alternative translated month names in to_char function
@ 2026-08-12 07:13  Pavel Stehule <pavel.stehule@gmail.com>
  parent: Pavel Stehule <pavel.stehule@gmail.com>
  0 siblings, 1 reply; 18+ messages in thread

From: Pavel Stehule @ 2026-08-12 07:13 UTC (permalink / raw)
  To: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>

Hi

út 11. 8. 2026 v 17:14 odesílatel Pavel Stehule <pavel.stehule@gmail.com>
napsal:

>
>
> út 11. 8. 2026 v 17:06 odesílatel Pavel Stehule <pavel.stehule@gmail.com>
> napsal:
>
>> Hi
>>
>> My customer reported an interesting issue. He needs translated month
>> name, and then he use
>> to_char(current_date, 'tmmonth');
>>
>> Unfortunately, glibc returns nouns in the genitive case instead of the
>> nominative case.
>>
>> This is a glibc feature from the 2.28 release. Genitive case makes sense,
>> when the result holds a day, but without it, it is messy.
>>
>> glibc has alternative month names, that can be taken by usage placeholder
>> '%OB'  of function strftime.
>> https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/V1_chap07.html
>> - see alt_mon.
>>
>> Can we enhance prefixes (maybe tmo) to be possible to use alternative
>> names?
>>
>
> example:
>
> pavel@nemesis:~/src/orafce$ date +'%B'
> srpna
> pavel@nemesis:~/src/orafce$ date +'%OB'
> srpen
> pavel@nemesis:~/src/orafce$ LANG=C date +'%OB'
> August
>
>
attached patch that implements 'TAM' modifier for data/timestamp formatting

Regards

Pavel


>
>
>>
>> Regards
>>
>> Pavel
>>
>>
>>
>>
>>
>>

Attachments:

0001-introduce-tam-modifier-for-date-timestamp-formatting.patch (text/x-patch, 12.2K) download From 072d25e8d5728ce2ee62530af20e38b8f879228c Mon Sep 17 00:00:00 2001 From: "okbob@github.com" <pavel.stehule@gmail.com> Date: Wed, 12 Aug 2026 07:03:28 +0200 Subject: [PATCH] introduce 'tam' modifier for date/timestamp formatting MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit glibc returns localized month names in the genitive case, but it also provides alternative month names in the nominative case. The TAM prefix allows you to retrieve this alternative name. example: SELECT to_char(date '2026-08-01', 'TMMONTH'); ┌─────────┐ │ to_char │ ╞═════════╡ │ SRPNA │ └─────────┘ (1 row) SELECT to_char(date '2026-08-01', 'TAMMONTH'); ┌─────────┐ │ to_char │ ╞═════════╡ │ SRPEN │ └─────────┘ (1 row) --- doc/src/sgml/func/func-formatting.sgml | 6 + src/backend/utils/adt/formatting.c | 121 +++++++++++++++--- src/backend/utils/adt/pg_locale.c | 9 +- src/include/utils/pg_locale.h | 1 + .../regress/expected/collate.linux.utf8.out | 28 ++++ src/test/regress/sql/collate.linux.utf8.sql | 12 ++ 6 files changed, 160 insertions(+), 17 deletions(-) diff --git a/doc/src/sgml/func/func-formatting.sgml b/doc/src/sgml/func/func-formatting.sgml index e4edaf4f42c..85444015caa 100644 --- a/doc/src/sgml/func/func-formatting.sgml +++ b/doc/src/sgml/func/func-formatting.sgml @@ -477,6 +477,12 @@ <xref linkend="guc-lc-time"/>)</entry> <entry><literal>TMMonth</literal></entry> </row> + <row> + <entry><literal>TAM</literal> prefix</entry> + <entry>translation alternative mode (use localized alternative month names based on + <xref linkend="guc-lc-time"/>)</entry> + <entry><literal>TAMMonth</literal></entry> + </row> <row> <entry><literal>SP</literal> suffix</entry> <entry>spell mode (not implemented)</entry> diff --git a/src/backend/utils/adt/formatting.c b/src/backend/utils/adt/formatting.c index effad4c37dd..b62fa3138e6 100644 --- a/src/backend/utils/adt/formatting.c +++ b/src/backend/utils/adt/formatting.c @@ -553,6 +553,7 @@ do { \ #define DCH_SUFFIX_th 0x04 #define DCH_SUFFIX_SP 0x08 #define DCH_SUFFIX_TM 0x10 +#define DCH_SUFFIX_TAM 0x20 /* * Suffix tests @@ -594,16 +595,25 @@ IS_SUFFIX_TM(uint8 _s) return (_s & DCH_SUFFIX_TM); } +static inline bool +IS_SUFFIX_TAM(uint8 _s) +{ + return (_s & DCH_SUFFIX_TAM); +} + /* * Suffixes definition for DATE-TIME TO/FROM CHAR */ #define TM_SUFFIX_LEN 2 +#define TAM_SUFFIX_LEN 3 static const KeySuffix DCH_suff[] = { {"FM", 2, DCH_SUFFIX_FM, SUFFTYPE_PREFIX}, {"fm", 2, DCH_SUFFIX_FM, SUFFTYPE_PREFIX}, {"TM", TM_SUFFIX_LEN, DCH_SUFFIX_TM, SUFFTYPE_PREFIX}, + {"TAM", TAM_SUFFIX_LEN, DCH_SUFFIX_TAM, SUFFTYPE_PREFIX}, {"tm", 2, DCH_SUFFIX_TM, SUFFTYPE_PREFIX}, + {"tam", 3, DCH_SUFFIX_TAM, SUFFTYPE_PREFIX}, {"TH", 2, DCH_SUFFIX_TH, SUFFTYPE_POSTFIX}, {"th", 2, DCH_SUFFIX_th, SUFFTYPE_POSTFIX}, {"SP", 2, DCH_SUFFIX_SP, SUFFTYPE_POSTFIX}, @@ -2786,11 +2796,32 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out, Oid col INVALID_FOR_INTERVAL; if (!tm->tm_mon) break; - if (IS_SUFFIX_TM(n->suffix)) + if (IS_SUFFIX_TM(n->suffix) || IS_SUFFIX_TAM(n->suffix)) { - char *str = str_toupper_z(localized_full_months[tm->tm_mon - 1], collid); + char *str; + char **localized_months; + int suffix_len; - if (strlen(str) <= (n->key->len + TM_SUFFIX_LEN) * DCH_MAX_ITEM_SIZ) + if (IS_SUFFIX_TM(n->suffix) && IS_SUFFIX_TAM(n->suffix)) + ereport(ERROR, + (errcode(ERRCODE_INVALID_DATETIME_FORMAT), + errmsg("TM and TAM prefixes cannot be used together"))); + + if (IS_SUFFIX_TM(n->suffix)) + { + localized_months = localized_full_months; + suffix_len = TM_SUFFIX_LEN; + } + else + { + /* TAM suffix - localized alternative month name */ + localized_months = localized_alt_full_months; + suffix_len = TAM_SUFFIX_LEN; + } + + str = str_toupper_z(localized_months[tm->tm_mon - 1], collid); + + if (strlen(str) <= (n->key->len + suffix_len) * DCH_MAX_ITEM_SIZ) strcpy(s, str); else ereport(ERROR, @@ -2806,11 +2837,32 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out, Oid col INVALID_FOR_INTERVAL; if (!tm->tm_mon) break; - if (IS_SUFFIX_TM(n->suffix)) + if (IS_SUFFIX_TM(n->suffix) || IS_SUFFIX_TAM(n->suffix)) { - char *str = str_initcap_z(localized_full_months[tm->tm_mon - 1], collid); + char *str; + char **localized_months; + int suffix_len; - if (strlen(str) <= (n->key->len + TM_SUFFIX_LEN) * DCH_MAX_ITEM_SIZ) + if (IS_SUFFIX_TM(n->suffix) && IS_SUFFIX_TAM(n->suffix)) + ereport(ERROR, + (errcode(ERRCODE_INVALID_DATETIME_FORMAT), + errmsg("TM and TAM prefixes cannot be used together"))); + + if (IS_SUFFIX_TM(n->suffix)) + { + localized_months = localized_full_months; + suffix_len = TM_SUFFIX_LEN; + } + else + { + /* TAM suffix - localized alternative month name */ + localized_months = localized_alt_full_months; + suffix_len = TAM_SUFFIX_LEN; + } + + str = str_initcap_z(localized_months[tm->tm_mon - 1], collid); + + if (strlen(str) <= (n->key->len + suffix_len) * DCH_MAX_ITEM_SIZ) strcpy(s, str); else ereport(ERROR, @@ -2826,11 +2878,32 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out, Oid col INVALID_FOR_INTERVAL; if (!tm->tm_mon) break; - if (IS_SUFFIX_TM(n->suffix)) + if (IS_SUFFIX_TM(n->suffix) || IS_SUFFIX_TAM(n->suffix)) { - char *str = str_tolower_z(localized_full_months[tm->tm_mon - 1], collid); + char *str; + char **localized_months; + int suffix_len; - if (strlen(str) <= (n->key->len + TM_SUFFIX_LEN) * DCH_MAX_ITEM_SIZ) + if (IS_SUFFIX_TM(n->suffix) && IS_SUFFIX_TAM(n->suffix)) + ereport(ERROR, + (errcode(ERRCODE_INVALID_DATETIME_FORMAT), + errmsg("TM and TAM prefixes cannot be used together"))); + + if (IS_SUFFIX_TM(n->suffix)) + { + localized_months = localized_full_months; + suffix_len = TM_SUFFIX_LEN; + } + else + { + /* TAM suffix - localized alternative month name */ + localized_months = localized_alt_full_months; + suffix_len = TAM_SUFFIX_LEN; + } + + str = str_tolower_z(localized_months[tm->tm_mon - 1], collid); + + if (strlen(str) <= (n->key->len + suffix_len) * DCH_MAX_ITEM_SIZ) strcpy(s, str); else ereport(ERROR, @@ -3565,13 +3638,29 @@ DCH_from_char(FormatNode *node, const char *in, TmFromChar *out, case DCH_MONTH: case DCH_Month: case DCH_month: - if (!from_char_seq_search(&value, &s, months_full, - IS_SUFFIX_TM(n->suffix) ? localized_full_months : NULL, - collid, - n, escontext)) - return; - if (!from_char_set_int(&out->mm, value + 1, n, escontext)) - return; + { + char **months; + + if (IS_SUFFIX_TM(n->suffix) && IS_SUFFIX_TAM(n->suffix)) + ereturn(escontext,, + (errcode(ERRCODE_INVALID_DATETIME_FORMAT), + errmsg("TM and TAM prefixes cannot be used together"))); + + if (IS_SUFFIX_TM(n->suffix)) + months = localized_full_months; + else if (IS_SUFFIX_TAM(n->suffix)) + months = localized_alt_full_months; + else + months = NULL; + + if (!from_char_seq_search(&value, &s, months_full, + months, + collid, + n, escontext)) + return; + if (!from_char_set_int(&out->mm, value + 1, n, escontext)) + return; + } break; case DCH_MON: case DCH_Mon: diff --git a/src/backend/utils/adt/pg_locale.c b/src/backend/utils/adt/pg_locale.c index 9eb99487e57..34d758486b5 100644 --- a/src/backend/utils/adt/pg_locale.c +++ b/src/backend/utils/adt/pg_locale.c @@ -102,6 +102,7 @@ char *localized_abbrev_days[7 + 1]; char *localized_full_days[7 + 1]; char *localized_abbrev_months[12 + 1]; char *localized_full_months[12 + 1]; +char *localized_alt_full_months[12 + 1]; static pg_locale_t default_locale = NULL; @@ -701,7 +702,7 @@ cache_single_string(char **dst, const char *src, int encoding) void cache_locale_time(void) { - char buf[(2 * 7 + 2 * 12) * MAX_L10N_DATA]; + char buf[(2 * 7 + 3 * 12) * MAX_L10N_DATA]; char *bufptr; time_t timenow; struct tm *timeinfo; @@ -768,6 +769,9 @@ cache_locale_time(void) if (strftime_l(bufptr, MAX_L10N_DATA, "%B", timeinfo, locale) <= 0) strftimefail = true; bufptr += MAX_L10N_DATA; + if (strftime_l(bufptr, MAX_L10N_DATA, "%OB", timeinfo, locale) <= 0) + strftimefail = true; + bufptr += MAX_L10N_DATA; } #ifdef WIN32 @@ -824,9 +828,12 @@ cache_locale_time(void) bufptr += MAX_L10N_DATA; cache_single_string(&localized_full_months[i], bufptr, encoding); bufptr += MAX_L10N_DATA; + cache_single_string(&localized_alt_full_months[i], bufptr, encoding); + bufptr += MAX_L10N_DATA; } localized_abbrev_months[12] = NULL; localized_full_months[12] = NULL; + localized_alt_full_months[12] = NULL; CurrentLCTimeValid = true; } diff --git a/src/include/utils/pg_locale.h b/src/include/utils/pg_locale.h index b74821fdfa9..3f79d4f0c1c 100644 --- a/src/include/utils/pg_locale.h +++ b/src/include/utils/pg_locale.h @@ -43,6 +43,7 @@ extern PGDLLIMPORT char *localized_abbrev_days[]; extern PGDLLIMPORT char *localized_full_days[]; extern PGDLLIMPORT char *localized_abbrev_months[]; extern PGDLLIMPORT char *localized_full_months[]; +extern PGDLLIMPORT char *localized_alt_full_months[]; extern bool check_locale(int category, const char *locale, char **canonname); extern char *pg_perm_setlocale(int category, const char *locale); diff --git a/src/test/regress/expected/collate.linux.utf8.out b/src/test/regress/expected/collate.linux.utf8.out index e0a39e4c300..26a03ac4530 100644 --- a/src/test/regress/expected/collate.linux.utf8.out +++ b/src/test/regress/expected/collate.linux.utf8.out @@ -463,7 +463,22 @@ SELECT to_char(date '2010-04-01', 'DD TMMON YYYY' COLLATE "tr_TR"); 01 NİS 2010 (1 row) +-- to_char +SET lc_time TO 'cs_CZ'; +SELECT to_char(date '2010-02-01', 'DD TMMONTH'); + to_char +---------- + 01 ÚNORA +(1 row) + +SELECT to_char(date '2010-02-01', 'TAMMONTH'); + to_char +--------- + ÚNOR +(1 row) + -- to_date +SET lc_time TO 'tr_TR'; SELECT to_date('01 ŞUB 2010', 'DD TMMON YYYY'); to_date ------------ @@ -497,6 +512,19 @@ SELECT to_date('2010 01 araLık', 'YYYY DD TMMONTH'); 12-01-2010 (1 row) +SET lc_time TO 'cs_CZ'; +SELECT to_date('1 srpna 2010', 'DD TMMONTH YYYY'); + to_date +------------ + 08-01-2010 +(1 row) + +SELECT to_date('1 srpen 2010', 'DD TAMMONTH YYYY'); + to_date +------------ + 08-01-2010 +(1 row) + -- backwards parsing CREATE VIEW collview1 AS SELECT * FROM collate_test1 WHERE b COLLATE "C" >= 'bbc'; CREATE VIEW collview2 AS SELECT a, b FROM collate_test1 ORDER BY b COLLATE "C"; diff --git a/src/test/regress/sql/collate.linux.utf8.sql b/src/test/regress/sql/collate.linux.utf8.sql index 6d726ee9c99..3e7c356adb7 100644 --- a/src/test/regress/sql/collate.linux.utf8.sql +++ b/src/test/regress/sql/collate.linux.utf8.sql @@ -182,7 +182,14 @@ SELECT to_char(date '2010-02-01', 'DD TMMON YYYY' COLLATE "tr_TR"); SELECT to_char(date '2010-04-01', 'DD TMMON YYYY'); SELECT to_char(date '2010-04-01', 'DD TMMON YYYY' COLLATE "tr_TR"); +-- to_char +SET lc_time TO 'cs_CZ'; + +SELECT to_char(date '2010-02-01', 'DD TMMONTH'); +SELECT to_char(date '2010-02-01', 'TAMMONTH'); + -- to_date +SET lc_time TO 'tr_TR'; SELECT to_date('01 ŞUB 2010', 'DD TMMON YYYY'); SELECT to_date('01 Şub 2010', 'DD TMMON YYYY'); @@ -192,6 +199,11 @@ SELECT to_date('01 Aralık 2010', 'DD TMMONTH YYYY'); SELECT to_date('01 aralık 2010', 'DD TMMONTH YYYY'); SELECT to_date('2010 01 araLık', 'YYYY DD TMMONTH'); +SET lc_time TO 'cs_CZ'; + +SELECT to_date('1 srpna 2010', 'DD TMMONTH YYYY'); +SELECT to_date('1 srpen 2010', 'DD TAMMONTH YYYY'); + -- backwards parsing CREATE VIEW collview1 AS SELECT * FROM collate_test1 WHERE b COLLATE "C" >= 'bbc'; -- 2.55.0
^ permalink raw reply [nested|flat] 18+ messages in thread

* Re: missing possibility to use alternative translated month names in to_char function
@ 2026-08-12 21:51  Bernd Reiß <bd_reiss@gmx.at>
  parent: Pavel Stehule <pavel.stehule@gmail.com>
  0 siblings, 1 reply; 18+ messages in thread

From: Bernd Reiß @ 2026-08-12 21:51 UTC (permalink / raw)
  To: Pavel Stehule <pavel.stehule@gmail.com>; PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>

Hi Pavel,

I've looked into your patch and provide the review below.

Threads I found touching TMMONTH + glibc:
https://www.postgresql.org/message-id/CALSKcLS3Zi4o0Ak5pNOheqmAiKWcez%2B%2BqwKvyPccvOz2v62QZQ%40mail... 
(Russian)
https://www.postgresql.org/message-id/14717914.JAiOoc7IO7%40utklippan

I did not come across a prior thread proposing an implementation of what
this patch does. Worth noting that in the utklippan thread above, Tom Lane
suggested that a new format code or modifier would be the palatable way to
address a similar problem.

Contents & Purpose
==================
This patch gives users control over the case (genitive vs. nominative)
to use when pulling localized month names from  glibc via the function
to_char(). The author proposes to add a TAMMONTH option for formatting
dates.

Intended behaviour: TMMONTH uses the genitive form (if applicable to the
language; equivalent to %B) while TAMMONTH uses the nominative
(equivalent to %OB).

The patch contains regression test cases. It also adds a corresponding
entry in the documentation.

Initial Run
===========
The patch applies cleanly to HEAD. The regression tests all pass
successfully against the new patch, but fail against pre-patched HEAD,
so the test cases are sane and do cover the new behavior.

Manual Testing
==============
The provided examples all work fine. However, I realized that the
shortened form TAMMON falls back to English instead of honouring
lc_time:

postgres=# set lc_time to 'de_DE.UTF-8';
SET
postgres=# SELECT to_char(date '2026-03-01'::date, 'DD TMMON');
SELECT to_char(date '2026-03-01'::date, 'DD TAMMON');
  to_char
---------
  01 MÄR
(1 row)

  to_char
---------
  01 MAR
(1 row)

It looks like only the full-month cases (DCH_MONTH/Month/month) were 
wired up for
TAM; the abbreviated cases (DCH_MON/Mon/mon) still test IS_SUFFIX_TM 
only, so TAM
silently drops to the default English abbreviation. I'd expect TAMMON to 
stay
localized.

Code Review
===========
I am not sure if this condition can be ever true:

+ if (IS_SUFFIX_TM(n->suffix) && IS_SUFFIX_TAM(n->suffix))

In case this is not possible the subsequent error message will never be
thrown and the whole block is dead code.

However, if there is a reason for this check, it would be nice to
have a comment mention it.

One thing I am not entirely sure about is this line:

+ if (strftime_l(bufptr, MAX_L10N_DATA, "%OB", timeinfo, locale) <= 0)
+     strftimefail = true;

As far as I checked %OB is not supported on Windows:

https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/strftime-wcsftime-strftime-l-wcsft...

I was, however, not able to confirm this on a Windows machine right now.
I might be able to do so on the weekend.

However, the same problem exists with older glibc versions not supporting
%OB. As far as I understand strftime_l this will lead to it returning 0 and
therefore setting strftimefail to true always. Since this if statement 
is evaluated
unconditionally I expect this to also influence the behaviour of TM.

Nitpicking & Conclusion
=======================
I feel like the documentation could explicitly mention the difference
between TMMONTH and TAMMONTH (i.e., mentioning genitive and nominative
like the Locale docs you mentioned do). I also think it would be 
beneficial to
mention that this linguistic detail is specific to certain languages.

Furthermore, in general I feel like the code could have more comments.
The single comment /* TAM suffix - localized alternative month name */
I would rather put outside the if-else block and set TAM directly in 
relation
to TM there.

All in all, this topic seems to have been a pain point for many people
as the discussion threads mentioned in the beginning attest. The patch
offers a solution to make glibc behaviour more predictable for users.
I see a very real use case here.

Best
Bernd

On 12/08/2026 09:13, Pavel Stehule wrote:
> Hi
>
> út 11. 8. 2026 v 17:14 odesílatel Pavel Stehule 
> <pavel.stehule@gmail.com> napsal:
>
>
>
>     út 11. 8. 2026 v 17:06 odesílatel Pavel Stehule
>     <pavel.stehule@gmail.com> napsal:
>
>         Hi
>
>         My customer reported an interesting issue. He needs translated
>         month name, and then he use
>         to_char(current_date, 'tmmonth');
>
>         Unfortunately, glibc returns nouns in the genitive case
>         instead of the nominative case.
>
>         This is a glibc feature from the 2.28 release. Genitive case
>         makes sense, when the result holds a day, but without it, it
>         is messy.
>
>         glibc has alternative month names, that can be taken by usage
>         placeholder '%OB'  of function strftime.
>         https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/V1_chap07.html
>         - see alt_mon.
>
>         Can we enhance prefixes (maybe tmo) to be possible to use
>         alternative names?
>
>
>     example:
>
>     pavel@nemesis:~/src/orafce$ date +'%B'
>     srpna
>     pavel@nemesis:~/src/orafce$ date +'%OB'
>     srpen
>     pavel@nemesis:~/src/orafce$ LANG=C date +'%OB'
>     August
>
>
> attached patch that implements 'TAM' modifier for data/timestamp 
> formatting
>
> Regards
>
> Pavel
>
>
>         Regards
>
>         Pavel
>
>
>
>
>







^ permalink  raw  reply  [nested|flat] 18+ messages in thread

* Re: missing possibility to use alternative translated month names in to_char function
@ 2026-08-13 04:47  Pavel Stehule <pavel.stehule@gmail.com>
  parent: Bernd Reiß <bd_reiss@gmx.at>
  0 siblings, 2 replies; 18+ messages in thread

From: Pavel Stehule @ 2026-08-13 04:47 UTC (permalink / raw)
  To: Bernd Reiß <bd_reiss@gmx.at>; +Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>

Hi

st 12. 8. 2026 v 23:51 odesílatel Bernd Reiß <bd_reiss@gmx.at> napsal:

> Hi Pavel,
>
> I've looked into your patch and provide the review below.
>
> Threads I found touching TMMONTH + glibc:
>
> https://www.postgresql.org/message-id/CALSKcLS3Zi4o0Ak5pNOheqmAiKWcez%2B%2BqwKvyPccvOz2v62QZQ%40mail...
> (Russian)
> https://www.postgresql.org/message-id/14717914.JAiOoc7IO7%40utklippan
>
> I did not come across a prior thread proposing an implementation of what
> this patch does. Worth noting that in the utklippan thread above, Tom Lane
> suggested that a new format code or modifier would be the palatable way to
> address a similar problem.
>
> Contents & Purpose
> ==================
> This patch gives users control over the case (genitive vs. nominative)
> to use when pulling localized month names from  glibc via the function
> to_char(). The author proposes to add a TAMMONTH option for formatting
> dates.
>
> Intended behaviour: TMMONTH uses the genitive form (if applicable to the
> language; equivalent to %B) while TAMMONTH uses the nominative
> (equivalent to %OB).
>
> The patch contains regression test cases. It also adds a corresponding
> entry in the documentation.
>
> Initial Run
> ===========
> The patch applies cleanly to HEAD. The regression tests all pass
> successfully against the new patch, but fail against pre-patched HEAD,
> so the test cases are sane and do cover the new behavior.
>
> Manual Testing
> ==============
> The provided examples all work fine. However, I realized that the
> shortened form TAMMON falls back to English instead of honouring
> lc_time:
>
> postgres=# set lc_time to 'de_DE.UTF-8';
> SET
> postgres=# SELECT to_char(date '2026-03-01'::date, 'DD TMMON');
> SELECT to_char(date '2026-03-01'::date, 'DD TAMMON');
>   to_char
> ---------
>   01 MÄR
> (1 row)
>
>   to_char
> ---------
>   01 MAR
> (1 row)
>
> It looks like only the full-month cases (DCH_MONTH/Month/month) were
> wired up for
> TAM; the abbreviated cases (DCH_MON/Mon/mon) still test IS_SUFFIX_TM
> only, so TAM
> silently drops to the default English abbreviation. I'd expect TAMMON to
> stay
> localized.
>

TAMMON is not implemented, because glibc doesn't provide an alternative
form for abbreviated month names.
It is a question if it is better to raise an error, return a non
alternative name or just ignore this flag. I have not strong
opinion about this. Inside DCH_to_char the prefix TM is ignored when it is
not used. So I did the same.

But I can imagine using localized abbreviation. It is possible for the
Czech language - but I have not idea if it is true for other languages.


>
> Code Review
> ===========
> I am not sure if this condition can be ever true:
>
> + if (IS_SUFFIX_TM(n->suffix) && IS_SUFFIX_TAM(n->suffix))
>
> In case this is not possible the subsequent error message will never be
> thrown and the whole block is dead code.
>
> However, if there is a reason for this check, it would be nice to
> have a comment mention it.
>

Yes, I badly expected that prefixes could be mixed. I checked the code, and
this is not possible, so I removed this check



>
> One thing I am not entirely sure about is this line:
>
> + if (strftime_l(bufptr, MAX_L10N_DATA, "%OB", timeinfo, locale) <= 0)
> +     strftimefail = true;
>
> As far as I checked %OB is not supported on Windows:
>
>
> https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/strftime-wcsftime-strftime-l-wcsft...
>
> I was, however, not able to confirm this on a Windows machine right now.
> I might be able to do so on the weekend.
>
> However, the same problem exists with older glibc versions not supporting
> %OB. As far as I understand strftime_l this will lead to it returning 0 and
> therefore setting strftimefail to true always. Since this if statement
> is evaluated
> unconditionally I expect this to also influence the behaviour of TM.
>

I am afraid about this case too, and I expect maybe some fallback mode
there. But because
I have not a Window machine or some machine with older glibc I decided to
don't touch it
for this moment.

glibc older than 2.28 doesn't support %OB. On the second hand the result of
%B is probably
equal to expected result %B.


> Nitpicking & Conclusion
> =======================
> I feel like the documentation could explicitly mention the difference
> between TMMONTH and TAMMONTH (i.e., mentioning genitive and nominative
> like the Locale docs you mentioned do). I also think it would be
> beneficial to
> mention that this linguistic detail is specific to certain languages.
>

please, if you can write this part of the doc. My English is not good
enough to write well about these linguistic details.
It is a problem primarily for slavic languages - like Czech or Russian -
but maybe it can be a wide problem.


> Furthermore, in general I feel like the code could have more comments.
> The single comment /* TAM suffix - localized alternative month name */
> I would rather put outside the if-else block and set TAM directly in
> relation
> to TM there.
>
> All in all, this topic seems to have been a pain point for many people
> as the discussion threads mentioned in the beginning attest. The patch
> offers a solution to make glibc behaviour more predictable for users.
> I see a very real use case here.
>

Thank you very much for this immediate review

Regards

Pavel


> Best
> Bernd
>
> On 12/08/2026 09:13, Pavel Stehule wrote:
> > Hi
> >
> > út 11. 8. 2026 v 17:14 odesílatel Pavel Stehule
> > <pavel.stehule@gmail.com> napsal:
> >
> >
> >
> >     út 11. 8. 2026 v 17:06 odesílatel Pavel Stehule
> >     <pavel.stehule@gmail.com> napsal:
> >
> >         Hi
> >
> >         My customer reported an interesting issue. He needs translated
> >         month name, and then he use
> >         to_char(current_date, 'tmmonth');
> >
> >         Unfortunately, glibc returns nouns in the genitive case
> >         instead of the nominative case.
> >
> >         This is a glibc feature from the 2.28 release. Genitive case
> >         makes sense, when the result holds a day, but without it, it
> >         is messy.
> >
> >         glibc has alternative month names, that can be taken by usage
> >         placeholder '%OB'  of function strftime.
> >
> https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/V1_chap07.html
> >         - see alt_mon.
> >
> >         Can we enhance prefixes (maybe tmo) to be possible to use
> >         alternative names?
> >
> >
> >     example:
> >
> >     pavel@nemesis:~/src/orafce$ date +'%B'
> >     srpna
> >     pavel@nemesis:~/src/orafce$ date +'%OB'
> >     srpen
> >     pavel@nemesis:~/src/orafce$ LANG=C date +'%OB'
> >     August
> >
> >
> > attached patch that implements 'TAM' modifier for data/timestamp
> > formatting
> >
> > Regards
> >
> > Pavel
> >
> >
> >         Regards
> >
> >         Pavel
> >
> >
> >
> >
> >
>
>

Attachments:

0001-introduce-tam-modifier-for-date-timestamp-formatting.patch (text/x-patch, 11.4K) download From c1511bb9165e4b0685a0990632a8ff4ae9d8c1ec Mon Sep 17 00:00:00 2001 From: "okbob@github.com" <pavel.stehule@gmail.com> Date: Wed, 12 Aug 2026 07:03:28 +0200 Subject: [PATCH] introduce 'tam' modifier for date/timestamp formatting MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit glibc returns localized month names in the genitive case, but it also provides alternative month names in the nominative case. The TAM prefix allows you to retrieve this alternative name. example: SELECT to_char(date '2026-08-01', 'TMMONTH'); ┌─────────┐ │ to_char │ ╞═════════╡ │ SRPNA │ └─────────┘ (1 row) SELECT to_char(date '2026-08-01', 'TAMMONTH'); ┌─────────┐ │ to_char │ ╞═════════╡ │ SRPEN │ └─────────┘ (1 row) --- doc/src/sgml/func/func-formatting.sgml | 6 + src/backend/utils/adt/formatting.c | 103 +++++++++++++++--- src/backend/utils/adt/pg_locale.c | 9 +- src/include/utils/pg_locale.h | 1 + .../regress/expected/collate.linux.utf8.out | 28 +++++ src/test/regress/sql/collate.linux.utf8.sql | 12 ++ 6 files changed, 142 insertions(+), 17 deletions(-) diff --git a/doc/src/sgml/func/func-formatting.sgml b/doc/src/sgml/func/func-formatting.sgml index e4edaf4f42c..85444015caa 100644 --- a/doc/src/sgml/func/func-formatting.sgml +++ b/doc/src/sgml/func/func-formatting.sgml @@ -477,6 +477,12 @@ <xref linkend="guc-lc-time"/>)</entry> <entry><literal>TMMonth</literal></entry> </row> + <row> + <entry><literal>TAM</literal> prefix</entry> + <entry>translation alternative mode (use localized alternative month names based on + <xref linkend="guc-lc-time"/>)</entry> + <entry><literal>TAMMonth</literal></entry> + </row> <row> <entry><literal>SP</literal> suffix</entry> <entry>spell mode (not implemented)</entry> diff --git a/src/backend/utils/adt/formatting.c b/src/backend/utils/adt/formatting.c index effad4c37dd..42f7935ac7c 100644 --- a/src/backend/utils/adt/formatting.c +++ b/src/backend/utils/adt/formatting.c @@ -553,6 +553,7 @@ do { \ #define DCH_SUFFIX_th 0x04 #define DCH_SUFFIX_SP 0x08 #define DCH_SUFFIX_TM 0x10 +#define DCH_SUFFIX_TAM 0x20 /* * Suffix tests @@ -594,16 +595,25 @@ IS_SUFFIX_TM(uint8 _s) return (_s & DCH_SUFFIX_TM); } +static inline bool +IS_SUFFIX_TAM(uint8 _s) +{ + return (_s & DCH_SUFFIX_TAM); +} + /* * Suffixes definition for DATE-TIME TO/FROM CHAR */ #define TM_SUFFIX_LEN 2 +#define TAM_SUFFIX_LEN 3 static const KeySuffix DCH_suff[] = { {"FM", 2, DCH_SUFFIX_FM, SUFFTYPE_PREFIX}, {"fm", 2, DCH_SUFFIX_FM, SUFFTYPE_PREFIX}, {"TM", TM_SUFFIX_LEN, DCH_SUFFIX_TM, SUFFTYPE_PREFIX}, + {"TAM", TAM_SUFFIX_LEN, DCH_SUFFIX_TAM, SUFFTYPE_PREFIX}, {"tm", 2, DCH_SUFFIX_TM, SUFFTYPE_PREFIX}, + {"tam", 3, DCH_SUFFIX_TAM, SUFFTYPE_PREFIX}, {"TH", 2, DCH_SUFFIX_TH, SUFFTYPE_POSTFIX}, {"th", 2, DCH_SUFFIX_th, SUFFTYPE_POSTFIX}, {"SP", 2, DCH_SUFFIX_SP, SUFFTYPE_POSTFIX}, @@ -2786,11 +2796,26 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out, Oid col INVALID_FOR_INTERVAL; if (!tm->tm_mon) break; - if (IS_SUFFIX_TM(n->suffix)) + if (IS_SUFFIX_TM(n->suffix) || IS_SUFFIX_TAM(n->suffix)) { - char *str = str_toupper_z(localized_full_months[tm->tm_mon - 1], collid); + char *str; + char **localized_months; + int suffix_len; - if (strlen(str) <= (n->key->len + TM_SUFFIX_LEN) * DCH_MAX_ITEM_SIZ) + if (IS_SUFFIX_TM(n->suffix)) + { + localized_months = localized_full_months; + suffix_len = TM_SUFFIX_LEN; + } + else + { + localized_months = localized_alt_full_months; + suffix_len = TAM_SUFFIX_LEN; + } + + str = str_toupper_z(localized_months[tm->tm_mon - 1], collid); + + if (strlen(str) <= (n->key->len + suffix_len) * DCH_MAX_ITEM_SIZ) strcpy(s, str); else ereport(ERROR, @@ -2806,11 +2831,26 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out, Oid col INVALID_FOR_INTERVAL; if (!tm->tm_mon) break; - if (IS_SUFFIX_TM(n->suffix)) + if (IS_SUFFIX_TM(n->suffix) || IS_SUFFIX_TAM(n->suffix)) { - char *str = str_initcap_z(localized_full_months[tm->tm_mon - 1], collid); + char *str; + char **localized_months; + int suffix_len; - if (strlen(str) <= (n->key->len + TM_SUFFIX_LEN) * DCH_MAX_ITEM_SIZ) + if (IS_SUFFIX_TM(n->suffix)) + { + localized_months = localized_full_months; + suffix_len = TM_SUFFIX_LEN; + } + else + { + localized_months = localized_alt_full_months; + suffix_len = TAM_SUFFIX_LEN; + } + + str = str_initcap_z(localized_months[tm->tm_mon - 1], collid); + + if (strlen(str) <= (n->key->len + suffix_len) * DCH_MAX_ITEM_SIZ) strcpy(s, str); else ereport(ERROR, @@ -2826,11 +2866,26 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out, Oid col INVALID_FOR_INTERVAL; if (!tm->tm_mon) break; - if (IS_SUFFIX_TM(n->suffix)) + if (IS_SUFFIX_TM(n->suffix) || IS_SUFFIX_TAM(n->suffix)) { - char *str = str_tolower_z(localized_full_months[tm->tm_mon - 1], collid); + char *str; + char **localized_months; + int suffix_len; - if (strlen(str) <= (n->key->len + TM_SUFFIX_LEN) * DCH_MAX_ITEM_SIZ) + if (IS_SUFFIX_TM(n->suffix)) + { + localized_months = localized_full_months; + suffix_len = TM_SUFFIX_LEN; + } + else + { + localized_months = localized_alt_full_months; + suffix_len = TAM_SUFFIX_LEN; + } + + str = str_tolower_z(localized_months[tm->tm_mon - 1], collid); + + if (strlen(str) <= (n->key->len + suffix_len) * DCH_MAX_ITEM_SIZ) strcpy(s, str); else ereport(ERROR, @@ -3565,13 +3620,29 @@ DCH_from_char(FormatNode *node, const char *in, TmFromChar *out, case DCH_MONTH: case DCH_Month: case DCH_month: - if (!from_char_seq_search(&value, &s, months_full, - IS_SUFFIX_TM(n->suffix) ? localized_full_months : NULL, - collid, - n, escontext)) - return; - if (!from_char_set_int(&out->mm, value + 1, n, escontext)) - return; + { + char **months; + + if (IS_SUFFIX_TM(n->suffix) && IS_SUFFIX_TAM(n->suffix)) + ereturn(escontext,, + (errcode(ERRCODE_INVALID_DATETIME_FORMAT), + errmsg("TM and TAM prefixes cannot be used together"))); + + if (IS_SUFFIX_TM(n->suffix)) + months = localized_full_months; + else if (IS_SUFFIX_TAM(n->suffix)) + months = localized_alt_full_months; + else + months = NULL; + + if (!from_char_seq_search(&value, &s, months_full, + months, + collid, + n, escontext)) + return; + if (!from_char_set_int(&out->mm, value + 1, n, escontext)) + return; + } break; case DCH_MON: case DCH_Mon: diff --git a/src/backend/utils/adt/pg_locale.c b/src/backend/utils/adt/pg_locale.c index 9eb99487e57..34d758486b5 100644 --- a/src/backend/utils/adt/pg_locale.c +++ b/src/backend/utils/adt/pg_locale.c @@ -102,6 +102,7 @@ char *localized_abbrev_days[7 + 1]; char *localized_full_days[7 + 1]; char *localized_abbrev_months[12 + 1]; char *localized_full_months[12 + 1]; +char *localized_alt_full_months[12 + 1]; static pg_locale_t default_locale = NULL; @@ -701,7 +702,7 @@ cache_single_string(char **dst, const char *src, int encoding) void cache_locale_time(void) { - char buf[(2 * 7 + 2 * 12) * MAX_L10N_DATA]; + char buf[(2 * 7 + 3 * 12) * MAX_L10N_DATA]; char *bufptr; time_t timenow; struct tm *timeinfo; @@ -768,6 +769,9 @@ cache_locale_time(void) if (strftime_l(bufptr, MAX_L10N_DATA, "%B", timeinfo, locale) <= 0) strftimefail = true; bufptr += MAX_L10N_DATA; + if (strftime_l(bufptr, MAX_L10N_DATA, "%OB", timeinfo, locale) <= 0) + strftimefail = true; + bufptr += MAX_L10N_DATA; } #ifdef WIN32 @@ -824,9 +828,12 @@ cache_locale_time(void) bufptr += MAX_L10N_DATA; cache_single_string(&localized_full_months[i], bufptr, encoding); bufptr += MAX_L10N_DATA; + cache_single_string(&localized_alt_full_months[i], bufptr, encoding); + bufptr += MAX_L10N_DATA; } localized_abbrev_months[12] = NULL; localized_full_months[12] = NULL; + localized_alt_full_months[12] = NULL; CurrentLCTimeValid = true; } diff --git a/src/include/utils/pg_locale.h b/src/include/utils/pg_locale.h index b74821fdfa9..3f79d4f0c1c 100644 --- a/src/include/utils/pg_locale.h +++ b/src/include/utils/pg_locale.h @@ -43,6 +43,7 @@ extern PGDLLIMPORT char *localized_abbrev_days[]; extern PGDLLIMPORT char *localized_full_days[]; extern PGDLLIMPORT char *localized_abbrev_months[]; extern PGDLLIMPORT char *localized_full_months[]; +extern PGDLLIMPORT char *localized_alt_full_months[]; extern bool check_locale(int category, const char *locale, char **canonname); extern char *pg_perm_setlocale(int category, const char *locale); diff --git a/src/test/regress/expected/collate.linux.utf8.out b/src/test/regress/expected/collate.linux.utf8.out index e0a39e4c300..26a03ac4530 100644 --- a/src/test/regress/expected/collate.linux.utf8.out +++ b/src/test/regress/expected/collate.linux.utf8.out @@ -463,7 +463,22 @@ SELECT to_char(date '2010-04-01', 'DD TMMON YYYY' COLLATE "tr_TR"); 01 NİS 2010 (1 row) +-- to_char +SET lc_time TO 'cs_CZ'; +SELECT to_char(date '2010-02-01', 'DD TMMONTH'); + to_char +---------- + 01 ÚNORA +(1 row) + +SELECT to_char(date '2010-02-01', 'TAMMONTH'); + to_char +--------- + ÚNOR +(1 row) + -- to_date +SET lc_time TO 'tr_TR'; SELECT to_date('01 ŞUB 2010', 'DD TMMON YYYY'); to_date ------------ @@ -497,6 +512,19 @@ SELECT to_date('2010 01 araLık', 'YYYY DD TMMONTH'); 12-01-2010 (1 row) +SET lc_time TO 'cs_CZ'; +SELECT to_date('1 srpna 2010', 'DD TMMONTH YYYY'); + to_date +------------ + 08-01-2010 +(1 row) + +SELECT to_date('1 srpen 2010', 'DD TAMMONTH YYYY'); + to_date +------------ + 08-01-2010 +(1 row) + -- backwards parsing CREATE VIEW collview1 AS SELECT * FROM collate_test1 WHERE b COLLATE "C" >= 'bbc'; CREATE VIEW collview2 AS SELECT a, b FROM collate_test1 ORDER BY b COLLATE "C"; diff --git a/src/test/regress/sql/collate.linux.utf8.sql b/src/test/regress/sql/collate.linux.utf8.sql index 6d726ee9c99..3e7c356adb7 100644 --- a/src/test/regress/sql/collate.linux.utf8.sql +++ b/src/test/regress/sql/collate.linux.utf8.sql @@ -182,7 +182,14 @@ SELECT to_char(date '2010-02-01', 'DD TMMON YYYY' COLLATE "tr_TR"); SELECT to_char(date '2010-04-01', 'DD TMMON YYYY'); SELECT to_char(date '2010-04-01', 'DD TMMON YYYY' COLLATE "tr_TR"); +-- to_char +SET lc_time TO 'cs_CZ'; + +SELECT to_char(date '2010-02-01', 'DD TMMONTH'); +SELECT to_char(date '2010-02-01', 'TAMMONTH'); + -- to_date +SET lc_time TO 'tr_TR'; SELECT to_date('01 ŞUB 2010', 'DD TMMON YYYY'); SELECT to_date('01 Şub 2010', 'DD TMMON YYYY'); @@ -192,6 +199,11 @@ SELECT to_date('01 Aralık 2010', 'DD TMMONTH YYYY'); SELECT to_date('01 aralık 2010', 'DD TMMONTH YYYY'); SELECT to_date('2010 01 araLık', 'YYYY DD TMMONTH'); +SET lc_time TO 'cs_CZ'; + +SELECT to_date('1 srpna 2010', 'DD TMMONTH YYYY'); +SELECT to_date('1 srpen 2010', 'DD TAMMONTH YYYY'); + -- backwards parsing CREATE VIEW collview1 AS SELECT * FROM collate_test1 WHERE b COLLATE "C" >= 'bbc'; -- 2.55.0
^ permalink raw reply [nested|flat] 18+ messages in thread

* Re: missing possibility to use alternative translated month names in to_char function
@ 2026-08-15 12:03  Bernd Reiß <bd_reiss@gmx.at>
  parent: Pavel Stehule <pavel.stehule@gmail.com>
  1 sibling, 1 reply; 18+ messages in thread

From: Bernd Reiß @ 2026-08-15 12:03 UTC (permalink / raw)
  To: Pavel Stehule <pavel.stehule@gmail.com>; +Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>

Hi again,

thanks for the updated patch.
> TAMMON is not implemented, because glibc doesn't provide an 
> alternative form for abbreviated month names.
> It is a question if it is better to raise an error, return a non 
> alternative name or just ignore this flag. I have not strong
> opinion about this. Inside DCH_to_char the prefix TM is ignored when 
> it is not used. So I did the same.
The Locale standard actually mentions abbreviated alternative month 
names as
"ab_alt_mon" (see [1]). I tested this by setting your TAMMONTH strftime 
call to '%Ob'.
If we set the locale to Russian and call the function for May this 
actually returns
an abbreviated version of the month name:

Breakpoint 1, cache_locale_time () at pg_locale.c:772
772           if (strftime_l(bufptr, MAX_L10N_DATA, "%Ob", timeinfo, 
locale) <= 0)
(gdb) n
774                     bufptr += MAX_L10N_DATA;
(gdb) print bufptr
$4 = 0x7ffde4554630 "май"

Compared to the TMMON form of May in Russian this actually makes a 
difference:

postgres=# set lc_time='ru_RU.UTF8';
SET
postgres=# select to_char('2026-05-01'::date, 'TMMON');
  to_char
---------
  МАЯ
(1 row)

postgres=# select to_char('2026-05-01'::date, 'TAMMONTH');
  to_char
---------
  МАЙ
(1 row)

Again, TAMMONTH uses %Ob here. So I would argue for implementing the 
abbreviated
forms too.

>
>     Code Review
>     ===========
>     I am not sure if this condition can be ever true:
>
>     + if (IS_SUFFIX_TM(n->suffix) && IS_SUFFIX_TAM(n->suffix))
>
>     In case this is not possible the subsequent error message will
>     never be
>     thrown and the whole block is dead code.
>
>     However, if there is a reason for this check, it would be nice to
>     have a comment mention it.
>
>
> Yes, I badly expected that prefixes could be mixed. I checked the 
> code, and this is not possible, so I removed this check

I think you missed one occurrence in the current patch:

[bernd@paco patches]$ cat 
v2-0001-introduce-tam-modifier-for-date-timestamp-formatting.patch | 
grep -B4 together
+
+ if (IS_SUFFIX_TM(n->suffix) && IS_SUFFIX_TAM(n->suffix))
+         ereturn(escontext,,
+                         (errcode(ERRCODE_INVALID_DATETIME_FORMAT),
+                          errmsg("TM and TAM prefixes cannot be used 
together")));

>
>     One thing I am not entirely sure about is this line:
>
>     + if (strftime_l(bufptr, MAX_L10N_DATA, "%OB", timeinfo, locale) 
> <= 0)
>     +     strftimefail = true;
>
>     As far as I checked %OB is not supported on Windows:
>
> https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/strftime-wcsftime-strftime-l-wcsft... 
>
>
>     I was, however, not able to confirm this on a Windows machine
>     right now.
>     I might be able to do so on the weekend.
>
>     However, the same problem exists with older glibc versions not
>     supporting
>     %OB. As far as I understand strftime_l this will lead to it
>     returning 0 and
>     therefore setting strftimefail to true always. Since this if
>     statement
>     is evaluated
>     unconditionally I expect this to also influence the behaviour of TM.
>
>
> I am afraid about this case too, and I expect maybe some fallback mode 
> there. But because
> I have not a Window machine or some machine with older glibc I decided 
> to don't touch it
> for this moment.
>
> glibc older than 2.28 doesn't support %OB. On the second hand the 
> result of %B is probably
> equal to expected result %B.

Turns out I was wrong about this one. For one, although %OB is not 
supported, Windows
actually does fall back to %B when used:

postgres=# set lc_time='cs-CZ.UTF8';
SET
postgres=# SELECT to_char('2026-08-01'::date, 'TMMONTH');
  to_char
---------
  SRPEN
(1 row)

postgres=# SELECT to_char('2026-08-01'::date, 'TAMMONTH');
  to_char
---------
  SRPEN
(1 row)

The documentation for wcsftime even mentions this behaviour (see [2]).

Furthermore, strftime_l only returns 0 when the result string does not
fit the buffer (or the result is in fact empty, see [3]). The return 
value of
a function call with unrecognized format is not defined. glibc seems to
default to returning the format string itself:

PS C:\Users\bernd> docker run --rm -it debian:8 bash -c 'LC_TIME=C date 
"+%B"'
August
PS C:\Users\bernd> docker run --rm -it debian:8 bash -c 'LC_TIME=C date 
"+%OB"'
%OB

In my opinion this function call is very unlikely to ever return 0 
because %OB is not
defined. So I don't see an issue with that code segment after all, as 
this patch does
not interfere with TM and the current documentation of this patch 
mentions the
platform dependency of this feature. However, one could argue for 
checking whether
%OB/%Ob is literally returned and manually falling back to %B/%b to 
cover all bases
and make behaviour more consistent.

>
>     Nitpicking & Conclusion
>     =======================
>     I feel like the documentation could explicitly mention the difference
>     between TMMONTH and TAMMONTH (i.e., mentioning genitive and 
> nominative
>     like the Locale docs you mentioned do). I also think it would be
>     beneficial to
>     mention that this linguistic detail is specific to certain languages.
>
>
> please, if you can write this part of the doc. My English is not good 
> enough to write well about these linguistic details.
> It is a problem primarily for slavic languages - like Czech or Russian 
> - but maybe it can be a wide problem.

I attached a revised version of your patch to this message explaining the
difference from a linguistic standpoint. I also fixed the second 
listitem not
mentioning the suppression of trailing white space by TAM.

As English is also not my first language, I would be very glad if any 
native
speaker reading this could have a look over it. Any feedback is 
appreciated!

> Thank you very much for this immediate review
You are most welcome 🙂

Best
Bernd

[1] https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/V1_chap07.html
[2] https://en.cppreference.com/cpp/chrono/c/wcsftime
[3] https://man7.org/linux/man-pages/man3/strftime.3.html

Attachments:

v3-0001-introduce-tam-modifier-for-date-timestamp-formatt.patch (text/x-patch, 13.0K) download From 40ac8c6f05df816d10259fe7deaab2d7be91401f Mon Sep 17 00:00:00 2001 From: "okbob@github.com" <pavel.stehule@gmail.com> Date: Wed, 12 Aug 2026 07:03:28 +0200 Subject: [PATCH v3] introduce 'tam' modifier for date/timestamp formatting MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit glibc returns localized month names in the genitive case, but it also provides alternative month names in the nominative case. The TAM prefix allows you to retrieve this alternative name. example: SELECT to_char(date '2026-08-01', 'TMMONTH'); ┌─────────┐ │ to_char │ ╞═════════╡ │ SRPNA │ └─────────┘ (1 row) SELECT to_char(date '2026-08-01', 'TAMMONTH'); ┌─────────┐ │ to_char │ ╞═════════╡ │ SRPEN │ └─────────┘ (1 row) --- doc/src/sgml/func/func-formatting.sgml | 31 +++++- src/backend/utils/adt/formatting.c | 103 +++++++++++++++--- src/backend/utils/adt/pg_locale.c | 9 +- src/include/utils/pg_locale.h | 1 + .../regress/expected/collate.linux.utf8.out | 28 +++++ src/test/regress/sql/collate.linux.utf8.sql | 12 ++ 6 files changed, 165 insertions(+), 19 deletions(-) diff --git a/doc/src/sgml/func/func-formatting.sgml b/doc/src/sgml/func/func-formatting.sgml index e4edaf4f42..2c356e7e8e 100644 --- a/doc/src/sgml/func/func-formatting.sgml +++ b/doc/src/sgml/func/func-formatting.sgml @@ -477,6 +477,12 @@ <xref linkend="guc-lc-time"/>)</entry> <entry><literal>TMMonth</literal></entry> </row> + <row> + <entry><literal>TAM</literal> prefix</entry> + <entry>translation alternative mode (use localized alternative month names based on + <xref linkend="guc-lc-time"/>; see usage notes)</entry> + <entry><literal>TAMMonth</literal></entry> + </row> <row> <entry><literal>SP</literal> suffix</entry> <entry>spell mode (not implemented)</entry> @@ -504,8 +510,29 @@ <listitem> <para> - <literal>TM</literal> suppresses trailing blanks whether or - not <literal>FM</literal> is specified. + <literal>TM</literal> and <literal>TAM</literal> suppress trailing + blanks whether or not <literal>FM</literal> is specified. + </para> + </listitem> + + <listitem> + <para> + <literal>TM</literal> and <literal>TAM</literal> both produce + localized month names according to <xref linkend="guc-lc-time"/>, + but they can differ for certain languages that inflect month names + (e.g., Slavic languages). In such languages <literal>TM</literal> + produces the form used together with a day number, which is often the + genitive case, while <literal>TAM</literal> produces the standalone + (nominative) form. For example, with <literal>lc_time</literal> set to + a Czech locale, <literal>to_char('2026-08-01'::date, 'TMMONTH')</literal> + returns <literal>SRPNA</literal> (genitive), whereas + <literal>to_char('2026-08-01'::date, 'TAMMONTH')</literal> returns + <literal>SRPEN</literal> (nominative). For languages that do not draw + this distinction, and for the <literal>C</literal> locale, the two + modifiers produce the same result. This distinction relies on + alternative month names being available from the underlying operating + system's locale support, so <literal>TAM</literal> may not be effective + on all platforms. </para> </listitem> diff --git a/src/backend/utils/adt/formatting.c b/src/backend/utils/adt/formatting.c index effad4c37d..42f7935ac7 100644 --- a/src/backend/utils/adt/formatting.c +++ b/src/backend/utils/adt/formatting.c @@ -553,6 +553,7 @@ do { \ #define DCH_SUFFIX_th 0x04 #define DCH_SUFFIX_SP 0x08 #define DCH_SUFFIX_TM 0x10 +#define DCH_SUFFIX_TAM 0x20 /* * Suffix tests @@ -594,16 +595,25 @@ IS_SUFFIX_TM(uint8 _s) return (_s & DCH_SUFFIX_TM); } +static inline bool +IS_SUFFIX_TAM(uint8 _s) +{ + return (_s & DCH_SUFFIX_TAM); +} + /* * Suffixes definition for DATE-TIME TO/FROM CHAR */ #define TM_SUFFIX_LEN 2 +#define TAM_SUFFIX_LEN 3 static const KeySuffix DCH_suff[] = { {"FM", 2, DCH_SUFFIX_FM, SUFFTYPE_PREFIX}, {"fm", 2, DCH_SUFFIX_FM, SUFFTYPE_PREFIX}, {"TM", TM_SUFFIX_LEN, DCH_SUFFIX_TM, SUFFTYPE_PREFIX}, + {"TAM", TAM_SUFFIX_LEN, DCH_SUFFIX_TAM, SUFFTYPE_PREFIX}, {"tm", 2, DCH_SUFFIX_TM, SUFFTYPE_PREFIX}, + {"tam", 3, DCH_SUFFIX_TAM, SUFFTYPE_PREFIX}, {"TH", 2, DCH_SUFFIX_TH, SUFFTYPE_POSTFIX}, {"th", 2, DCH_SUFFIX_th, SUFFTYPE_POSTFIX}, {"SP", 2, DCH_SUFFIX_SP, SUFFTYPE_POSTFIX}, @@ -2786,11 +2796,26 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out, Oid col INVALID_FOR_INTERVAL; if (!tm->tm_mon) break; - if (IS_SUFFIX_TM(n->suffix)) + if (IS_SUFFIX_TM(n->suffix) || IS_SUFFIX_TAM(n->suffix)) { - char *str = str_toupper_z(localized_full_months[tm->tm_mon - 1], collid); + char *str; + char **localized_months; + int suffix_len; - if (strlen(str) <= (n->key->len + TM_SUFFIX_LEN) * DCH_MAX_ITEM_SIZ) + if (IS_SUFFIX_TM(n->suffix)) + { + localized_months = localized_full_months; + suffix_len = TM_SUFFIX_LEN; + } + else + { + localized_months = localized_alt_full_months; + suffix_len = TAM_SUFFIX_LEN; + } + + str = str_toupper_z(localized_months[tm->tm_mon - 1], collid); + + if (strlen(str) <= (n->key->len + suffix_len) * DCH_MAX_ITEM_SIZ) strcpy(s, str); else ereport(ERROR, @@ -2806,11 +2831,26 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out, Oid col INVALID_FOR_INTERVAL; if (!tm->tm_mon) break; - if (IS_SUFFIX_TM(n->suffix)) + if (IS_SUFFIX_TM(n->suffix) || IS_SUFFIX_TAM(n->suffix)) { - char *str = str_initcap_z(localized_full_months[tm->tm_mon - 1], collid); + char *str; + char **localized_months; + int suffix_len; - if (strlen(str) <= (n->key->len + TM_SUFFIX_LEN) * DCH_MAX_ITEM_SIZ) + if (IS_SUFFIX_TM(n->suffix)) + { + localized_months = localized_full_months; + suffix_len = TM_SUFFIX_LEN; + } + else + { + localized_months = localized_alt_full_months; + suffix_len = TAM_SUFFIX_LEN; + } + + str = str_initcap_z(localized_months[tm->tm_mon - 1], collid); + + if (strlen(str) <= (n->key->len + suffix_len) * DCH_MAX_ITEM_SIZ) strcpy(s, str); else ereport(ERROR, @@ -2826,11 +2866,26 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out, Oid col INVALID_FOR_INTERVAL; if (!tm->tm_mon) break; - if (IS_SUFFIX_TM(n->suffix)) + if (IS_SUFFIX_TM(n->suffix) || IS_SUFFIX_TAM(n->suffix)) { - char *str = str_tolower_z(localized_full_months[tm->tm_mon - 1], collid); + char *str; + char **localized_months; + int suffix_len; - if (strlen(str) <= (n->key->len + TM_SUFFIX_LEN) * DCH_MAX_ITEM_SIZ) + if (IS_SUFFIX_TM(n->suffix)) + { + localized_months = localized_full_months; + suffix_len = TM_SUFFIX_LEN; + } + else + { + localized_months = localized_alt_full_months; + suffix_len = TAM_SUFFIX_LEN; + } + + str = str_tolower_z(localized_months[tm->tm_mon - 1], collid); + + if (strlen(str) <= (n->key->len + suffix_len) * DCH_MAX_ITEM_SIZ) strcpy(s, str); else ereport(ERROR, @@ -3565,13 +3620,29 @@ DCH_from_char(FormatNode *node, const char *in, TmFromChar *out, case DCH_MONTH: case DCH_Month: case DCH_month: - if (!from_char_seq_search(&value, &s, months_full, - IS_SUFFIX_TM(n->suffix) ? localized_full_months : NULL, - collid, - n, escontext)) - return; - if (!from_char_set_int(&out->mm, value + 1, n, escontext)) - return; + { + char **months; + + if (IS_SUFFIX_TM(n->suffix) && IS_SUFFIX_TAM(n->suffix)) + ereturn(escontext,, + (errcode(ERRCODE_INVALID_DATETIME_FORMAT), + errmsg("TM and TAM prefixes cannot be used together"))); + + if (IS_SUFFIX_TM(n->suffix)) + months = localized_full_months; + else if (IS_SUFFIX_TAM(n->suffix)) + months = localized_alt_full_months; + else + months = NULL; + + if (!from_char_seq_search(&value, &s, months_full, + months, + collid, + n, escontext)) + return; + if (!from_char_set_int(&out->mm, value + 1, n, escontext)) + return; + } break; case DCH_MON: case DCH_Mon: diff --git a/src/backend/utils/adt/pg_locale.c b/src/backend/utils/adt/pg_locale.c index 9eb99487e5..34d758486b 100644 --- a/src/backend/utils/adt/pg_locale.c +++ b/src/backend/utils/adt/pg_locale.c @@ -102,6 +102,7 @@ char *localized_abbrev_days[7 + 1]; char *localized_full_days[7 + 1]; char *localized_abbrev_months[12 + 1]; char *localized_full_months[12 + 1]; +char *localized_alt_full_months[12 + 1]; static pg_locale_t default_locale = NULL; @@ -701,7 +702,7 @@ cache_single_string(char **dst, const char *src, int encoding) void cache_locale_time(void) { - char buf[(2 * 7 + 2 * 12) * MAX_L10N_DATA]; + char buf[(2 * 7 + 3 * 12) * MAX_L10N_DATA]; char *bufptr; time_t timenow; struct tm *timeinfo; @@ -768,6 +769,9 @@ cache_locale_time(void) if (strftime_l(bufptr, MAX_L10N_DATA, "%B", timeinfo, locale) <= 0) strftimefail = true; bufptr += MAX_L10N_DATA; + if (strftime_l(bufptr, MAX_L10N_DATA, "%OB", timeinfo, locale) <= 0) + strftimefail = true; + bufptr += MAX_L10N_DATA; } #ifdef WIN32 @@ -824,9 +828,12 @@ cache_locale_time(void) bufptr += MAX_L10N_DATA; cache_single_string(&localized_full_months[i], bufptr, encoding); bufptr += MAX_L10N_DATA; + cache_single_string(&localized_alt_full_months[i], bufptr, encoding); + bufptr += MAX_L10N_DATA; } localized_abbrev_months[12] = NULL; localized_full_months[12] = NULL; + localized_alt_full_months[12] = NULL; CurrentLCTimeValid = true; } diff --git a/src/include/utils/pg_locale.h b/src/include/utils/pg_locale.h index b74821fdfa..3f79d4f0c1 100644 --- a/src/include/utils/pg_locale.h +++ b/src/include/utils/pg_locale.h @@ -43,6 +43,7 @@ extern PGDLLIMPORT char *localized_abbrev_days[]; extern PGDLLIMPORT char *localized_full_days[]; extern PGDLLIMPORT char *localized_abbrev_months[]; extern PGDLLIMPORT char *localized_full_months[]; +extern PGDLLIMPORT char *localized_alt_full_months[]; extern bool check_locale(int category, const char *locale, char **canonname); extern char *pg_perm_setlocale(int category, const char *locale); diff --git a/src/test/regress/expected/collate.linux.utf8.out b/src/test/regress/expected/collate.linux.utf8.out index e0a39e4c30..26a03ac453 100644 --- a/src/test/regress/expected/collate.linux.utf8.out +++ b/src/test/regress/expected/collate.linux.utf8.out @@ -463,7 +463,22 @@ SELECT to_char(date '2010-04-01', 'DD TMMON YYYY' COLLATE "tr_TR"); 01 NİS 2010 (1 row) +-- to_char +SET lc_time TO 'cs_CZ'; +SELECT to_char(date '2010-02-01', 'DD TMMONTH'); + to_char +---------- + 01 ÚNORA +(1 row) + +SELECT to_char(date '2010-02-01', 'TAMMONTH'); + to_char +--------- + ÚNOR +(1 row) + -- to_date +SET lc_time TO 'tr_TR'; SELECT to_date('01 ŞUB 2010', 'DD TMMON YYYY'); to_date ------------ @@ -497,6 +512,19 @@ SELECT to_date('2010 01 araLık', 'YYYY DD TMMONTH'); 12-01-2010 (1 row) +SET lc_time TO 'cs_CZ'; +SELECT to_date('1 srpna 2010', 'DD TMMONTH YYYY'); + to_date +------------ + 08-01-2010 +(1 row) + +SELECT to_date('1 srpen 2010', 'DD TAMMONTH YYYY'); + to_date +------------ + 08-01-2010 +(1 row) + -- backwards parsing CREATE VIEW collview1 AS SELECT * FROM collate_test1 WHERE b COLLATE "C" >= 'bbc'; CREATE VIEW collview2 AS SELECT a, b FROM collate_test1 ORDER BY b COLLATE "C"; diff --git a/src/test/regress/sql/collate.linux.utf8.sql b/src/test/regress/sql/collate.linux.utf8.sql index 6d726ee9c9..3e7c356adb 100644 --- a/src/test/regress/sql/collate.linux.utf8.sql +++ b/src/test/regress/sql/collate.linux.utf8.sql @@ -182,7 +182,14 @@ SELECT to_char(date '2010-02-01', 'DD TMMON YYYY' COLLATE "tr_TR"); SELECT to_char(date '2010-04-01', 'DD TMMON YYYY'); SELECT to_char(date '2010-04-01', 'DD TMMON YYYY' COLLATE "tr_TR"); +-- to_char +SET lc_time TO 'cs_CZ'; + +SELECT to_char(date '2010-02-01', 'DD TMMONTH'); +SELECT to_char(date '2010-02-01', 'TAMMONTH'); + -- to_date +SET lc_time TO 'tr_TR'; SELECT to_date('01 ŞUB 2010', 'DD TMMON YYYY'); SELECT to_date('01 Şub 2010', 'DD TMMON YYYY'); @@ -192,6 +199,11 @@ SELECT to_date('01 Aralık 2010', 'DD TMMONTH YYYY'); SELECT to_date('01 aralık 2010', 'DD TMMONTH YYYY'); SELECT to_date('2010 01 araLık', 'YYYY DD TMMONTH'); +SET lc_time TO 'cs_CZ'; + +SELECT to_date('1 srpna 2010', 'DD TMMONTH YYYY'); +SELECT to_date('1 srpen 2010', 'DD TAMMONTH YYYY'); + -- backwards parsing CREATE VIEW collview1 AS SELECT * FROM collate_test1 WHERE b COLLATE "C" >= 'bbc'; -- 2.55.0
^ permalink raw reply [nested|flat] 18+ messages in thread

* Re: missing possibility to use alternative translated month names in to_char function
@ 2026-08-18 18:47  Pavel Stehule <pavel.stehule@gmail.com>
  parent: Bernd Reiß <bd_reiss@gmx.at>
  0 siblings, 1 reply; 18+ messages in thread

From: Pavel Stehule @ 2026-08-18 18:47 UTC (permalink / raw)
  To: Bernd Reiß <bd_reiss@gmx.at>; +Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>

Hi

so 15. 8. 2026 v 14:03 odesílatel Bernd Reiß <bd_reiss@gmx.at> napsal:

> Hi again,
>
> thanks for the updated patch.
> > TAMMON is not implemented, because glibc doesn't provide an
> > alternative form for abbreviated month names.
> > It is a question if it is better to raise an error, return a non
> > alternative name or just ignore this flag. I have not strong
> > opinion about this. Inside DCH_to_char the prefix TM is ignored when
> > it is not used. So I did the same.
> The Locale standard actually mentions abbreviated alternative month
> names as
> "ab_alt_mon" (see [1]). I tested this by setting your TAMMONTH strftime
> call to '%Ob'.
> If we set the locale to Russian and call the function for May this
> actually returns
> an abbreviated version of the month name:
>
> Breakpoint 1, cache_locale_time () at pg_locale.c:772
> 772           if (strftime_l(bufptr, MAX_L10N_DATA, "%Ob", timeinfo,
> locale) <= 0)
> (gdb) n
> 774                     bufptr += MAX_L10N_DATA;
> (gdb) print bufptr
> $4 = 0x7ffde4554630 "май"
>
> Compared to the TMMON form of May in Russian this actually makes a
> difference:
>
> postgres=# set lc_time='ru_RU.UTF8';
> SET
> postgres=# select to_char('2026-05-01'::date, 'TMMON');
>   to_char
> ---------
>   МАЯ
> (1 row)
>
> postgres=# select to_char('2026-05-01'::date, 'TAMMONTH');
>   to_char
> ---------
>   МАЙ
> (1 row)
>
> Again, TAMMONTH uses %Ob here. So I would argue for implementing the
> abbreviated
> forms too.
>

I implemented it - please check


> >
> >     Code Review
> >     ===========
> >     I am not sure if this condition can be ever true:
> >
> >     + if (IS_SUFFIX_TM(n->suffix) && IS_SUFFIX_TAM(n->suffix))
> >
> >     In case this is not possible the subsequent error message will
> >     never be
> >     thrown and the whole block is dead code.
> >
> >     However, if there is a reason for this check, it would be nice to
> >     have a comment mention it.
> >
> >
> > Yes, I badly expected that prefixes could be mixed. I checked the
> > code, and this is not possible, so I removed this check
>
> I think you missed one occurrence in the current patch:
>
> [bernd@paco patches]$ cat
> v2-0001-introduce-tam-modifier-for-date-timestamp-formatting.patch |
> grep -B4 together
> +
> + if (IS_SUFFIX_TM(n->suffix) && IS_SUFFIX_TAM(n->suffix))
> +         ereturn(escontext,,
> +                         (errcode(ERRCODE_INVALID_DATETIME_FORMAT),
> +                          errmsg("TM and TAM prefixes cannot be used
> together")));
>

removed


>
> >
> >     One thing I am not entirely sure about is this line:
> >
> >     + if (strftime_l(bufptr, MAX_L10N_DATA, "%OB", timeinfo, locale)
> > <= 0)
> >     +     strftimefail = true;
> >
> >     As far as I checked %OB is not supported on Windows:
> >
> >
> https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/strftime-wcsftime-strftime-l-wcsft...
> >
> >
> >     I was, however, not able to confirm this on a Windows machine
> >     right now.
> >     I might be able to do so on the weekend.
> >
> >     However, the same problem exists with older glibc versions not
> >     supporting
> >     %OB. As far as I understand strftime_l this will lead to it
> >     returning 0 and
> >     therefore setting strftimefail to true always. Since this if
> >     statement
> >     is evaluated
> >     unconditionally I expect this to also influence the behaviour of TM.
> >
> >
> > I am afraid about this case too, and I expect maybe some fallback mode
> > there. But because
> > I have not a Window machine or some machine with older glibc I decided
> > to don't touch it
> > for this moment.
> >
> > glibc older than 2.28 doesn't support %OB. On the second hand the
> > result of %B is probably
> > equal to expected result %B.
>
> Turns out I was wrong about this one. For one, although %OB is not
> supported, Windows
> actually does fall back to %B when used:
>
> postgres=# set lc_time='cs-CZ.UTF8';
> SET
> postgres=# SELECT to_char('2026-08-01'::date, 'TMMONTH');
>   to_char
> ---------
>   SRPEN
> (1 row)
>
> postgres=# SELECT to_char('2026-08-01'::date, 'TAMMONTH');
>   to_char
> ---------
>   SRPEN
> (1 row)
>
> The documentation for wcsftime even mentions this behaviour (see [2]).
>
> Furthermore, strftime_l only returns 0 when the result string does not
> fit the buffer (or the result is in fact empty, see [3]). The return
> value of
> a function call with unrecognized format is not defined. glibc seems to
> default to returning the format string itself:
>
> PS C:\Users\bernd> docker run --rm -it debian:8 bash -c 'LC_TIME=C date
> "+%B"'
> August
> PS C:\Users\bernd> docker run --rm -it debian:8 bash -c 'LC_TIME=C date
> "+%OB"'
> %OB
>
> In my opinion this function call is very unlikely to ever return 0
> because %OB is not
> defined. So I don't see an issue with that code segment after all, as
> this patch does
> not interfere with TM and the current documentation of this patch
> mentions the
> platform dependency of this feature. However, one could argue for
> checking whether
> %OB/%Ob is literally returned and manually falling back to %B/%b to
> cover all bases
> and make behaviour more consistent.
>
> >
> >     Nitpicking & Conclusion
> >     =======================
> >     I feel like the documentation could explicitly mention the difference
> >     between TMMONTH and TAMMONTH (i.e., mentioning genitive and
> > nominative
> >     like the Locale docs you mentioned do). I also think it would be
> >     beneficial to
> >     mention that this linguistic detail is specific to certain languages.
> >
> >
> > please, if you can write this part of the doc. My English is not good
> > enough to write well about these linguistic details.
> > It is a problem primarily for slavic languages - like Czech or Russian
> > - but maybe it can be a wide problem.
>
> I attached a revised version of your patch to this message explaining the
> difference from a linguistic standpoint. I also fixed the second
> listitem not
> mentioning the suppression of trailing white space by TAM.
>
> As English is also not my first language, I would be very glad if any
> native
> speaker reading this could have a look over it. Any feedback is
> appreciated!
>

I merged your documentation patch, thank you


>
> > Thank you very much for this immediate review
> You are most welcome 🙂
>

:-)

Please check updated patch

Nice evening

Pavel


> Best
> Bernd
>
> [1]
> https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/V1_chap07.html
> [2] https://en.cppreference.com/cpp/chrono/c/wcsftime
> [3] https://man7.org/linux/man-pages/man3/strftime.3.html
>

Attachments:

v20260818-4-0001-introduce-tam-modifier-for-date-timestamp-formatting.patch (text/x-patch, 17.0K) download From f471aba088bd438a731c598060f11871c7fd1264 Mon Sep 17 00:00:00 2001 From: "okbob@github.com" <pavel.stehule@gmail.com> Date: Wed, 12 Aug 2026 07:03:28 +0200 Subject: [PATCH] introduce 'tam' modifier for date/timestamp formatting MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit glibc returns localized month names in the genitive case, but it also provides alternative month names in the nominative case. The TAM prefix allows you to retrieve this alternative name. example: SELECT to_char(date '2026-08-01', 'TMMONTH'); ┌─────────┐ │ to_char │ ╞═════════╡ │ SRPNA │ └─────────┘ (1 row) SELECT to_char(date '2026-08-01', 'TAMMONTH'); ┌─────────┐ │ to_char │ ╞═════════╡ │ SRPEN │ └─────────┘ (1 row) --- doc/src/sgml/func/func-formatting.sgml | 31 +++- src/backend/utils/adt/formatting.c | 170 +++++++++++++++--- src/backend/utils/adt/pg_locale.c | 16 +- src/include/utils/pg_locale.h | 2 + .../regress/expected/collate.linux.utf8.out | 40 +++++ src/test/regress/sql/collate.linux.utf8.sql | 14 ++ 6 files changed, 241 insertions(+), 32 deletions(-) diff --git a/doc/src/sgml/func/func-formatting.sgml b/doc/src/sgml/func/func-formatting.sgml index e4edaf4f42c..563587dc617 100644 --- a/doc/src/sgml/func/func-formatting.sgml +++ b/doc/src/sgml/func/func-formatting.sgml @@ -477,6 +477,12 @@ <xref linkend="guc-lc-time"/>)</entry> <entry><literal>TMMonth</literal></entry> </row> + <row> + <entry><literal>TAM</literal> prefix</entry> + <entry>translation alternative mode (use localized alternative month names based on + <xref linkend="guc-lc-time"/>; see usage notes)</entry> + <entry><literal>TAMMonth</literal></entry> + </row> <row> <entry><literal>SP</literal> suffix</entry> <entry>spell mode (not implemented)</entry> @@ -504,8 +510,29 @@ <listitem> <para> - <literal>TM</literal> suppresses trailing blanks whether or - not <literal>FM</literal> is specified. + <literal>TM</literal> and <literal>TAM</literal> suppress trailing + blanks whether or not <literal>FM</literal> is specified. + </para> + </listitem> + + <listitem> + <para> + <literal>TM</literal> and <literal>TAM</literal> both produce + localized month names according to <xref linkend="guc-lc-time"/>, + but they can differ for certain languages that inflect month names + (e.g., Slavic languages). In such languages <literal>TM</literal> + produces the form used together with a day number, which is often the + genitive case, while <literal>TAM</literal> produces the standalone + (nominative) form. For example, with <literal>lc_time</literal> set to + a Czech locale, <literal>to_char('2026-08-01'::date, 'TMMONTH')</literal> + returns <literal>SRPNA</literal> (genitive), whereas + <literal>to_char('2026-08-01'::date, 'TAMMONTH')</literal> returns + <literal>SRPEN</literal> (nominative). For languages that do not draw + this distinction, and for the <literal>C</literal> locale, the two + modifiers produce the same result. This distinction relies on + alternative month names being available from the underlying operating + system's locale support, so <literal>TAM</literal> may not be effective + on all platforms. </para> </listitem> diff --git a/src/backend/utils/adt/formatting.c b/src/backend/utils/adt/formatting.c index effad4c37dd..f5376d0a0a7 100644 --- a/src/backend/utils/adt/formatting.c +++ b/src/backend/utils/adt/formatting.c @@ -553,6 +553,7 @@ do { \ #define DCH_SUFFIX_th 0x04 #define DCH_SUFFIX_SP 0x08 #define DCH_SUFFIX_TM 0x10 +#define DCH_SUFFIX_TAM 0x20 /* * Suffix tests @@ -594,16 +595,25 @@ IS_SUFFIX_TM(uint8 _s) return (_s & DCH_SUFFIX_TM); } +static inline bool +IS_SUFFIX_TAM(uint8 _s) +{ + return (_s & DCH_SUFFIX_TAM); +} + /* * Suffixes definition for DATE-TIME TO/FROM CHAR */ #define TM_SUFFIX_LEN 2 +#define TAM_SUFFIX_LEN 3 static const KeySuffix DCH_suff[] = { {"FM", 2, DCH_SUFFIX_FM, SUFFTYPE_PREFIX}, {"fm", 2, DCH_SUFFIX_FM, SUFFTYPE_PREFIX}, {"TM", TM_SUFFIX_LEN, DCH_SUFFIX_TM, SUFFTYPE_PREFIX}, + {"TAM", TAM_SUFFIX_LEN, DCH_SUFFIX_TAM, SUFFTYPE_PREFIX}, {"tm", 2, DCH_SUFFIX_TM, SUFFTYPE_PREFIX}, + {"tam", 3, DCH_SUFFIX_TAM, SUFFTYPE_PREFIX}, {"TH", 2, DCH_SUFFIX_TH, SUFFTYPE_POSTFIX}, {"th", 2, DCH_SUFFIX_th, SUFFTYPE_POSTFIX}, {"SP", 2, DCH_SUFFIX_SP, SUFFTYPE_POSTFIX}, @@ -2573,6 +2583,50 @@ from_char_seq_search(int *dest, const char **src, const char *const *array, return true; } +/* + * Allow to choose localized names or alternative localized names by + * usage prefix TM or TAM. Simple code, just reduction of repeated code. + */ +static char ** +get_localized_abbrev_months(uint8 suffix, int *suffix_len) +{ + if (IS_SUFFIX_TM(suffix)) + { + *suffix_len = 2; + return localized_abbrev_months; + } + else if (IS_SUFFIX_TAM(suffix)) + { + *suffix_len = 3; + return localized_alt_abbrev_months; + } + else + { + *suffix_len = 0; + return NULL; + } +} + +static char ** +get_localized_full_months(uint8 suffix, int *suffix_len) +{ + if (IS_SUFFIX_TM(suffix)) + { + *suffix_len = 2; + return localized_full_months; + } + else if (IS_SUFFIX_TAM(suffix)) + { + *suffix_len = 3; + return localized_alt_full_months; + } + else + { + *suffix_len = 0; + return NULL; + } +} + /* * Process a TmToChar struct as denoted by a list of FormatNodes. * The formatted data is written to the string pointed to by 'out'. @@ -2786,11 +2840,18 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out, Oid col INVALID_FOR_INTERVAL; if (!tm->tm_mon) break; - if (IS_SUFFIX_TM(n->suffix)) + if (IS_SUFFIX_TM(n->suffix) || IS_SUFFIX_TAM(n->suffix)) { - char *str = str_toupper_z(localized_full_months[tm->tm_mon - 1], collid); + char *str; + char **localized_months; + int suffix_len; - if (strlen(str) <= (n->key->len + TM_SUFFIX_LEN) * DCH_MAX_ITEM_SIZ) + localized_months = get_localized_full_months(n->suffix, + &suffix_len); + + str = str_toupper_z(localized_months[tm->tm_mon - 1], collid); + + if (strlen(str) <= (n->key->len + suffix_len) * DCH_MAX_ITEM_SIZ) strcpy(s, str); else ereport(ERROR, @@ -2806,11 +2867,18 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out, Oid col INVALID_FOR_INTERVAL; if (!tm->tm_mon) break; - if (IS_SUFFIX_TM(n->suffix)) + if (IS_SUFFIX_TM(n->suffix) || IS_SUFFIX_TAM(n->suffix)) { - char *str = str_initcap_z(localized_full_months[tm->tm_mon - 1], collid); + char *str; + char **localized_months; + int suffix_len; - if (strlen(str) <= (n->key->len + TM_SUFFIX_LEN) * DCH_MAX_ITEM_SIZ) + localized_months = get_localized_full_months(n->suffix, + &suffix_len); + + str = str_initcap_z(localized_months[tm->tm_mon - 1], collid); + + if (strlen(str) <= (n->key->len + suffix_len) * DCH_MAX_ITEM_SIZ) strcpy(s, str); else ereport(ERROR, @@ -2826,11 +2894,18 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out, Oid col INVALID_FOR_INTERVAL; if (!tm->tm_mon) break; - if (IS_SUFFIX_TM(n->suffix)) + if (IS_SUFFIX_TM(n->suffix) || IS_SUFFIX_TAM(n->suffix)) { - char *str = str_tolower_z(localized_full_months[tm->tm_mon - 1], collid); + char *str; + char **localized_months; + int suffix_len; - if (strlen(str) <= (n->key->len + TM_SUFFIX_LEN) * DCH_MAX_ITEM_SIZ) + localized_months = get_localized_full_months(n->suffix, + &suffix_len); + + str = str_tolower_z(localized_months[tm->tm_mon - 1], collid); + + if (strlen(str) <= (n->key->len + suffix_len) * DCH_MAX_ITEM_SIZ) strcpy(s, str); else ereport(ERROR, @@ -2846,9 +2921,16 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out, Oid col INVALID_FOR_INTERVAL; if (!tm->tm_mon) break; - if (IS_SUFFIX_TM(n->suffix)) + if (IS_SUFFIX_TM(n->suffix) || IS_SUFFIX_TAM(n->suffix)) { - char *str = str_toupper_z(localized_abbrev_months[tm->tm_mon - 1], collid); + char *str; + char **localized_months; + int suffix_len; + + localized_months = get_localized_abbrev_months(n->suffix, + &suffix_len); + + str = str_toupper_z(localized_months[tm->tm_mon - 1], collid); if (strlen(str) <= (n->key->len + TM_SUFFIX_LEN) * DCH_MAX_ITEM_SIZ) strcpy(s, str); @@ -2865,9 +2947,16 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out, Oid col INVALID_FOR_INTERVAL; if (!tm->tm_mon) break; - if (IS_SUFFIX_TM(n->suffix)) + if (IS_SUFFIX_TM(n->suffix) || IS_SUFFIX_TAM(n->suffix)) { - char *str = str_initcap_z(localized_abbrev_months[tm->tm_mon - 1], collid); + char *str; + char **localized_months; + int suffix_len; + + localized_months = get_localized_abbrev_months(n->suffix, + &suffix_len); + + str = str_initcap_z(localized_months[tm->tm_mon - 1], collid); if (strlen(str) <= (n->key->len + TM_SUFFIX_LEN) * DCH_MAX_ITEM_SIZ) strcpy(s, str); @@ -2884,9 +2973,16 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out, Oid col INVALID_FOR_INTERVAL; if (!tm->tm_mon) break; - if (IS_SUFFIX_TM(n->suffix)) + if (IS_SUFFIX_TM(n->suffix) || IS_SUFFIX_TAM(n->suffix)) { - char *str = str_tolower_z(localized_abbrev_months[tm->tm_mon - 1], collid); + char *str; + char **localized_months; + int suffix_len; + + localized_months = get_localized_abbrev_months(n->suffix, + &suffix_len); + + str = str_tolower_z(localized_months[tm->tm_mon - 1], collid); if (strlen(str) <= (n->key->len + TM_SUFFIX_LEN) * DCH_MAX_ITEM_SIZ) strcpy(s, str); @@ -3565,24 +3661,40 @@ DCH_from_char(FormatNode *node, const char *in, TmFromChar *out, case DCH_MONTH: case DCH_Month: case DCH_month: - if (!from_char_seq_search(&value, &s, months_full, - IS_SUFFIX_TM(n->suffix) ? localized_full_months : NULL, - collid, - n, escontext)) - return; - if (!from_char_set_int(&out->mm, value + 1, n, escontext)) - return; + { + char **localized_months; + int suffix_len; + + localized_months = get_localized_full_months(n->suffix, + &suffix_len); + + if (!from_char_seq_search(&value, &s, months_full, + localized_months, + collid, + n, escontext)) + return; + if (!from_char_set_int(&out->mm, value + 1, n, escontext)) + return; + } break; case DCH_MON: case DCH_Mon: case DCH_mon: - if (!from_char_seq_search(&value, &s, months, - IS_SUFFIX_TM(n->suffix) ? localized_abbrev_months : NULL, - collid, - n, escontext)) - return; - if (!from_char_set_int(&out->mm, value + 1, n, escontext)) - return; + { + char **localized_months; + int suffix_len; + + localized_months = get_localized_abbrev_months(n->suffix, + &suffix_len); + + if (!from_char_seq_search(&value, &s, months, + localized_months, + collid, + n, escontext)) + return; + if (!from_char_set_int(&out->mm, value + 1, n, escontext)) + return; + } break; case DCH_MM: if (from_char_parse_int(&out->mm, &s, n, escontext) < 0) diff --git a/src/backend/utils/adt/pg_locale.c b/src/backend/utils/adt/pg_locale.c index 9eb99487e57..773a563867e 100644 --- a/src/backend/utils/adt/pg_locale.c +++ b/src/backend/utils/adt/pg_locale.c @@ -101,7 +101,9 @@ int icu_validation_level = WARNING; char *localized_abbrev_days[7 + 1]; char *localized_full_days[7 + 1]; char *localized_abbrev_months[12 + 1]; +char *localized_alt_abbrev_months[12 + 1]; char *localized_full_months[12 + 1]; +char *localized_alt_full_months[12 + 1]; static pg_locale_t default_locale = NULL; @@ -701,7 +703,7 @@ cache_single_string(char **dst, const char *src, int encoding) void cache_locale_time(void) { - char buf[(2 * 7 + 2 * 12) * MAX_L10N_DATA]; + char buf[(2 * 7 + 4 * 12) * MAX_L10N_DATA]; char *bufptr; time_t timenow; struct tm *timeinfo; @@ -765,9 +767,15 @@ cache_locale_time(void) if (strftime_l(bufptr, MAX_L10N_DATA, "%b", timeinfo, locale) <= 0) strftimefail = true; bufptr += MAX_L10N_DATA; + if (strftime_l(bufptr, MAX_L10N_DATA, "%Ob", timeinfo, locale) <= 0) + strftimefail = true; + bufptr += MAX_L10N_DATA; if (strftime_l(bufptr, MAX_L10N_DATA, "%B", timeinfo, locale) <= 0) strftimefail = true; bufptr += MAX_L10N_DATA; + if (strftime_l(bufptr, MAX_L10N_DATA, "%OB", timeinfo, locale) <= 0) + strftimefail = true; + bufptr += MAX_L10N_DATA; } #ifdef WIN32 @@ -822,11 +830,17 @@ cache_locale_time(void) { cache_single_string(&localized_abbrev_months[i], bufptr, encoding); bufptr += MAX_L10N_DATA; + cache_single_string(&localized_alt_abbrev_months[i], bufptr, encoding); + bufptr += MAX_L10N_DATA; cache_single_string(&localized_full_months[i], bufptr, encoding); bufptr += MAX_L10N_DATA; + cache_single_string(&localized_alt_full_months[i], bufptr, encoding); + bufptr += MAX_L10N_DATA; } localized_abbrev_months[12] = NULL; + localized_alt_abbrev_months[12] = NULL; localized_full_months[12] = NULL; + localized_alt_full_months[12] = NULL; CurrentLCTimeValid = true; } diff --git a/src/include/utils/pg_locale.h b/src/include/utils/pg_locale.h index b74821fdfa9..a23876b5f43 100644 --- a/src/include/utils/pg_locale.h +++ b/src/include/utils/pg_locale.h @@ -42,7 +42,9 @@ extern PGDLLIMPORT int icu_validation_level; extern PGDLLIMPORT char *localized_abbrev_days[]; extern PGDLLIMPORT char *localized_full_days[]; extern PGDLLIMPORT char *localized_abbrev_months[]; +extern PGDLLIMPORT char *localized_alt_abbrev_months[]; extern PGDLLIMPORT char *localized_full_months[]; +extern PGDLLIMPORT char *localized_alt_full_months[]; extern bool check_locale(int category, const char *locale, char **canonname); extern char *pg_perm_setlocale(int category, const char *locale); diff --git a/src/test/regress/expected/collate.linux.utf8.out b/src/test/regress/expected/collate.linux.utf8.out index e0a39e4c300..f4b0d60ea4c 100644 --- a/src/test/regress/expected/collate.linux.utf8.out +++ b/src/test/regress/expected/collate.linux.utf8.out @@ -463,7 +463,28 @@ SELECT to_char(date '2010-04-01', 'DD TMMON YYYY' COLLATE "tr_TR"); 01 NİS 2010 (1 row) +-- to_char +SET lc_time TO 'cs_CZ'; +SELECT to_char(date '2010-02-01', 'DD TMMONTH'); + to_char +---------- + 01 ÚNORA +(1 row) + +SELECT to_char(date '2010-02-01', 'TAMMONTH'); + to_char +--------- + ÚNOR +(1 row) + +SELECT to_char(date '2010-02-01', 'TAMMON'); + to_char +--------- + ÚNO +(1 row) + -- to_date +SET lc_time TO 'tr_TR'; SELECT to_date('01 ŞUB 2010', 'DD TMMON YYYY'); to_date ------------ @@ -497,6 +518,25 @@ SELECT to_date('2010 01 araLık', 'YYYY DD TMMONTH'); 12-01-2010 (1 row) +SET lc_time TO 'cs_CZ'; +SELECT to_date('1 srpna 2010', 'DD TMMONTH YYYY'); + to_date +------------ + 08-01-2010 +(1 row) + +SELECT to_date('1 srp 2010', 'DD TAMMON YYYY'); + to_date +------------ + 08-01-2010 +(1 row) + +SELECT to_date('1 srpen 2010', 'DD TAMMONTH YYYY'); + to_date +------------ + 08-01-2010 +(1 row) + -- backwards parsing CREATE VIEW collview1 AS SELECT * FROM collate_test1 WHERE b COLLATE "C" >= 'bbc'; CREATE VIEW collview2 AS SELECT a, b FROM collate_test1 ORDER BY b COLLATE "C"; diff --git a/src/test/regress/sql/collate.linux.utf8.sql b/src/test/regress/sql/collate.linux.utf8.sql index 6d726ee9c99..544679fede5 100644 --- a/src/test/regress/sql/collate.linux.utf8.sql +++ b/src/test/regress/sql/collate.linux.utf8.sql @@ -182,7 +182,15 @@ SELECT to_char(date '2010-02-01', 'DD TMMON YYYY' COLLATE "tr_TR"); SELECT to_char(date '2010-04-01', 'DD TMMON YYYY'); SELECT to_char(date '2010-04-01', 'DD TMMON YYYY' COLLATE "tr_TR"); +-- to_char +SET lc_time TO 'cs_CZ'; + +SELECT to_char(date '2010-02-01', 'DD TMMONTH'); +SELECT to_char(date '2010-02-01', 'TAMMONTH'); +SELECT to_char(date '2010-02-01', 'TAMMON'); + -- to_date +SET lc_time TO 'tr_TR'; SELECT to_date('01 ŞUB 2010', 'DD TMMON YYYY'); SELECT to_date('01 Şub 2010', 'DD TMMON YYYY'); @@ -192,6 +200,12 @@ SELECT to_date('01 Aralık 2010', 'DD TMMONTH YYYY'); SELECT to_date('01 aralık 2010', 'DD TMMONTH YYYY'); SELECT to_date('2010 01 araLık', 'YYYY DD TMMONTH'); +SET lc_time TO 'cs_CZ'; + +SELECT to_date('1 srpna 2010', 'DD TMMONTH YYYY'); +SELECT to_date('1 srp 2010', 'DD TAMMON YYYY'); +SELECT to_date('1 srpen 2010', 'DD TAMMONTH YYYY'); + -- backwards parsing CREATE VIEW collview1 AS SELECT * FROM collate_test1 WHERE b COLLATE "C" >= 'bbc'; -- 2.55.0
^ permalink raw reply [nested|flat] 18+ messages in thread

* Re: missing possibility to use alternative translated month names in to_char function
@ 2026-08-21 16:56  Bernd Reiß <bd_reiss@gmx.at>
  parent: Pavel Stehule <pavel.stehule@gmail.com>
  0 siblings, 2 replies; 18+ messages in thread

From: Bernd Reiß @ 2026-08-21 16:56 UTC (permalink / raw)
  To: Pavel Stehule <pavel.stehule@gmail.com>; +Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>

Hi Pavel,

On 8/18/26 8:47 PM, Pavel Stehule wrote:
> Hi
> 
> so 15. 8. 2026 v 14:03 odesílatel Bernd Reiß <bd_reiss@gmx.at <mailto:bd_reiss@gmx.at>> napsal:
> 
>     Hi again,
> 
>     thanks for the updated patch.
>     > TAMMON is not implemented, because glibc doesn't provide an
>     > alternative form for abbreviated month names.
>     > It is a question if it is better to raise an error, return a non
>     > alternative name or just ignore this flag. I have not strong
>     > opinion about this. Inside DCH_to_char the prefix TM is ignored when
>     > it is not used. So I did the same.
>     The Locale standard actually mentions abbreviated alternative month
>     names as
>     "ab_alt_mon" (see [1]). I tested this by setting your TAMMONTH strftime
>     call to '%Ob'.
>     If we set the locale to Russian and call the function for May this
>     actually returns
>     an abbreviated version of the month name:
> 
>     Breakpoint 1, cache_locale_time () at pg_locale.c:772
>     772           if (strftime_l(bufptr, MAX_L10N_DATA, "%Ob", timeinfo,
>     locale) <= 0)
>     (gdb) n
>     774                     bufptr += MAX_L10N_DATA;
>     (gdb) print bufptr
>     $4 = 0x7ffde4554630 "май"
> 
>     Compared to the TMMON form of May in Russian this actually makes a
>     difference:
> 
>     postgres=# set lc_time='ru_RU.UTF8';
>     SET
>     postgres=# select to_char('2026-05-01'::date, 'TMMON');
>       to_char
>     ---------
>       МАЯ
>     (1 row)
> 
>     postgres=# select to_char('2026-05-01'::date, 'TAMMONTH');
>       to_char
>     ---------
>       МАЙ
>     (1 row)
> 
>     Again, TAMMONTH uses %Ob here. So I would argue for implementing the
>     abbreviated
>     forms too.
> 
> 
> I implemented it - please check

LGTM. I compiled it and it works as expected. I also like the introduction of 
the get_localized_*_months functions. However, this leads to suffix_len being 
declared and set but never used in the DCH_MONTH, DCH_Month, and DCH_month 
cases (as well as for the abbreviated equivalents) in DCH_from_char. Passing 
NULL and guarding in the functions would be an option to avoid this. However, 
I don't feel strongly about this.

In DCH_to_char I think you forgot to refactor this if statement for the 
MON/Mon/mon cases?

          if (strlen(str) <= (n->key->len + TM_SUFFIX_LEN) * DCH_MAX_ITEM_SIZ)
            strcpy(s, str);   

> 
> Please check updated patch
> 

With the if statements cleaned up this is a +1 for Ready for Committer from me.

Best
Bernd





^ permalink  raw  reply  [nested|flat] 18+ messages in thread

* Re: missing possibility to use alternative translated month names in to_char function
@ 2026-08-21 17:15  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Bernd Reiß <bd_reiss@gmx.at>
  1 sibling, 0 replies; 18+ messages in thread

From: Tom Lane @ 2026-08-21 17:15 UTC (permalink / raw)
  To: Bernd Reiß <bd_reiss@gmx.at>; +Cc: Pavel Stehule <pavel.stehule@gmail.com>; PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>

=?UTF-8?Q?Bernd_Rei=C3=9F?= <bd_reiss@gmx.at> writes:
> With the if statements cleaned up this is a +1 for Ready for Committer from me.

I have no opinion about the merits of this patch, but I am
pretty sure it needs a rebase after 03d255463.  (The cfbot
doesn't seem to have noticed that yet.)

			regards, tom lane






^ permalink  raw  reply  [nested|flat] 18+ messages in thread

* Re: missing possibility to use alternative translated month names in to_char function
@ 2026-08-21 22:17  Haibo Yan <tristan.yim@gmail.com>
  parent: Pavel Stehule <pavel.stehule@gmail.com>
  1 sibling, 1 reply; 18+ messages in thread

From: Haibo Yan @ 2026-08-21 22:17 UTC (permalink / raw)
  To: Pavel Stehule <pavel.stehule@gmail.com>; +Cc: Bernd Reiß <bd_reiss@gmx.at>; PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>

On Wed, Aug 12, 2026 at 9:47 PM Pavel Stehule <pavel.stehule@gmail.com> wrote:
>
> Hi
>
> st 12. 8. 2026 v 23:51 odesílatel Bernd Reiß <bd_reiss@gmx.at> napsal:
>>
>> Hi Pavel,
>>
>> I've looked into your patch and provide the review below.
>>
>> Threads I found touching TMMONTH + glibc:
>> https://www.postgresql.org/message-id/CALSKcLS3Zi4o0Ak5pNOheqmAiKWcez%2B%2BqwKvyPccvOz2v62QZQ%40mail...
>> (Russian)
>> https://www.postgresql.org/message-id/14717914.JAiOoc7IO7%40utklippan
>>
>> I did not come across a prior thread proposing an implementation of what
>> this patch does. Worth noting that in the utklippan thread above, Tom Lane
>> suggested that a new format code or modifier would be the palatable way to
>> address a similar problem.
>>
>> Contents & Purpose
>> ==================
>> This patch gives users control over the case (genitive vs. nominative)
>> to use when pulling localized month names from  glibc via the function
>> to_char(). The author proposes to add a TAMMONTH option for formatting
>> dates.
>>
>> Intended behaviour: TMMONTH uses the genitive form (if applicable to the
>> language; equivalent to %B) while TAMMONTH uses the nominative
>> (equivalent to %OB).
>>
>> The patch contains regression test cases. It also adds a corresponding
>> entry in the documentation.
>>
>> Initial Run
>> ===========
>> The patch applies cleanly to HEAD. The regression tests all pass
>> successfully against the new patch, but fail against pre-patched HEAD,
>> so the test cases are sane and do cover the new behavior.
>>
>> Manual Testing
>> ==============
>> The provided examples all work fine. However, I realized that the
>> shortened form TAMMON falls back to English instead of honouring
>> lc_time:
>>
>> postgres=# set lc_time to 'de_DE.UTF-8';
>> SET
>> postgres=# SELECT to_char(date '2026-03-01'::date, 'DD TMMON');
>> SELECT to_char(date '2026-03-01'::date, 'DD TAMMON');
>>   to_char
>> ---------
>>   01 MÄR
>> (1 row)
>>
>>   to_char
>> ---------
>>   01 MAR
>> (1 row)
>>
>> It looks like only the full-month cases (DCH_MONTH/Month/month) were
>> wired up for
>> TAM; the abbreviated cases (DCH_MON/Mon/mon) still test IS_SUFFIX_TM
>> only, so TAM
>> silently drops to the default English abbreviation. I'd expect TAMMON to
>> stay
>> localized.
>
>
> TAMMON is not implemented, because glibc doesn't provide an alternative form for abbreviated month names.
> It is a question if it is better to raise an error, return a non alternative name or just ignore this flag. I have not strong
> opinion about this. Inside DCH_to_char the prefix TM is ignored when it is not used. So I did the same.
>
> But I can imagine using localized abbreviation. It is possible for the Czech language - but I have not idea if it is true for other languages.
>
>>
>>
>> Code Review
>> ===========
>> I am not sure if this condition can be ever true:
>>
>> + if (IS_SUFFIX_TM(n->suffix) && IS_SUFFIX_TAM(n->suffix))
>>
>> In case this is not possible the subsequent error message will never be
>> thrown and the whole block is dead code.
>>
>> However, if there is a reason for this check, it would be nice to
>> have a comment mention it.
>
>
> Yes, I badly expected that prefixes could be mixed. I checked the code, and this is not possible, so I removed this check
>
>
>>
>>
>> One thing I am not entirely sure about is this line:
>>
>> + if (strftime_l(bufptr, MAX_L10N_DATA, "%OB", timeinfo, locale) <= 0)
>> +     strftimefail = true;
>>
>> As far as I checked %OB is not supported on Windows:
>>
>> https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/strftime-wcsftime-strftime-l-wcsft...
>>
>> I was, however, not able to confirm this on a Windows machine right now.
>> I might be able to do so on the weekend.
>>
>> However, the same problem exists with older glibc versions not supporting
>> %OB. As far as I understand strftime_l this will lead to it returning 0 and
>> therefore setting strftimefail to true always. Since this if statement
>> is evaluated
>> unconditionally I expect this to also influence the behaviour of TM.
>
>
> I am afraid about this case too, and I expect maybe some fallback mode there. But because
> I have not a Window machine or some machine with older glibc I decided to don't touch it
> for this moment.
>
> glibc older than 2.28 doesn't support %OB. On the second hand the result of %B is probably
> equal to expected result %B.
>
>>
>> Nitpicking & Conclusion
>> =======================
>> I feel like the documentation could explicitly mention the difference
>> between TMMONTH and TAMMONTH (i.e., mentioning genitive and nominative
>> like the Locale docs you mentioned do). I also think it would be
>> beneficial to
>> mention that this linguistic detail is specific to certain languages.
>
>
> please, if you can write this part of the doc. My English is not good enough to write well about these linguistic details.
> It is a problem primarily for slavic languages - like Czech or Russian - but maybe it can be a wide problem.
>
>>
>> Furthermore, in general I feel like the code could have more comments.
>> The single comment /* TAM suffix - localized alternative month name */
>> I would rather put outside the if-else block and set TAM directly in
>> relation
>> to TM there.
>>
>> All in all, this topic seems to have been a pain point for many people
>> as the discussion threads mentioned in the beginning attest. The patch
>> offers a solution to make glibc behaviour more predictable for users.
>> I see a very real use case here.
>
>
> Thank you very much for this immediate review
>
> Regards
>
> Pavel
>
>>
>> Best
>> Bernd
>>
>> On 12/08/2026 09:13, Pavel Stehule wrote:
>> > Hi
>> >
>> > út 11. 8. 2026 v 17:14 odesílatel Pavel Stehule
>> > <pavel.stehule@gmail.com> napsal:
>> >
>> >
>> >
>> >     út 11. 8. 2026 v 17:06 odesílatel Pavel Stehule
>> >     <pavel.stehule@gmail.com> napsal:
>> >
>> >         Hi
>> >
>> >         My customer reported an interesting issue. He needs translated
>> >         month name, and then he use
>> >         to_char(current_date, 'tmmonth');
>> >
>> >         Unfortunately, glibc returns nouns in the genitive case
>> >         instead of the nominative case.
>> >
>> >         This is a glibc feature from the 2.28 release. Genitive case
>> >         makes sense, when the result holds a day, but without it, it
>> >         is messy.
>> >
>> >         glibc has alternative month names, that can be taken by usage
>> >         placeholder '%OB'  of function strftime.
>> >         https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/V1_chap07.html
>> >         - see alt_mon.
>> >
>> >         Can we enhance prefixes (maybe tmo) to be possible to use
>> >         alternative names?
>> >
>> >
>> >     example:
>> >
>> >     pavel@nemesis:~/src/orafce$ date +'%B'
>> >     srpna
>> >     pavel@nemesis:~/src/orafce$ date +'%OB'
>> >     srpen
>> >     pavel@nemesis:~/src/orafce$ LANG=C date +'%OB'
>> >     August
>> >
>> >
>> > attached patch that implements 'TAM' modifier for data/timestamp
>> > formatting
>> >
>> > Regards
>> >
>> > Pavel
>> >
>> >
>> >         Regards
>> >
>> >         Pavel
>> >
>> >
>> >
>> >
>> >
>>

The use case makes sense to me, but I wonder a bit about the abstraction
boundary here.

TA exposes a fairly specific locale/grammatical distinction as part of the
to_char() format language. Is this something we want to make part of the
long-term SQL-facing API, rather than leaving context-sensitive localization
to the application/localization layer?

I’m not objecting to the patch, but if other locale-specific grammatical forms
come up later, would we expect to keep adding similar modifiers? Maybe this
particular distinction is common enough to justify it, but I think the i
intended boundary is worth considering.

I’m not a committer, so I may be missing some of the context here, and I’m
happy to defer to others who have more experience with this area.

Regards,
Haibo






^ permalink  raw  reply  [nested|flat] 18+ messages in thread

* Re: missing possibility to use alternative translated month names in to_char function
@ 2026-08-22 17:35  Pavel Stehule <pavel.stehule@gmail.com>
  parent: Haibo Yan <tristan.yim@gmail.com>
  0 siblings, 1 reply; 18+ messages in thread

From: Pavel Stehule @ 2026-08-22 17:35 UTC (permalink / raw)
  To: Haibo Yan <tristan.yim@gmail.com>; +Cc: Bernd Reiß <bd_reiss@gmx.at>; PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>

Hi


> >>
>
> The use case makes sense to me, but I wonder a bit about the abstraction
> boundary here.
>
> TA exposes a fairly specific locale/grammatical distinction as part of the
> to_char() format language. Is this something we want to make part of the
> long-term SQL-facing API, rather than leaving context-sensitive
> localization
> to the application/localization layer?
>
> I’m not objecting to the patch, but if other locale-specific grammatical
> forms
> come up later, would we expect to keep adding similar modifiers? Maybe this
> particular distinction is common enough to justify it, but I think the i
> intended boundary is worth considering.
>

The design is based on glibc locales - and they introduced just one
alternative form - no others.

I don't have a knowledge about other languages than Czech language, but
generally there are used only two forms for name of month

1. in combination with day - 2024-07-01 ... 1 července 2024 - this is
always combination day, month
2. Just the name of the month .. červenec - this form can be combined with
day, but can be used as an isolated name of month (in this case, only this
form).

Sometimes can be used third form (little bit obsolete) ... k 1 červenci
(this form is not supported by any library)

The form @2 was the historical default of all libraries that support
localized month names. glibc 2.28 z 2018 changed form to @1, and original
values were moved to alternative names.

libicu has a similar design (with different names) - it supports two forms
of month name - MMMM (month in year) and LLLL (stand-alone month in year).
No other form is supported.

https://unicode-org.github.io/icu/userguide/format_parse/datetime/#formatting-dates

Regards

Pavel


>
> I’m not a committer, so I may be missing some of the context here, and I’m
> happy to defer to others who have more experience with this area.
>
> Regards,
> Haibo
>

^ permalink  raw  reply  [nested|flat] 18+ messages in thread

* Re: missing possibility to use alternative translated month names in to_char function
@ 2026-08-23 05:30  Pavel Stehule <pavel.stehule@gmail.com>
  parent: Bernd Reiß <bd_reiss@gmx.at>
  1 sibling, 1 reply; 18+ messages in thread

From: Pavel Stehule @ 2026-08-23 05:30 UTC (permalink / raw)
  To: Bernd Reiß <bd_reiss@gmx.at>; +Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>

Hi

pá 21. 8. 2026 v 18:56 odesílatel Bernd Reiß <bd_reiss@gmx.at> napsal:

> Hi Pavel,
>
> On 8/18/26 8:47 PM, Pavel Stehule wrote:
> > Hi
> >
> > so 15. 8. 2026 v 14:03 odesílatel Bernd Reiß <bd_reiss@gmx.at <mailto:
> bd_reiss@gmx.at>> napsal:
> >
> >     Hi again,
> >
> >     thanks for the updated patch.
> >     > TAMMON is not implemented, because glibc doesn't provide an
> >     > alternative form for abbreviated month names.
> >     > It is a question if it is better to raise an error, return a non
> >     > alternative name or just ignore this flag. I have not strong
> >     > opinion about this. Inside DCH_to_char the prefix TM is ignored
> when
> >     > it is not used. So I did the same.
> >     The Locale standard actually mentions abbreviated alternative month
> >     names as
> >     "ab_alt_mon" (see [1]). I tested this by setting your TAMMONTH
> strftime
> >     call to '%Ob'.
> >     If we set the locale to Russian and call the function for May this
> >     actually returns
> >     an abbreviated version of the month name:
> >
> >     Breakpoint 1, cache_locale_time () at pg_locale.c:772
> >     772           if (strftime_l(bufptr, MAX_L10N_DATA, "%Ob", timeinfo,
> >     locale) <= 0)
> >     (gdb) n
> >     774                     bufptr += MAX_L10N_DATA;
> >     (gdb) print bufptr
> >     $4 = 0x7ffde4554630 "май"
> >
> >     Compared to the TMMON form of May in Russian this actually makes a
> >     difference:
> >
> >     postgres=# set lc_time='ru_RU.UTF8';
> >     SET
> >     postgres=# select to_char('2026-05-01'::date, 'TMMON');
> >       to_char
> >     ---------
> >       МАЯ
> >     (1 row)
> >
> >     postgres=# select to_char('2026-05-01'::date, 'TAMMONTH');
> >       to_char
> >     ---------
> >       МАЙ
> >     (1 row)
> >
> >     Again, TAMMONTH uses %Ob here. So I would argue for implementing the
> >     abbreviated
> >     forms too.
> >
> >
> > I implemented it - please check
>
> LGTM. I compiled it and it works as expected. I also like the introduction
> of
> the get_localized_*_months functions. However, this leads to suffix_len
> being
> declared and set but never used in the DCH_MONTH, DCH_Month, and DCH_month
> cases (as well as for the abbreviated equivalents) in DCH_from_char.
> Passing
> NULL and guarding in the functions would be an option to avoid this.
> However,
> I don't feel strongly about this.
>
> In DCH_to_char I think you forgot to refactor this if statement for the
> MON/Mon/mon cases?
>
>           if (strlen(str) <= (n->key->len + TM_SUFFIX_LEN) *
> DCH_MAX_ITEM_SIZ)
>             strcpy(s, str);
>

this code is removed in new version


>
> >
> > Please check updated patch
> >
>
> With the if statements cleaned up this is a +1 for Ready for Committer
> from me.
>

Regards

Pavel


>
> Best
> Bernd
>

Attachments:

0001-introduce-tam-modifier-for-date-timestamp-formatting.patch (text/x-patch, 15.9K) download From 50255dfd2e611f359c427565b70988b9a34f242b Mon Sep 17 00:00:00 2001 From: "okbob@github.com" <pavel.stehule@gmail.com> Date: Wed, 12 Aug 2026 07:03:28 +0200 Subject: [PATCH] introduce 'tam' modifier for date/timestamp formatting MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit glibc returns localized month names in the genitive case, but it also provides alternative month names in the nominative case. The TAM prefix allows you to retrieve this alternative name. example: SELECT to_char(date '2026-08-01', 'TMMONTH'); ┌─────────┐ │ to_char │ ╞═════════╡ │ SRPNA │ └─────────┘ (1 row) SELECT to_char(date '2026-08-01', 'TAMMONTH'); ┌─────────┐ │ to_char │ ╞═════════╡ │ SRPEN │ └─────────┘ (1 row) --- doc/src/sgml/func/func-formatting.sgml | 31 +++- src/backend/utils/adt/formatting.c | 142 ++++++++++++++---- src/backend/utils/adt/pg_locale.c | 16 +- src/include/utils/pg_locale.h | 2 + .../regress/expected/collate.linux.utf8.out | 40 +++++ src/test/regress/sql/collate.linux.utf8.sql | 14 ++ 6 files changed, 216 insertions(+), 29 deletions(-) diff --git a/doc/src/sgml/func/func-formatting.sgml b/doc/src/sgml/func/func-formatting.sgml index e4edaf4f42c..563587dc617 100644 --- a/doc/src/sgml/func/func-formatting.sgml +++ b/doc/src/sgml/func/func-formatting.sgml @@ -477,6 +477,12 @@ <xref linkend="guc-lc-time"/>)</entry> <entry><literal>TMMonth</literal></entry> </row> + <row> + <entry><literal>TAM</literal> prefix</entry> + <entry>translation alternative mode (use localized alternative month names based on + <xref linkend="guc-lc-time"/>; see usage notes)</entry> + <entry><literal>TAMMonth</literal></entry> + </row> <row> <entry><literal>SP</literal> suffix</entry> <entry>spell mode (not implemented)</entry> @@ -504,8 +510,29 @@ <listitem> <para> - <literal>TM</literal> suppresses trailing blanks whether or - not <literal>FM</literal> is specified. + <literal>TM</literal> and <literal>TAM</literal> suppress trailing + blanks whether or not <literal>FM</literal> is specified. + </para> + </listitem> + + <listitem> + <para> + <literal>TM</literal> and <literal>TAM</literal> both produce + localized month names according to <xref linkend="guc-lc-time"/>, + but they can differ for certain languages that inflect month names + (e.g., Slavic languages). In such languages <literal>TM</literal> + produces the form used together with a day number, which is often the + genitive case, while <literal>TAM</literal> produces the standalone + (nominative) form. For example, with <literal>lc_time</literal> set to + a Czech locale, <literal>to_char('2026-08-01'::date, 'TMMONTH')</literal> + returns <literal>SRPNA</literal> (genitive), whereas + <literal>to_char('2026-08-01'::date, 'TAMMONTH')</literal> returns + <literal>SRPEN</literal> (nominative). For languages that do not draw + this distinction, and for the <literal>C</literal> locale, the two + modifiers produce the same result. This distinction relies on + alternative month names being available from the underlying operating + system's locale support, so <literal>TAM</literal> may not be effective + on all platforms. </para> </listitem> diff --git a/src/backend/utils/adt/formatting.c b/src/backend/utils/adt/formatting.c index f87c0e53f56..2df90a7343d 100644 --- a/src/backend/utils/adt/formatting.c +++ b/src/backend/utils/adt/formatting.c @@ -547,6 +547,7 @@ do { \ #define DCH_SUFFIX_th 0x04 #define DCH_SUFFIX_SP 0x08 #define DCH_SUFFIX_TM 0x10 +#define DCH_SUFFIX_TAM 0x20 /* * Suffix tests @@ -588,16 +589,25 @@ IS_SUFFIX_TM(uint8 _s) return (_s & DCH_SUFFIX_TM); } +static inline bool +IS_SUFFIX_TAM(uint8 _s) +{ + return (_s & DCH_SUFFIX_TAM); +} + /* * Suffixes definition for DATE-TIME TO/FROM CHAR */ #define TM_SUFFIX_LEN 2 +#define TAM_SUFFIX_LEN 3 static const KeySuffix DCH_suff[] = { {"FM", 2, DCH_SUFFIX_FM, SUFFTYPE_PREFIX}, {"fm", 2, DCH_SUFFIX_FM, SUFFTYPE_PREFIX}, {"TM", TM_SUFFIX_LEN, DCH_SUFFIX_TM, SUFFTYPE_PREFIX}, + {"TAM", TAM_SUFFIX_LEN, DCH_SUFFIX_TAM, SUFFTYPE_PREFIX}, {"tm", 2, DCH_SUFFIX_TM, SUFFTYPE_PREFIX}, + {"tam", 3, DCH_SUFFIX_TAM, SUFFTYPE_PREFIX}, {"TH", 2, DCH_SUFFIX_TH, SUFFTYPE_POSTFIX}, {"th", 2, DCH_SUFFIX_th, SUFFTYPE_POSTFIX}, {"SP", 2, DCH_SUFFIX_SP, SUFFTYPE_POSTFIX}, @@ -2581,6 +2591,44 @@ from_char_seq_search(int *dest, const char **src, const char *const *array, return true; } +/* + * Allow to choose localized names or alternative localized names by + * usage prefix TM or TAM. Simple code, just reduction of repeated code. + */ +static char ** +get_localized_abbrev_months(uint8 suffix) +{ + if (IS_SUFFIX_TM(suffix)) + { + return localized_abbrev_months; + } + else if (IS_SUFFIX_TAM(suffix)) + { + return localized_alt_abbrev_months; + } + else + { + return NULL; + } +} + +static char ** +get_localized_full_months(uint8 suffix) +{ + if (IS_SUFFIX_TM(suffix)) + { + return localized_full_months; + } + else if (IS_SUFFIX_TAM(suffix)) + { + return localized_alt_full_months; + } + else + { + return NULL; + } +} + /* * Process a TmToChar struct as denoted by a list of FormatNodes. * The formatted data is appended to 'out'. @@ -2769,8 +2817,13 @@ DCH_to_char(const FormatNode *node, bool is_interval, Oid collid, INVALID_FOR_INTERVAL; if (!tm->tm_mon) break; - if (IS_SUFFIX_TM(n->suffix)) - DCH_EMITS(str_toupper_z(localized_full_months[tm->tm_mon - 1], collid)); + if (IS_SUFFIX_TM(n->suffix) || IS_SUFFIX_TAM(n->suffix)) + { + char **localized_months; + + localized_months = get_localized_full_months(n->suffix); + DCH_EMITS(str_toupper_z(localized_months[tm->tm_mon - 1], collid)); + } else DCH_EMITF("%*s", IS_SUFFIX_FM(n->suffix) ? 0 : -9, asc_toupper_z(months_full[tm->tm_mon - 1])); @@ -2779,8 +2832,13 @@ DCH_to_char(const FormatNode *node, bool is_interval, Oid collid, INVALID_FOR_INTERVAL; if (!tm->tm_mon) break; - if (IS_SUFFIX_TM(n->suffix)) - DCH_EMITS(str_initcap_z(localized_full_months[tm->tm_mon - 1], collid)); + if (IS_SUFFIX_TM(n->suffix) || IS_SUFFIX_TAM(n->suffix)) + { + char **localized_months; + + localized_months = get_localized_full_months(n->suffix); + DCH_EMITS(str_initcap_z(localized_months[tm->tm_mon - 1], collid)); + } else DCH_EMITF("%*s", IS_SUFFIX_FM(n->suffix) ? 0 : -9, months_full[tm->tm_mon - 1]); @@ -2789,8 +2847,13 @@ DCH_to_char(const FormatNode *node, bool is_interval, Oid collid, INVALID_FOR_INTERVAL; if (!tm->tm_mon) break; - if (IS_SUFFIX_TM(n->suffix)) - DCH_EMITS(str_tolower_z(localized_full_months[tm->tm_mon - 1], collid)); + if (IS_SUFFIX_TM(n->suffix) || IS_SUFFIX_TAM(n->suffix)) + { + char **localized_months; + + localized_months = get_localized_full_months(n->suffix); + DCH_EMITS(str_tolower_z(localized_months[tm->tm_mon - 1], collid)); + } else DCH_EMITF("%*s", IS_SUFFIX_FM(n->suffix) ? 0 : -9, asc_tolower_z(months_full[tm->tm_mon - 1])); @@ -2799,8 +2862,13 @@ DCH_to_char(const FormatNode *node, bool is_interval, Oid collid, INVALID_FOR_INTERVAL; if (!tm->tm_mon) break; - if (IS_SUFFIX_TM(n->suffix)) - DCH_EMITS(str_toupper_z(localized_abbrev_months[tm->tm_mon - 1], collid)); + if (IS_SUFFIX_TM(n->suffix) || IS_SUFFIX_TAM(n->suffix)) + { + char **localized_months; + + localized_months = get_localized_abbrev_months(n->suffix); + DCH_EMITS(str_toupper_z(localized_months[tm->tm_mon - 1], collid)); + } else DCH_EMITS(asc_toupper_z(months[tm->tm_mon - 1])); break; @@ -2808,8 +2876,13 @@ DCH_to_char(const FormatNode *node, bool is_interval, Oid collid, INVALID_FOR_INTERVAL; if (!tm->tm_mon) break; - if (IS_SUFFIX_TM(n->suffix)) - DCH_EMITS(str_initcap_z(localized_abbrev_months[tm->tm_mon - 1], collid)); + if (IS_SUFFIX_TM(n->suffix) || IS_SUFFIX_TAM(n->suffix)) + { + char **localized_months; + + localized_months = get_localized_abbrev_months(n->suffix); + DCH_EMITS(str_initcap_z(localized_months[tm->tm_mon - 1], collid)); + } else DCH_EMITS(months[tm->tm_mon - 1]); break; @@ -2817,8 +2890,13 @@ DCH_to_char(const FormatNode *node, bool is_interval, Oid collid, INVALID_FOR_INTERVAL; if (!tm->tm_mon) break; - if (IS_SUFFIX_TM(n->suffix)) - DCH_EMITS(str_tolower_z(localized_abbrev_months[tm->tm_mon - 1], collid)); + if (IS_SUFFIX_TM(n->suffix) || IS_SUFFIX_TAM(n->suffix)) + { + char **localized_months; + + localized_months = get_localized_abbrev_months(n->suffix); + DCH_EMITS(str_tolower_z(localized_months[tm->tm_mon - 1], collid)); + } else DCH_EMITS(asc_tolower_z(months[tm->tm_mon - 1])); break; @@ -3413,24 +3491,36 @@ DCH_from_char(FormatNode *node, const char *in, TmFromChar *out, case DCH_MONTH: case DCH_Month: case DCH_month: - if (!from_char_seq_search(&value, &s, months_full, - IS_SUFFIX_TM(n->suffix) ? localized_full_months : NULL, - collid, - n, escontext)) - return; - if (!from_char_set_int(&out->mm, value + 1, n, escontext)) - return; + { + char **localized_months; + + localized_months = get_localized_full_months(n->suffix); + + if (!from_char_seq_search(&value, &s, months_full, + localized_months, + collid, + n, escontext)) + return; + if (!from_char_set_int(&out->mm, value + 1, n, escontext)) + return; + } break; case DCH_MON: case DCH_Mon: case DCH_mon: - if (!from_char_seq_search(&value, &s, months, - IS_SUFFIX_TM(n->suffix) ? localized_abbrev_months : NULL, - collid, - n, escontext)) - return; - if (!from_char_set_int(&out->mm, value + 1, n, escontext)) - return; + { + char **localized_months; + + localized_months = get_localized_abbrev_months(n->suffix); + + if (!from_char_seq_search(&value, &s, months, + localized_months, + collid, + n, escontext)) + return; + if (!from_char_set_int(&out->mm, value + 1, n, escontext)) + return; + } break; case DCH_MM: if (from_char_parse_int(&out->mm, &s, n, escontext) < 0) diff --git a/src/backend/utils/adt/pg_locale.c b/src/backend/utils/adt/pg_locale.c index 4f0d0ca5057..ebfa17f292b 100644 --- a/src/backend/utils/adt/pg_locale.c +++ b/src/backend/utils/adt/pg_locale.c @@ -101,7 +101,9 @@ int icu_validation_level = WARNING; char *localized_abbrev_days[7 + 1]; char *localized_full_days[7 + 1]; char *localized_abbrev_months[12 + 1]; +char *localized_alt_abbrev_months[12 + 1]; char *localized_full_months[12 + 1]; +char *localized_alt_full_months[12 + 1]; static pg_locale_t default_locale = NULL; @@ -701,7 +703,7 @@ cache_single_string(char **dst, const char *src, int encoding) void cache_locale_time(void) { - char buf[(2 * 7 + 2 * 12) * MAX_L10N_DATA]; + char buf[(2 * 7 + 4 * 12) * MAX_L10N_DATA]; char *bufptr; time_t timenow; struct tm *timeinfo; @@ -765,9 +767,15 @@ cache_locale_time(void) if (strftime_l(bufptr, MAX_L10N_DATA, "%b", timeinfo, locale) <= 0) strftimefail = true; bufptr += MAX_L10N_DATA; + if (strftime_l(bufptr, MAX_L10N_DATA, "%Ob", timeinfo, locale) <= 0) + strftimefail = true; + bufptr += MAX_L10N_DATA; if (strftime_l(bufptr, MAX_L10N_DATA, "%B", timeinfo, locale) <= 0) strftimefail = true; bufptr += MAX_L10N_DATA; + if (strftime_l(bufptr, MAX_L10N_DATA, "%OB", timeinfo, locale) <= 0) + strftimefail = true; + bufptr += MAX_L10N_DATA; } #ifdef WIN32 @@ -822,11 +830,17 @@ cache_locale_time(void) { cache_single_string(&localized_abbrev_months[i], bufptr, encoding); bufptr += MAX_L10N_DATA; + cache_single_string(&localized_alt_abbrev_months[i], bufptr, encoding); + bufptr += MAX_L10N_DATA; cache_single_string(&localized_full_months[i], bufptr, encoding); bufptr += MAX_L10N_DATA; + cache_single_string(&localized_alt_full_months[i], bufptr, encoding); + bufptr += MAX_L10N_DATA; } localized_abbrev_months[12] = NULL; + localized_alt_abbrev_months[12] = NULL; localized_full_months[12] = NULL; + localized_alt_full_months[12] = NULL; CurrentLCTimeValid = true; } diff --git a/src/include/utils/pg_locale.h b/src/include/utils/pg_locale.h index fcd508f5dd6..57100d668d0 100644 --- a/src/include/utils/pg_locale.h +++ b/src/include/utils/pg_locale.h @@ -42,7 +42,9 @@ extern PGDLLIMPORT int icu_validation_level; extern PGDLLIMPORT char *localized_abbrev_days[]; extern PGDLLIMPORT char *localized_full_days[]; extern PGDLLIMPORT char *localized_abbrev_months[]; +extern PGDLLIMPORT char *localized_alt_abbrev_months[]; extern PGDLLIMPORT char *localized_full_months[]; +extern PGDLLIMPORT char *localized_alt_full_months[]; extern bool check_locale(int category, const char *locale, char **canonname); extern char *pg_perm_setlocale(int category, const char *locale); diff --git a/src/test/regress/expected/collate.linux.utf8.out b/src/test/regress/expected/collate.linux.utf8.out index e0a39e4c300..f4b0d60ea4c 100644 --- a/src/test/regress/expected/collate.linux.utf8.out +++ b/src/test/regress/expected/collate.linux.utf8.out @@ -463,7 +463,28 @@ SELECT to_char(date '2010-04-01', 'DD TMMON YYYY' COLLATE "tr_TR"); 01 NİS 2010 (1 row) +-- to_char +SET lc_time TO 'cs_CZ'; +SELECT to_char(date '2010-02-01', 'DD TMMONTH'); + to_char +---------- + 01 ÚNORA +(1 row) + +SELECT to_char(date '2010-02-01', 'TAMMONTH'); + to_char +--------- + ÚNOR +(1 row) + +SELECT to_char(date '2010-02-01', 'TAMMON'); + to_char +--------- + ÚNO +(1 row) + -- to_date +SET lc_time TO 'tr_TR'; SELECT to_date('01 ŞUB 2010', 'DD TMMON YYYY'); to_date ------------ @@ -497,6 +518,25 @@ SELECT to_date('2010 01 araLık', 'YYYY DD TMMONTH'); 12-01-2010 (1 row) +SET lc_time TO 'cs_CZ'; +SELECT to_date('1 srpna 2010', 'DD TMMONTH YYYY'); + to_date +------------ + 08-01-2010 +(1 row) + +SELECT to_date('1 srp 2010', 'DD TAMMON YYYY'); + to_date +------------ + 08-01-2010 +(1 row) + +SELECT to_date('1 srpen 2010', 'DD TAMMONTH YYYY'); + to_date +------------ + 08-01-2010 +(1 row) + -- backwards parsing CREATE VIEW collview1 AS SELECT * FROM collate_test1 WHERE b COLLATE "C" >= 'bbc'; CREATE VIEW collview2 AS SELECT a, b FROM collate_test1 ORDER BY b COLLATE "C"; diff --git a/src/test/regress/sql/collate.linux.utf8.sql b/src/test/regress/sql/collate.linux.utf8.sql index 6d726ee9c99..544679fede5 100644 --- a/src/test/regress/sql/collate.linux.utf8.sql +++ b/src/test/regress/sql/collate.linux.utf8.sql @@ -182,7 +182,15 @@ SELECT to_char(date '2010-02-01', 'DD TMMON YYYY' COLLATE "tr_TR"); SELECT to_char(date '2010-04-01', 'DD TMMON YYYY'); SELECT to_char(date '2010-04-01', 'DD TMMON YYYY' COLLATE "tr_TR"); +-- to_char +SET lc_time TO 'cs_CZ'; + +SELECT to_char(date '2010-02-01', 'DD TMMONTH'); +SELECT to_char(date '2010-02-01', 'TAMMONTH'); +SELECT to_char(date '2010-02-01', 'TAMMON'); + -- to_date +SET lc_time TO 'tr_TR'; SELECT to_date('01 ŞUB 2010', 'DD TMMON YYYY'); SELECT to_date('01 Şub 2010', 'DD TMMON YYYY'); @@ -192,6 +200,12 @@ SELECT to_date('01 Aralık 2010', 'DD TMMONTH YYYY'); SELECT to_date('01 aralık 2010', 'DD TMMONTH YYYY'); SELECT to_date('2010 01 araLık', 'YYYY DD TMMONTH'); +SET lc_time TO 'cs_CZ'; + +SELECT to_date('1 srpna 2010', 'DD TMMONTH YYYY'); +SELECT to_date('1 srp 2010', 'DD TAMMON YYYY'); +SELECT to_date('1 srpen 2010', 'DD TAMMONTH YYYY'); + -- backwards parsing CREATE VIEW collview1 AS SELECT * FROM collate_test1 WHERE b COLLATE "C" >= 'bbc'; -- 2.55.0
^ permalink raw reply [nested|flat] 18+ messages in thread

* Re: missing possibility to use alternative translated month names in to_char function
@ 2026-08-23 06:31  Bernd Reiß <bd_reiss@gmx.at>
  parent: Pavel Stehule <pavel.stehule@gmail.com>
  0 siblings, 1 reply; 18+ messages in thread

From: Bernd Reiß @ 2026-08-23 06:31 UTC (permalink / raw)
  To: Pavel Stehule <pavel.stehule@gmail.com>; +Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>

Hi,

On 23/08/2026 07:30, Pavel Stehule wrote:
> Hi
>
> pá 21. 8. 2026 v 18:56 odesílatel Bernd Reiß <bd_reiss@gmx.at> napsal:
>
>     Hi Pavel,
>
>     On 8/18/26 8:47 PM, Pavel Stehule wrote:
>     > Hi
>     >
>     > so 15. 8. 2026 v 14:03 odesílatel Bernd Reiß <bd_reiss@gmx.at
>     <mailto:bd_reiss@gmx.at>> napsal:
>     >
>     >     Hi again,
>     >
>     >     thanks for the updated patch.
>     >     > TAMMON is not implemented, because glibc doesn't provide an
>     >     > alternative form for abbreviated month names.
>     >     > It is a question if it is better to raise an error, return
>     a non
>     >     > alternative name or just ignore this flag. I have not strong
>     >     > opinion about this. Inside DCH_to_char the prefix TM is
>     ignored when
>     >     > it is not used. So I did the same.
>     >     The Locale standard actually mentions abbreviated
>     alternative month
>     >     names as
>     >     "ab_alt_mon" (see [1]). I tested this by setting your
>     TAMMONTH strftime
>     >     call to '%Ob'.
>     >     If we set the locale to Russian and call the function for
>     May this
>     >     actually returns
>     >     an abbreviated version of the month name:
>     >
>     >     Breakpoint 1, cache_locale_time () at pg_locale.c:772
>     >     772           if (strftime_l(bufptr, MAX_L10N_DATA, "%Ob",
>     timeinfo,
>     >     locale) <= 0)
>     >     (gdb) n
>     >     774                     bufptr += MAX_L10N_DATA;
>     >     (gdb) print bufptr
>     >     $4 = 0x7ffde4554630 "май"
>     >
>     >     Compared to the TMMON form of May in Russian this actually
>     makes a
>     >     difference:
>     >
>     >     postgres=# set lc_time='ru_RU.UTF8';
>     >     SET
>     >     postgres=# select to_char('2026-05-01'::date, 'TMMON');
>     >       to_char
>     >     ---------
>     >       МАЯ
>     >     (1 row)
>     >
>     >     postgres=# select to_char('2026-05-01'::date, 'TAMMONTH');
>     >       to_char
>     >     ---------
>     >       МАЙ
>     >     (1 row)
>     >
>     >     Again, TAMMONTH uses %Ob here. So I would argue for
>     implementing the
>     >     abbreviated
>     >     forms too.
>     >
>     >
>     > I implemented it - please check
>
>     LGTM. I compiled it and it works as expected. I also like the
>     introduction of
>     the get_localized_*_months functions. However, this leads to
>     suffix_len being
>     declared and set but never used in the DCH_MONTH, DCH_Month, and
>     DCH_month
>     cases (as well as for the abbreviated equivalents) in
>     DCH_from_char. Passing
>     NULL and guarding in the functions would be an option to avoid
>     this. However,
>     I don't feel strongly about this.
>
>     In DCH_to_char I think you forgot to refactor this if statement
>     for the
>     MON/Mon/mon cases?
>
>               if (strlen(str) <= (n->key->len + TM_SUFFIX_LEN) *
>     DCH_MAX_ITEM_SIZ)
>                 strcpy(s, str);
>
>
> this code is removed in new version
>
>
>     >
>     > Please check updated patch
>     >
>
>     With the if statements cleaned up this is a +1 for Ready for
>     Committer from me.
>
>
> Regards
>
> Pavel

Patch applies cleanly now on HEAD. New changes LGTM. Compiles without 
problems and
regression tests are all green. I am moving this to Ready for Reviewer.

Best
Bernd






^ permalink  raw  reply  [nested|flat] 18+ messages in thread

* Re: missing possibility to use alternative translated month names in to_char function
@ 2026-08-23 10:31  Pavel Stehule <pavel.stehule@gmail.com>
  parent: Bernd Reiß <bd_reiss@gmx.at>
  0 siblings, 1 reply; 18+ messages in thread

From: Pavel Stehule @ 2026-08-23 10:31 UTC (permalink / raw)
  To: Bernd Reiß <bd_reiss@gmx.at>; +Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>

ne 23. 8. 2026 v 8:32 odesílatel Bernd Reiß <bd_reiss@gmx.at> napsal:

> Hi,
>
> On 23/08/2026 07:30, Pavel Stehule wrote:
> > Hi
> >
> > pá 21. 8. 2026 v 18:56 odesílatel Bernd Reiß <bd_reiss@gmx.at> napsal:
> >
> >     Hi Pavel,
> >
> >     On 8/18/26 8:47 PM, Pavel Stehule wrote:
> >     > Hi
> >     >
> >     > so 15. 8. 2026 v 14:03 odesílatel Bernd Reiß <bd_reiss@gmx.at
> >     <mailto:bd_reiss@gmx.at>> napsal:
> >     >
> >     >     Hi again,
> >     >
> >     >     thanks for the updated patch.
> >     >     > TAMMON is not implemented, because glibc doesn't provide an
> >     >     > alternative form for abbreviated month names.
> >     >     > It is a question if it is better to raise an error, return
> >     a non
> >     >     > alternative name or just ignore this flag. I have not strong
> >     >     > opinion about this. Inside DCH_to_char the prefix TM is
> >     ignored when
> >     >     > it is not used. So I did the same.
> >     >     The Locale standard actually mentions abbreviated
> >     alternative month
> >     >     names as
> >     >     "ab_alt_mon" (see [1]). I tested this by setting your
> >     TAMMONTH strftime
> >     >     call to '%Ob'.
> >     >     If we set the locale to Russian and call the function for
> >     May this
> >     >     actually returns
> >     >     an abbreviated version of the month name:
> >     >
> >     >     Breakpoint 1, cache_locale_time () at pg_locale.c:772
> >     >     772           if (strftime_l(bufptr, MAX_L10N_DATA, "%Ob",
> >     timeinfo,
> >     >     locale) <= 0)
> >     >     (gdb) n
> >     >     774                     bufptr += MAX_L10N_DATA;
> >     >     (gdb) print bufptr
> >     >     $4 = 0x7ffde4554630 "май"
> >     >
> >     >     Compared to the TMMON form of May in Russian this actually
> >     makes a
> >     >     difference:
> >     >
> >     >     postgres=# set lc_time='ru_RU.UTF8';
> >     >     SET
> >     >     postgres=# select to_char('2026-05-01'::date, 'TMMON');
> >     >       to_char
> >     >     ---------
> >     >       МАЯ
> >     >     (1 row)
> >     >
> >     >     postgres=# select to_char('2026-05-01'::date, 'TAMMONTH');
> >     >       to_char
> >     >     ---------
> >     >       МАЙ
> >     >     (1 row)
> >     >
> >     >     Again, TAMMONTH uses %Ob here. So I would argue for
> >     implementing the
> >     >     abbreviated
> >     >     forms too.
> >     >
> >     >
> >     > I implemented it - please check
> >
> >     LGTM. I compiled it and it works as expected. I also like the
> >     introduction of
> >     the get_localized_*_months functions. However, this leads to
> >     suffix_len being
> >     declared and set but never used in the DCH_MONTH, DCH_Month, and
> >     DCH_month
> >     cases (as well as for the abbreviated equivalents) in
> >     DCH_from_char. Passing
> >     NULL and guarding in the functions would be an option to avoid
> >     this. However,
> >     I don't feel strongly about this.
> >
> >     In DCH_to_char I think you forgot to refactor this if statement
> >     for the
> >     MON/Mon/mon cases?
> >
> >               if (strlen(str) <= (n->key->len + TM_SUFFIX_LEN) *
> >     DCH_MAX_ITEM_SIZ)
> >                 strcpy(s, str);
> >
> >
> > this code is removed in new version
> >
> >
> >     >
> >     > Please check updated patch
> >     >
> >
> >     With the if statements cleaned up this is a +1 for Ready for
> >     Committer from me.
> >
> >
> > Regards
> >
> > Pavel
>
> Patch applies cleanly now on HEAD. New changes LGTM. Compiles without
> problems and
> regression tests are all green. I am moving this to Ready for Reviewer.
>

you are a reviewer :-)

Pavel

>
> Best
> Bernd
>

^ permalink  raw  reply  [nested|flat] 18+ messages in thread

* Re: missing possibility to use alternative translated month names in to_char function
@ 2026-08-23 10:37  bd_reiss@gmx.at
  parent: Pavel Stehule <pavel.stehule@gmail.com>
  0 siblings, 1 reply; 18+ messages in thread

From: bd_reiss@gmx.at @ 2026-08-23 10:37 UTC (permalink / raw)
  To: Pavel Stehule <pavel.stehule@gmail.com>; +Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>

Ah, my bad. Meant to say Committer, of course :)

Bernd

Sent with Spark
On 23 Aug 2026 at 12:32 +0200, Pavel Stehule <pavel.stehule@gmail.com>, wrote:
>
>
> ne 23. 8. 2026 v 8:32 odesílatel Bernd Reiß <bd_reiss@gmx.at> napsal:
> > Hi,
> >
> > On 23/08/2026 07:30, Pavel Stehule wrote:
> > > Hi
> > >
> > > pá 21. 8. 2026 v 18:56 odesílatel Bernd Reiß <bd_reiss@gmx.at> napsal:
> > >
> > >     Hi Pavel,
> > >
> > >     On 8/18/26 8:47 PM, Pavel Stehule wrote:
> > >     > Hi
> > >     >
> > >     > so 15. 8. 2026 v 14:03 odesílatel Bernd Reiß <bd_reiss@gmx.at
> > >     <mailto:bd_reiss@gmx.at>> napsal:
> > >     >
> > >     >     Hi again,
> > >     >
> > >     >     thanks for the updated patch.
> > >     >     > TAMMON is not implemented, because glibc doesn't provide an
> > >     >     > alternative form for abbreviated month names.
> > >     >     > It is a question if it is better to raise an error, return
> > >     a non
> > >     >     > alternative name or just ignore this flag. I have not strong
> > >     >     > opinion about this. Inside DCH_to_char the prefix TM is
> > >     ignored when
> > >     >     > it is not used. So I did the same.
> > >     >     The Locale standard actually mentions abbreviated
> > >     alternative month
> > >     >     names as
> > >     >     "ab_alt_mon" (see [1]). I tested this by setting your
> > >     TAMMONTH strftime
> > >     >     call to '%Ob'.
> > >     >     If we set the locale to Russian and call the function for
> > >     May this
> > >     >     actually returns
> > >     >     an abbreviated version of the month name:
> > >     >
> > >     >     Breakpoint 1, cache_locale_time () at pg_locale.c:772
> > >     >     772           if (strftime_l(bufptr, MAX_L10N_DATA, "%Ob",
> > >     timeinfo,
> > >     >     locale) <= 0)
> > >     >     (gdb) n
> > >     >     774                     bufptr += MAX_L10N_DATA;
> > >     >     (gdb) print bufptr
> > >     >     $4 = 0x7ffde4554630 "май"
> > >     >
> > >     >     Compared to the TMMON form of May in Russian this actually
> > >     makes a
> > >     >     difference:
> > >     >
> > >     >     postgres=# set lc_time='ru_RU.UTF8';
> > >     >     SET
> > >     >     postgres=# select to_char('2026-05-01'::date, 'TMMON');
> > >     >       to_char
> > >     >     ---------
> > >     >       МАЯ
> > >     >     (1 row)
> > >     >
> > >     >     postgres=# select to_char('2026-05-01'::date, 'TAMMONTH');
> > >     >       to_char
> > >     >     ---------
> > >     >       МАЙ
> > >     >     (1 row)
> > >     >
> > >     >     Again, TAMMONTH uses %Ob here. So I would argue for
> > >     implementing the
> > >     >     abbreviated
> > >     >     forms too.
> > >     >
> > >     >
> > >     > I implemented it - please check
> > >
> > >     LGTM. I compiled it and it works as expected. I also like the
> > >     introduction of
> > >     the get_localized_*_months functions. However, this leads to
> > >     suffix_len being
> > >     declared and set but never used in the DCH_MONTH, DCH_Month, and
> > >     DCH_month
> > >     cases (as well as for the abbreviated equivalents) in
> > >     DCH_from_char. Passing
> > >     NULL and guarding in the functions would be an option to avoid
> > >     this. However,
> > >     I don't feel strongly about this.
> > >
> > >     In DCH_to_char I think you forgot to refactor this if statement
> > >     for the
> > >     MON/Mon/mon cases?
> > >
> > >               if (strlen(str) <= (n->key->len + TM_SUFFIX_LEN) *
> > >     DCH_MAX_ITEM_SIZ)
> > >                 strcpy(s, str);
> > >
> > >
> > > this code is removed in new version
> > >
> > >
> > >     >
> > >     > Please check updated patch
> > >     >
> > >
> > >     With the if statements cleaned up this is a +1 for Ready for
> > >     Committer from me.
> > >
> > >
> > > Regards
> > >
> > > Pavel
> >
> > Patch applies cleanly now on HEAD. New changes LGTM. Compiles without
> > problems and
> > regression tests are all green. I am moving this to Ready for Reviewer.
>
> you are a reviewer :-)
>
> Pavel
> >
> > Best
> > Bernd

^ permalink  raw  reply  [nested|flat] 18+ messages in thread

* Re: missing possibility to use alternative translated month names in to_char function
@ 2026-08-23 13:22  Pavel Stehule <pavel.stehule@gmail.com>
  parent: bd_reiss@gmx.at
  0 siblings, 0 replies; 18+ messages in thread

From: Pavel Stehule @ 2026-08-23 13:22 UTC (permalink / raw)
  To: bd_reiss@gmx.at; +Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>

ne 23. 8. 2026 v 12:37 odesílatel <bd_reiss@gmx.at> napsal:

> Ah, my bad. Meant to say Committer, of course :)
>

Thank you :)

Pavel


>
> Bernd
>
> Sent with Spark <https://sparkmailapp.com/source?from=signature;
> On 23 Aug 2026 at 12:32 +0200, Pavel Stehule <pavel.stehule@gmail.com>,
> wrote:
>
>
>
> ne 23. 8. 2026 v 8:32 odesílatel Bernd Reiß <bd_reiss@gmx.at> napsal:
>
>> Hi,
>>
>> On 23/08/2026 07:30, Pavel Stehule wrote:
>> > Hi
>> >
>> > pá 21. 8. 2026 v 18:56 odesílatel Bernd Reiß <bd_reiss@gmx.at> napsal:
>> >
>> >     Hi Pavel,
>> >
>> >     On 8/18/26 8:47 PM, Pavel Stehule wrote:
>> >     > Hi
>> >     >
>> >     > so 15. 8. 2026 v 14:03 odesílatel Bernd Reiß <bd_reiss@gmx.at
>> >     <mailto:bd_reiss@gmx.at>> napsal:
>> >     >
>> >     >     Hi again,
>> >     >
>> >     >     thanks for the updated patch.
>> >     >     > TAMMON is not implemented, because glibc doesn't provide an
>> >     >     > alternative form for abbreviated month names.
>> >     >     > It is a question if it is better to raise an error, return
>> >     a non
>> >     >     > alternative name or just ignore this flag. I have not strong
>> >     >     > opinion about this. Inside DCH_to_char the prefix TM is
>> >     ignored when
>> >     >     > it is not used. So I did the same.
>> >     >     The Locale standard actually mentions abbreviated
>> >     alternative month
>> >     >     names as
>> >     >     "ab_alt_mon" (see [1]). I tested this by setting your
>> >     TAMMONTH strftime
>> >     >     call to '%Ob'.
>> >     >     If we set the locale to Russian and call the function for
>> >     May this
>> >     >     actually returns
>> >     >     an abbreviated version of the month name:
>> >     >
>> >     >     Breakpoint 1, cache_locale_time () at pg_locale.c:772
>> >     >     772           if (strftime_l(bufptr, MAX_L10N_DATA, "%Ob",
>> >     timeinfo,
>> >     >     locale) <= 0)
>> >     >     (gdb) n
>> >     >     774                     bufptr += MAX_L10N_DATA;
>> >     >     (gdb) print bufptr
>> >     >     $4 = 0x7ffde4554630 "май"
>> >     >
>> >     >     Compared to the TMMON form of May in Russian this actually
>> >     makes a
>> >     >     difference:
>> >     >
>> >     >     postgres=# set lc_time='ru_RU.UTF8';
>> >     >     SET
>> >     >     postgres=# select to_char('2026-05-01'::date, 'TMMON');
>> >     >       to_char
>> >     >     ---------
>> >     >       МАЯ
>> >     >     (1 row)
>> >     >
>> >     >     postgres=# select to_char('2026-05-01'::date, 'TAMMONTH');
>> >     >       to_char
>> >     >     ---------
>> >     >       МАЙ
>> >     >     (1 row)
>> >     >
>> >     >     Again, TAMMONTH uses %Ob here. So I would argue for
>> >     implementing the
>> >     >     abbreviated
>> >     >     forms too.
>> >     >
>> >     >
>> >     > I implemented it - please check
>> >
>> >     LGTM. I compiled it and it works as expected. I also like the
>> >     introduction of
>> >     the get_localized_*_months functions. However, this leads to
>> >     suffix_len being
>> >     declared and set but never used in the DCH_MONTH, DCH_Month, and
>> >     DCH_month
>> >     cases (as well as for the abbreviated equivalents) in
>> >     DCH_from_char. Passing
>> >     NULL and guarding in the functions would be an option to avoid
>> >     this. However,
>> >     I don't feel strongly about this.
>> >
>> >     In DCH_to_char I think you forgot to refactor this if statement
>> >     for the
>> >     MON/Mon/mon cases?
>> >
>> >               if (strlen(str) <= (n->key->len + TM_SUFFIX_LEN) *
>> >     DCH_MAX_ITEM_SIZ)
>> >                 strcpy(s, str);
>> >
>> >
>> > this code is removed in new version
>> >
>> >
>> >     >
>> >     > Please check updated patch
>> >     >
>> >
>> >     With the if statements cleaned up this is a +1 for Ready for
>> >     Committer from me.
>> >
>> >
>> > Regards
>> >
>> > Pavel
>>
>> Patch applies cleanly now on HEAD. New changes LGTM. Compiles without
>> problems and
>> regression tests are all green. I am moving this to Ready for Reviewer.
>>
>
> you are a reviewer :-)
>
> Pavel
>
>>
>> Best
>> Bernd
>>
>

^ permalink  raw  reply  [nested|flat] 18+ messages in thread

* Re: missing possibility to use alternative translated month names in to_char function
@ 2026-08-24 17:46  Haibo Yan <tristan.yim@gmail.com>
  parent: Pavel Stehule <pavel.stehule@gmail.com>
  0 siblings, 1 reply; 18+ messages in thread

From: Haibo Yan @ 2026-08-24 17:46 UTC (permalink / raw)
  To: Pavel Stehule <pavel.stehule@gmail.com>; +Cc: Bernd Reiß <bd_reiss@gmx.at>; PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>

On Sat, Aug 22, 2026 at 10:36 AM Pavel Stehule <pavel.stehule@gmail.com> wrote:
>
> Hi
>
>>
>> >>
>>
>> The use case makes sense to me, but I wonder a bit about the abstraction
>> boundary here.
>>
>> TA exposes a fairly specific locale/grammatical distinction as part of the
>> to_char() format language. Is this something we want to make part of the
>> long-term SQL-facing API, rather than leaving context-sensitive localization
>> to the application/localization layer?
>>
>> I’m not objecting to the patch, but if other locale-specific grammatical forms
>> come up later, would we expect to keep adding similar modifiers? Maybe this
>> particular distinction is common enough to justify it, but I think the i
>> intended boundary is worth considering.
>
>
> The design is based on glibc locales - and they introduced just one alternative form - no others.
>
> I don't have a knowledge about other languages than Czech language, but generally there are used only two forms for name of month
>
> 1. in combination with day - 2024-07-01 ... 1 července 2024 - this is always combination day, month
> 2. Just the name of the month .. červenec - this form can be combined with day, but can be used as an isolated name of month (in this case, only this form).
>
> Sometimes can be used third form (little bit obsolete) ... k 1 červenci (this form is not supported by any library)
>
> The form @2 was the historical default of all libraries that support localized month names. glibc 2.28 z 2018 changed form to @1, and original values were moved to alternative names.
>
> libicu has a similar design (with different names) - it supports two forms of month name - MMMM (month in year) and LLLL (stand-alone month in year). No other form is supported.
>
> https://unicode-org.github.io/icu/userguide/format_parse/datetime/#formatting-dates
>

Thanks for the explanation. The comparison with ICU’s contextual vs.
stand-alone forms makes the scope much clearer to me.

Looking through the patch, one thing I was wondering about is the to_date()
side. The original problem is about choosing the representation produced by
to_char(), but TAM is also made part of the input parsing semantics.

For example, DD TAMMONTH YYYY searches the alternative localized month names,
while DD TMMONTH YYYY searches the regular localized names. Is TAM intended to
specify the grammatical form accepted on input as well, or is this distinction
primarily an output-formatting choice?

I don’t have a strong opinion either way, but it seems worth defining
explicitly since this becomes part of the format model too.

> Regards
>
> Pavel
>
>>
>>
>> I’m not a committer, so I may be missing some of the context here, and I’m
>> happy to defer to others who have more experience with this area.
>>
>> Regards,
>> Haibo





^ permalink  raw  reply  [nested|flat] 18+ messages in thread

* Re: missing possibility to use alternative translated month names in to_char function
@ 2026-08-24 18:42  Pavel Stehule <pavel.stehule@gmail.com>
  parent: Haibo Yan <tristan.yim@gmail.com>
  0 siblings, 0 replies; 18+ messages in thread

From: Pavel Stehule @ 2026-08-24 18:42 UTC (permalink / raw)
  To: Haibo Yan <tristan.yim@gmail.com>; +Cc: Bernd Reiß <bd_reiss@gmx.at>; PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>

po 24. 8. 2026 v 19:47 odesílatel Haibo Yan <tristan.yim@gmail.com> napsal:

> On Sat, Aug 22, 2026 at 10:36 AM Pavel Stehule <pavel.stehule@gmail.com>
> wrote:
> >
> > Hi
> >
> >>
> >> >>
> >>
> >> The use case makes sense to me, but I wonder a bit about the abstraction
> >> boundary here.
> >>
> >> TA exposes a fairly specific locale/grammatical distinction as part of
> the
> >> to_char() format language. Is this something we want to make part of the
> >> long-term SQL-facing API, rather than leaving context-sensitive
> localization
> >> to the application/localization layer?
> >>
> >> I’m not objecting to the patch, but if other locale-specific
> grammatical forms
> >> come up later, would we expect to keep adding similar modifiers? Maybe
> this
> >> particular distinction is common enough to justify it, but I think the i
> >> intended boundary is worth considering.
> >
> >
> > The design is based on glibc locales - and they introduced just one
> alternative form - no others.
> >
> > I don't have a knowledge about other languages than Czech language, but
> generally there are used only two forms for name of month
> >
> > 1. in combination with day - 2024-07-01 ... 1 července 2024 - this is
> always combination day, month
> > 2. Just the name of the month .. červenec - this form can be combined
> with day, but can be used as an isolated name of month (in this case, only
> this form).
> >
> > Sometimes can be used third form (little bit obsolete) ... k 1 červenci
> (this form is not supported by any library)
> >
> > The form @2 was the historical default of all libraries that support
> localized month names. glibc 2.28 z 2018 changed form to @1, and original
> values were moved to alternative names.
> >
> > libicu has a similar design (with different names) - it supports two
> forms of month name - MMMM (month in year) and LLLL (stand-alone month in
> year). No other form is supported.
> >
> >
> https://unicode-org.github.io/icu/userguide/format_parse/datetime/#formatting-dates
> >
>
> Thanks for the explanation. The comparison with ICU’s contextual vs.
> stand-alone forms makes the scope much clearer to me.
>
> Looking through the patch, one thing I was wondering about is the to_date()
> side. The original problem is about choosing the representation produced by
> to_char(), but TAM is also made part of the input parsing semantics.
>
> For example, DD TAMMONTH YYYY searches the alternative localized month
> names,
> while DD TMMONTH YYYY searches the regular localized names. Is TAM
> intended to
> specify the grammatical form accepted on input as well, or is this
> distinction
> primarily an output-formatting choice?
>

Current design is strict - same output, same input.

I can imagine a combination DD TMTAMMONTH - and this can be probably in
some situations wanted, but format parser doesn't allow combination of
prefixes. And if we accept alternative names when TM is used or localized
non alternative names when TAM is used, then it can be pretty messy. So
when TAM is used, then only alternative localized names can be accepted,
when TM, then only localized names can be accepted. Maybe in next versions
to_date will support soft errors and some combinations of formats, and this
can be ideal solution - like

to_date(val, 'DDTMMONTH', 'DDTMMONTH', 'DDMONTH', ...)

but this is another topic

Regards

Pavel


I don’t have a strong opinion either way, but it seems worth defining
> explicitly since this becomes part of the format model too.
>
> > Regards
> >
> > Pavel
> >
> >>
> >>
> >> I’m not a committer, so I may be missing some of the context here, and
> I’m
> >> happy to defer to others who have more experience with this area.
> >>
> >> Regards,
> >> Haibo
>

^ permalink  raw  reply  [nested|flat] 18+ messages in thread


end of thread, other threads:[~2026-08-24 18:42 UTC | newest]

Thread overview: 18+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-08-11 15:06 missing possibility to use alternative translated month names in to_char function Pavel Stehule <pavel.stehule@gmail.com>
2026-08-11 15:14 ` Pavel Stehule <pavel.stehule@gmail.com>
2026-08-12 07:13   ` Pavel Stehule <pavel.stehule@gmail.com>
2026-08-12 21:51     ` Bernd Reiß <bd_reiss@gmx.at>
2026-08-13 04:47       ` Pavel Stehule <pavel.stehule@gmail.com>
2026-08-15 12:03         ` Bernd Reiß <bd_reiss@gmx.at>
2026-08-18 18:47           ` Pavel Stehule <pavel.stehule@gmail.com>
2026-08-21 16:56             ` Bernd Reiß <bd_reiss@gmx.at>
2026-08-21 17:15               ` Tom Lane <tgl@sss.pgh.pa.us>
2026-08-23 05:30               ` Pavel Stehule <pavel.stehule@gmail.com>
2026-08-23 06:31                 ` Bernd Reiß <bd_reiss@gmx.at>
2026-08-23 10:31                   ` Pavel Stehule <pavel.stehule@gmail.com>
2026-08-23 10:37                     ` bd_reiss@gmx.at
2026-08-23 13:22                       ` Pavel Stehule <pavel.stehule@gmail.com>
2026-08-21 22:17         ` Haibo Yan <tristan.yim@gmail.com>
2026-08-22 17:35           ` Pavel Stehule <pavel.stehule@gmail.com>
2026-08-24 17:46             ` Haibo Yan <tristan.yim@gmail.com>
2026-08-24 18:42               ` Pavel Stehule <pavel.stehule@gmail.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox