Re: BUG #6126: CC parameter in to_char() behaves incorrectly

From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Artem Andreev <artem(at)oktetlabs(dot)ru>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #6126: CC parameter in to_char() behaves incorrectly
Date: 2012-08-04 14:34:14
Message-ID: 20120804143414.GA29773@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Fri, Aug 3, 2012 at 06:51:45PM -0400, Bruce Momjian wrote:
> I also tested boundry values, e.g. 6th Century BC is 600-501:
>
> test=> select to_char('0600-01-01 00:00:00 BC' :: timestamp, 'CC');
> to_char
> ---------
> -6
> (1 row)
>
> test=> select to_char('0599-01-01 00:00:00 BC' :: timestamp, 'CC');
> to_char
> ---------
> -6
> (1 row)
>
> test=> select to_char('0501-01-01 00:00:00 BC' :: timestamp, 'CC');
> to_char
> ---------
> -6
> (1 row)
>
> test=> select to_char('0500-01-01 00:00:00 BC' :: timestamp, 'CC');
> to_char
> ---------
> -5
> (1 row)
>
> I am thinking it is too late to apply this for 9.2 because users might
> have already tested their applications, though I doubt many are using BC
> dates. Feedback?

There is never just one bug in formatting.c --- the input side was also
broken for BC/negative centuries. The attached patch fixes the input
side as well, and shows the old/fixed output for BC centuries. The test
queries were:

SELECT to_date('-6 4', 'CC YY');
SELECT to_date(' 6 4', 'CC YY');
SELECT to_date('-6 00', 'CC YY');
SELECT to_date(' 6 00', 'CC YY');
SELECT to_date('-6', 'CC');
SELECT to_date(' 6', 'CC');

I believe this is all for 9.3-only.

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ It's impossible for everything to be true. +

Attachment Content-Type Size
century.diff text/x-diff 6.1 KB
output.diff text/x-diff 1.0 KB

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Eric Thomas 2012-08-04 15:43:58 Small bug in psqlodbc-09.01 prevents interoperability with LISTSERV
Previous Message Bruce Momjian 2012-08-03 22:51:45 Re: BUG #6126: CC parameter in to_char() behaves incorrectly