FM suffix in to_char Y/YY/YYY still screwy

Started by Tom Lanealmost 16 years ago3 messages
#1Tom Lane
tgl@sss.pgh.pa.us

I thought we'd fixed this ...

regression=# select to_char('2009-01-01'::date, 'YY');
to_char
---------
09
(1 row)

regression=# select to_char('2009-01-01'::date, 'FMYY');
to_char
---------
09
(1 row)

Not a lot of zero suppression happening there :-(.

I believe the correct fix is to reduce the year mod 100 (or 10 or 1000)
before feeding it to snprintf, rather than playing games with printing
only part of the result string as the original and current code try to
do.

regards, tom lane

#2Brendan Jurd
direvus@gmail.com
In reply to: Tom Lane (#1)
Re: FM suffix in to_char Y/YY/YYY still screwy

On 8 April 2010 06:46, Tom Lane <tgl@sss.pgh.pa.us> wrote:

Not a lot of zero suppression happening there :-(.

I believe the correct fix is to reduce the year mod 100 (or 10 or 1000)
before feeding it to snprintf, rather than playing games with printing
only part of the result string as the original and current code try to
do.

I think you're right. FM should behave as advertised, even for years.

Cheers,
BJ

#3Bruce Momjian
bruce@momjian.us
In reply to: Tom Lane (#1)
Re: FM suffix in to_char Y/YY/YYY still screwy

Tom Lane wrote:

I thought we'd fixed this ...

regression=# select to_char('2009-01-01'::date, 'YY');
to_char
---------
09
(1 row)

regression=# select to_char('2009-01-01'::date, 'FMYY');
to_char
---------
09
(1 row)

Not a lot of zero suppression happening there :-(.

I believe the correct fix is to reduce the year mod 100 (or 10 or 1000)
before feeding it to snprintf, rather than playing games with printing
only part of the result string as the original and current code try to
do.

Agreed. Thanks for the fix.

--
Bruce Momjian <bruce@momjian.us> http://momjian.us
EnterpriseDB http://enterprisedb.com