Re: to_date()/to_timestamp() silently accept month=0 and day=0 - Mailing list pgsql-bugs

From Tom Lane
Subject Re: to_date()/to_timestamp() silently accept month=0 and day=0
Date
Msg-id 1444609.1776958814@sss.pgh.pa.us
Whole thread
In response to Re: to_date()/to_timestamp() silently accept month=0 and day=0  (Daniel Gustafsson <daniel@yesql.se>)
Responses Re: to_date()/to_timestamp() silently accept month=0 and day=0
List pgsql-bugs
Daniel Gustafsson <daniel@yesql.se> writes:
>> On 23 Apr 2026, at 09:57, Michael Paquier <michael@paquier.xyz> wrote:
>> Perhaps we could consider strengthening such inputs on HEAD once v20
>> opens for business?  It would be really a scary thing to backpatch,
>> still a major release is a different thing.

> This could definitely not be backpatched IMO, a quick check in v14 shows the
> same behaviour.  The gregorian calendar goes from BC1 to AD1 and does not
> define a year 0, to_date('0000','YYYY') correctly returns year 0001, handling
> months/days in the same way at least makes it consistent (though I didn't scour
> the archives to see if it was intentionally done like that).

Looking at the code, I think it intentionally interprets zero as
"missing data".  See for example the stanza at formatting.c:4650ff
where tm_mon and tm_mday can be backfilled from a DDD field.

I'm disinclined to change the behavior around this; you're far
more likely to get complaints than kudos.

            regards, tom lane



pgsql-bugs by date:

Previous
From: Владимир Фролов
Date:
Subject: pg_dumpall bug exit code 0 with fatal
Next
From: Ayush Tiwari
Date:
Subject: Re: to_date()/to_timestamp() silently accept month=0 and day=0