From: Adrian Klaver <adrian.klaver@aklaver.com>
To: Bryn Llewellyn <bryn@yugabyte.com>
Cc: Tom Lane PostgreSQL <tgl@sss.pgh.pa.us>
Cc: pgsql-general list <pgsql-general@lists.postgresql.org>
Subject: Re: to_date() and to_timestamp() with negative years
Date: Wed, 3 Nov 2021 15:14:49 -0700
Message-ID: <c105f567-aa51-8eee-d272-ef472ca6c9dc@aklaver.com> (raw)
In-Reply-To: <0B75398B-91CC-4074-B77A-390AA157685B@yugabyte.com>
References: <A7385FDD-CC12-44DD-BEE8-8E8AD5C69EF5@yugabyte.com>
<138332.1635962086@sss.pgh.pa.us>
<08E63AD5-8E6D-4140-AE1C-9DC22324A287@yugabyte.com>
<72204b8f-41b2-0004-b09b-842f8c57477f@aklaver.com>
<0B75398B-91CC-4074-B77A-390AA157685B@yugabyte.com>
On 11/3/21 1:39 PM, Bryn Llewellyn wrote:
> /adrian.klaver@aklaver.com <mailto:adrian.klaver@aklaver.com> wrote:/
>
>> /Bryn wrote:/
>>
>>> In what PG version did you run your test?
>>> I'm not surprised that grandfathered-in "solution" that I described
>>> will never go away—despite its questionable conceptual basis.
>
> Thanks, Adrian. What results do these queries give in Version 14?
> (Forgive me, I'll make time to install v14 very soon.)
select version();
version
------------------------------------------------------------------------------------
PostgreSQL 14.0 on x86_64-pc-linux-gnu, compiled by gcc (SUSE Linux)
7.5.0, 64-bit
>
> select make_timestamp(0,1,1,0,0,0);
ERROR: date field value out of range: 0-01-01
> select make_timestamp(-0,1,1,0,0,0);
ERROR: date field value out of range: 0-01-01
>
> select '-0001-01-01'::date; -- and similar for typecasts to timestamp
> and timestamptz
ERROR: invalid input syntax for type date: "-0001-01-01"
LINE 1: select '-0001-01-01'::date;
>
> select '0000-01-01'::date;
ERROR: date/time field value out of range: "0000-01-01"
LINE 1: select '0000-01-01'::date;
>
> select '-0000-01-01'::date;
ERROR: invalid input syntax for type date: "-0000-01-01"
LINE 1: select '-0000-01-01'::date;
>
> select
> to_date( '15/06/-2021', 'DD/MM/YYYY' ) as a1,
> to_date( '15/06/-2021 BC', 'DD/MM/YYYY/AD' ) as a2,
> '' as "-",
> to_date( '15 06 -2021', 'DD MM YYYY' ) as b1,
> to_date( '15 06 -2021 BC', 'DD MM YYYY AD' ) as b2;
>
a1 | a2 | - | b1 | b2
---------------+------------+---+------------+---------------
2021-06-15 BC | 2021-06-15 | | 2021-06-15 | 2021-06-15 BC
Haven't had time to work through what the above is actually doing.
--
Adrian Klaver
adrian.klaver@aklaver.com
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-general@postgresql.org
Cc: adrian.klaver@aklaver.com, bryn@yugabyte.com, tgl@sss.pgh.pa.us
Subject: Re: to_date() and to_timestamp() with negative years
In-Reply-To: <c105f567-aa51-8eee-d272-ef472ca6c9dc@aklaver.com>
References: <A7385FDD-CC12-44DD-BEE8-8E8AD5C69EF5@yugabyte.com> <138332.1635962086@sss.pgh.pa.us> <08E63AD5-8E6D-4140-AE1C-9DC22324A287@yugabyte.com> <72204b8f-41b2-0004-b09b-842f8c57477f@aklaver.com> <0B75398B-91CC-4074-B77A-390AA157685B@yugabyte.com> <c105f567-aa51-8eee-d272-ef472ca6c9dc@aklaver.com>
* 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