Re: date_trunc'd timestamp index possible?

From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: "D(dot) Duccini" <duccini(at)backpack(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org, Pgsql-novice <pgsql-novice(at)postgresql(dot)org>
Subject: Re: date_trunc'd timestamp index possible?
Date: 2004-10-01 18:28:30
Message-ID: 20041001182830.GA20624@wolff.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-novice pgsql-sql

On Mon, Sep 27, 2004 at 19:14:09 -0500,
"D. Duccini" <duccini(at)backpack(dot)com> wrote:
>
> I'm trying to create a index from a timestamp+tz field and want the index
> to be date_trunc'd down to just the date
>
> when i try to do a
>
> create idxfoo on foo (date(footime));
>
> i get a
>
> ERROR: DefineIndex: index function must be marked IMMUTABLE
>
> and it chokes on when i try to use the date_trunc() function as well
>
> create idxfoo on foo (date_trunc('day',footime));
>
> ERROR: parser: parse error at or near "'day'" at character 53
>
> Any suggestions/workarounds (other than creating additional date-only
> columns in the schema and indexing those???)

The reason this doesn't work is that the timestamp to date conversion
depends on the time zone setting. In theory you should be able to avoid
this by specifying the time zone to check the date in. I tried something
like the following which I think should work, but doesn't:
create idxfoo on foo (date(timezone('UTC',footime)));

The conversion of the timestamp stored in footime should be immutable
and then taking the date should work. I did find that date of a timestamp
without time zone is treated as immutable.

I am not sure how to check if the supplied function for converting
a timestamp with time zone to a timestamp without timezone using a
specified time zone is immutable. I think this function should be
immutable, but that it probably isn't.

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message D. Duccini 2004-10-01 18:28:47 Re: date_trunc'd timestamp index possible?
Previous Message Chris Browne 2004-10-01 14:51:59 Re: AIX and V8 beta 3

Browse pgsql-novice by date

  From Date Subject
Next Message D. Duccini 2004-10-01 18:28:47 Re: date_trunc'd timestamp index possible?
Previous Message brew 2004-10-01 17:20:01 Re: Brand New User (I hope)

Browse pgsql-sql by date

  From Date Subject
Next Message D. Duccini 2004-10-01 18:28:47 Re: date_trunc'd timestamp index possible?
Previous Message Marcin Piotr Grondecki 2004-10-01 16:46:45 Re: SELECT with Function