From: Fabien COELHO <coelho@cri.ensmp.fr>
To: szx9231@gmail.com, PostgreSQL Bugs <pgsql-bugs@lists.postgresql.org>
Subject: Re: BUG #16216: the result of to_date function with negative year number not same as BC year number
Date: Fri, 17 Jan 2020 15:17:34 +0100 (CET)
Message-ID: <alpine.DEB.2.21.2001171503400.31891@pseudo> (raw)
In-Reply-To: <16216-68da08087f3aeb78@postgresql.org>
References: <16216-68da08087f3aeb78@postgresql.org>
Hello,
> example:
> postgres=# select to_date('-120', 'yyyy');
> to_date
> ---------------
> 0121-01-01 BC
> (1 row)
>
> postgres=# select to_date('120bc', 'yyyybc');
> to_date
> ---------------
> 0120-01-01 BC
> (1 row)
>
> I think -120 means 120bc, however, the output is 121bc not 120bc.
ISTM that the documentation does not say that -120 is supported as meaning
BC.
Given that there are no year 0 (zero was invented much later), history
skips form year -1 to year 1. If -120 means in the implementation "year as
an integer", then skipping zero would mean that it indeed represents year
121 BC, i.e. 120 years before "Jan 1, 1 AD". So there is a logic.
BTW I found another oddity while trying strange date patterns:
sql> SELECT DATE 'Jan 1, 0001 AD';
# 0001-01-01
But:
sql> SELECT DATE 'Jan 1, 1 AD';
# 2001-01-01 # WT*?
I'll try to have a look over the week-end.
--
Fabien.
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: coelho@cri.ensmp.fr
Subject: Re: BUG #16216: the result of to_date function with negative year number not same as BC year number
In-Reply-To: <alpine.DEB.2.21.2001171503400.31891@pseudo>
References: <16216-68da08087f3aeb78@postgresql.org> <alpine.DEB.2.21.2001171503400.31891@pseudo>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
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