Обсуждение: date is not immutable ?

Поиск
Список
Период
Сортировка

date is not immutable ?

От
"Gaetano Mendola"
Дата:
Hi all,
I'm trying to create an index on a timestamptz field just extracting the
date:

# create index idx_user_logs_login_time_date on user_logs (
date(login_time) );
ERROR:  DefineIndex: index function must be marked IMMUTABLE


why date is not marked immutable ?


Regards
Gaetano



Re: date is not immutable ?

От
"Gaetano Mendola"
Дата:
"Zachary Beane" <xach@xach.com> wrote in message
news:slrnb6sdcb.25l.xach@localhost.localdomain...
> In article <b4labj$15lq$1@news.hub.org>, Gaetano Mendola wrote:
> > Hi all,
> > I'm trying to create an index on a timestamptz field just extracting the
> > date:
> >
> > # create index idx_user_logs_login_time_date on user_logs (
> > date(login_time) );
> > ERROR:  DefineIndex: index function must be marked IMMUTABLE
> >
> >
> > why date is not marked immutable ?
>
> It is influenced by the local time zone.

Do you know another way to improve the select:

SELECT * FROM T WHERE date(login_time) = now()::date;


Regards
Gaetano





Re: date is not immutable ?

От
xach@xach.com (Zachary Beane)
Дата:
In article <b4labj$15lq$1@news.hub.org>, Gaetano Mendola wrote:
> Hi all,
> I'm trying to create an index on a timestamptz field just extracting the
> date:
>
> # create index idx_user_logs_login_time_date on user_logs (
> date(login_time) );
> ERROR:  DefineIndex: index function must be marked IMMUTABLE
>
>
> why date is not marked immutable ?

It is influenced by the local time zone.

Zach

Re: date is not immutable ?

От
Tom Lane
Дата:
"Gaetano Mendola" <mendola@bigfoot.com> writes:
> I'm trying to create an index on a timestamptz field just extracting the
> date:
> # create index idx_user_logs_login_time_date on user_logs (
> date(login_time) );
> ERROR:  DefineIndex: index function must be marked IMMUTABLE

> why date is not marked immutable ?

Because the conversion depends on your timezone setting.

            regards, tom lane