Search Postgresql Archives

Re: Inconsistent results in timestamp/interval comparison

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Am 04.03.2024 13:45 schrieb Francisco Olarte:
Intervals are composed of months, days and seconds, as not every month
has 30 days and not every day has 86400 seconds, so to compare them
you have to normalize them somehow, which can lead to bizarre results.

Ah, I see, thanks for the explanation. I had the (apparently wrong) impression that Postgres _internally_ always uses numerical values (i.e. the equivalent of EXTRACT(EPOCH …)) for such calculations. My bad…

However, a clarification in the docs might be helpful!

If you want to do point in time arithmetic, you will be better of by
extracting epoch from your timestamps and substracting that.

I can confirm that using the query

select now(), t1, extract(epoch from now() - t1) >= extract (epoch from '2 years'::interval), now() >= (t1 + '2 years'::interval) from testtab;

produces consistent results.

Thanks a lot for your help,
Albrecht.






[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]

  Powered by Linux