timestamp - timestamp result

Поиск
Список
Период
Сортировка
От Thomas Kellerer
Тема timestamp - timestamp result
Дата
Msg-id c1696f68-fa8d-7759-6a9c-eb293ab1bbc9@gmx.net
обсуждение исходный текст
Ответы Re: timestamp - timestamp result  (Pavel Stehule <pavel.stehule@gmail.com>)
Список pgsql-general
I regularly see people suggesting to use

    extract(day from one_timestamp - other_timestamp)

to calculate the difference between two timestamps in days.

But I wonder if the "format" of the resulting interval is guaranteed to only have days
(and not months or years)

The following:

     timestamp '2020-06-26 17:00:00' - timestamp '2019-04-01 14:00:00'

returns an interval like this:

     0 years 0 mons 452 days 3 hours 0 mins 0.0 secs

However, is there ever a chance that the expression will yield the (equivalent) interval:

     1 years 2 mons 25 days 3 hours 0 mins 0.0 secs

e.g. as the age() function does.

Is it safe to assume that "timestamp - timestamp" will never contain units larger then days?


Thomas




В списке pgsql-general по дате отправления:

Предыдущее
От: "Bhalodiya, Chirag"
Дата:
Сообщение: Re: PostGreSQL TDE encryption patch
Следующее
От: Pavel Stehule
Дата:
Сообщение: Re: timestamp - timestamp result