Re: to_date()/to_timestamp() silently accept month=0 and day=0

From: Peter Eisentraut <peter(at)eisentraut(dot)org>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Daniel Gustafsson <daniel(at)yesql(dot)se>
Cc: Michael Paquier <michael(at)paquier(dot)xyz>, Ayush Tiwari <ayushtiwari(dot)slg01(at)gmail(dot)com>, pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: to_date()/to_timestamp() silently accept month=0 and day=0
Date: 2026-04-24 15:41:50
Message-ID: d77aae98-f563-4561-b30e-699924d4d9c6@eisentraut.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On 23.04.26 17:40, Tom Lane wrote:
> Daniel Gustafsson <daniel(at)yesql(dot)se> writes:
>>> On 23 Apr 2026, at 09:57, Michael Paquier <michael(at)paquier(dot)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.

Complaints from whom? Oracle rejects these, and PostgreSQL generally
also rejects these dates/times in other contexts. I think this should
be rejected.

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Nathan Bossart 2026-04-24 19:58:25 Re: BUG #19418: SQL/JSON JSON_VALUE() does not conform to ISO/IEC 9075-2:2023(E) 6.34 <JSON value constructor>
Previous Message Daniel Gustafsson 2026-04-24 15:27:27 Re: BUG #19457: RE: pgp_sym_encrypt silently accepts non-FIPS ciphers (bf, cast5, 3des) when OpenSSL is in FIPS mod