Re: where clauses including timstamptz and intervals

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: where clauses including timstamptz and intervals
Дата
Msg-id 2198582.1617985392@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: where clauses including timstamptz and intervals  (Ron <ronljohnsonjr@gmail.com>)
Ответы SV: where clauses including timstamptz and intervals  (Niels Jespersen <NJN@dst.dk>)
Список pgsql-general
Ron <ronljohnsonjr@gmail.com> writes:
> On 4/9/21 5:24 AM, hubert depesz lubaczewski wrote:
>> For example, in my timezone:
>>
>> $ select ('2020-10-01 00:00:00+00'::timestamptz + interval '1 month'), '2020-11-01 00:00:00+00'::timestamptz;
>>         ?column?        │      timestamptz
>> ────────────────────────┼────────────────────────
>>  2020-11-01 02:00:00+01 │ 2020-11-01 01:00:00+01
>> (1 row)
>>
>> Please note that there is 1 hour difference.
>> The reason is that somewhere in there we change time due to daylight
>> savings.

> That looks like a flaw in how "month" is calculated.  Whether or not October
> is 744 hours (31 days x 24 hours/day) or 743 hours (subtracting the "fall
> back" hour), one month from 01-Oct-2020 is still 01-Nov-2020.

No, it's more likely because the calculation was done in some time
zone other than UTC, which (somewhat confusingly) is what the starting
value was specified in.  Assuming Hubert meant EU rules, we have

regression=# set timezone = 'Europe/Paris';
SET
regression=# select '2020-10-01 00:00:00+00'::timestamptz;
      timestamptz
------------------------
 2020-10-01 02:00:00+02
(1 row)

regression=# select '2020-10-01 00:00:00+00'::timestamptz + interval '1 month';
        ?column?
------------------------
 2020-11-01 02:00:00+01
(1 row)

which looks to me like the addition did exactly what it's supposed to,
ie same local time 1 month later.

            regards, tom lane



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

Предыдущее
От: Ron
Дата:
Сообщение: Re: Who altered the database?
Следующее
От: Ganesh Korde
Дата:
Сообщение: Re: Who altered the database?