Re: Inconsistent results in timestamp/interval comparison

Поиск
Список
Период
Сортировка
Искать
От
albrecht.dress@posteo.de
Тема
Re: Inconsistent results in timestamp/interval comparison
Дата
Msg-id
4faaea681e2e210bbfb7de92fc8cbb35@posteo.de
Ответ на
Список
Дерево обсуждения
Inconsistent results in timestamp/interval comparison albrecht.dress@posteo.de
Re: Inconsistent results in timestamp/interval comparison Francisco Olarte <folarte@peoplecall.com>
Re: Inconsistent results in timestamp/interval comparison albrecht.dress@posteo.de
Re: Inconsistent results in timestamp/interval comparison Francisco Olarte <folarte@peoplecall.com>
Re: Inconsistent results in timestamp/interval comparison Alban Hertroys <haramrae@gmail.com>
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.


В списке pgsql-general по дате отправления
От: Alban Hertroys
Дата:
От: Francisco Olarte
Дата:
FAQ