pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Bryn Llewellyn <bryn@yugabyte.com>
Cc: pgsql-general list <pgsql-general@lists.postgresql.org>
Subject: Re: to_date() and to_timestamp() with negative years
Date: Wed, 03 Nov 2021 13:54:46 -0400
Message-ID: <138332.1635962086@sss.pgh.pa.us> (raw)
In-Reply-To: <A7385FDD-CC12-44DD-BEE8-8E8AD5C69EF5@yugabyte.com>
References: <A7385FDD-CC12-44DD-BEE8-8E8AD5C69EF5@yugabyte.com>

Bryn Llewellyn <bryn@yugabyte.com> writes:
> Is there any chance that you might be bold and simply make negative "year" values illegal in "to_date()" and "to_timestamp()" — just as they already are in "make_timestamp()", "make_timestamptz()", and the "from text" typecasts to date-time moment values?

Uh, what?

regression=# select make_timestamp(-44,3,15,0,0,0);
     make_timestamp     
------------------------
 0044-03-15 00:00:00 BC
(1 row)

The other stuff you are talking about looks like confusion around which
characters are minus signs in the data and which ones are field
separators.  Given the very squishy definitions of to_date/to_timestamp,
I'm not surprised if that works only with carefully chosen field
layouts --- but it does work for me with all of these cases:

regression=# select to_date('-0044-03-15', 'YYYY-MM-DD');
    to_date    
---------------
 0044-03-15 BC
(1 row)

regression=# select to_date('03-15--0044', 'MM-DD-YYYY');
    to_date    
---------------
 0044-03-15 BC
(1 row)

regression=# select to_date('03/15/-0044', 'MM/DD/YYYY');
    to_date    
---------------
 0044-03-15 BC
(1 row)

I'd be the first to agree that that code is a mess and could stand to
be rewritten --- but I seriously doubt that we'd take a patch that
intentionally breaks cases that work fine today.  There's also the
angle that these are supposed to be Oracle-compatible, so I wonder
what Oracle does with such input.

			regards, tom lane





view thread (14+ messages)  latest in thread

Message-ID: <138332.1635962086@sss.pgh.pa.us>
Permalink:  ../138332.1635962086@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/138332.1635962086@sss.pgh.pa.us

 · 

reply

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: tgl@sss.pgh.pa.us, bryn@yugabyte.com
  Subject: Re: to_date() and to_timestamp() with negative years
  In-Reply-To: <138332.1635962086@sss.pgh.pa.us>
  References: <A7385FDD-CC12-44DD-BEE8-8E8AD5C69EF5@yugabyte.com> <138332.1635962086@sss.pgh.pa.us>

* 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