Re: date_trunc not immutable
| От | Tom Lane |
|---|---|
| Тема | Re: date_trunc not immutable |
| Дата | |
| Msg-id | 7869.1544920023@sss.pgh.pa.us обсуждение исходный текст |
| Ответ на | date_trunc not immutable (Ravi Krishna <srkrishna@fastmail.com>) |
| Список | pgsql-general |
Ravi Krishna <srkrishna@fastmail.com> writes:
> I am trying to create an index on function date_trunc('month',timestamp)
> PG is complaining that the function must be marked as IMMUTABLE.
The timestamptz version of it is not immutable, because its effects depend
on the timezone setting:
regression=# set timezone = 'America/New_York';
SET
regression=# select date_trunc('month', now());
date_trunc
------------------------
2018-12-01 00:00:00-05
(1 row)
regression=# set timezone = 'Europe/Paris';
SET
regression=# select date_trunc('month', now());
date_trunc
------------------------
2018-12-01 00:00:00+01
(1 row)
If you want immutability, you need to be working with timestamp-without-tz
or date input, so that timezone isn't a factor.
regards, tom lane
В списке pgsql-general по дате отправления: