Re: computing dT from an interval

From: David Fetter <david(at)fetter(dot)org>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: "Michael J(dot) Baars" <mjbaars1977(dot)pgsql-hackers(at)cyberfiber(dot)eu>, pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: computing dT from an interval
Date: 2021-02-22 16:11:06
Message-ID: 20210222161106.GA17314@fetter.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Mon, Feb 22, 2021 at 10:52:42AM -0500, Tom Lane wrote:
> "Michael J. Baars" <mjbaars1977(dot)pgsql-hackers(at)cyberfiber(dot)eu> writes:
> > So how do you compute the number of seconds in 8 years?
>
> IMO, that's a meaningless computation, because the answer is not fixed.
> Before you claim otherwise, think about the every-four-hundred-years
> leap year exception in the Gregorian rules. Besides, what if the
> question is "how many seconds in 7 years"? Then it definitely varies
> depending on the number of leap days included.
>
> What does make sense is timestamp subtraction, where the actual
> endpoints of the interval are known.

True.

I'm not sure whether this is a bug or an infelicity we document, but
at least in some parts of the world, this calculation doesn't comport
with the calendar in place at the time:

SELECT to_timestamp('1753', 'YYYY') - to_timestamp('1752', 'YYYY');
?column?
══════════
366 days
(1 row)

I'd like to imagine nobody will ever go mucking with the calendar to
the extent the British did that year, but one never knows.

Best,
David.
--
David Fetter <david(at)fetter(dot)org> http://fetter.org/
Phone: +1 415 235 3778

Remember to vote!
Consider donating to Postgres: http://www.postgresql.org/about/donate

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message David Fetter 2021-02-22 16:19:01 Re: Extensibility of the PostgreSQL wire protocol
Previous Message Álvaro Herrera 2021-02-22 15:56:42 Re: {CREATE INDEX, REINDEX} CONCURRENTLY improvements