Re: BUG #17573: timestamptz casting precision goes down as the year goes up

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: luc(dot)lavoie(at)usherbrooke(dot)ca
Cc: pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #17573: timestamptz casting precision goes down as the year goes up
Date: 2022-08-04 22:37:01
Message-ID: 3675316.1659652621@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

PG Bug reporting form <noreply(at)postgresql(dot)org> writes:
> timestamptz casting on year 2022 values returns a precision of one
> microsecond (as it is expected).
> As the year goes up, the precision goes down as the script below will show
> for years 2022, 23621, 2713, 4022, and 8022.

The issue here is not with the timestamp, nor even with the extract().
It's with your use of to_timestamp(), which takes float8, which has
limited precision. The precision is disappearing in the implicit
cast to float8.

Prior to v14, there was also an issue with extract() returning float8,
but nowadays it returns numeric. If you look directly at the extract()
results you'll see no precision is lost.

Maybe we should invent a variant of to_timestamp that takes numeric, but
the use-case seems pretty niche ...

regards, tom lane

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message PG Bug reporting form 2022-08-04 23:42:54 BUG #17574: Attaching an invalid index to partition head make head index invalid forever
Previous Message PG Bug reporting form 2022-08-04 21:12:37 BUG #17573: timestamptz casting precision goes down as the year goes up