From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | nickf(at)ontko(dot)com |
Cc: | "PGSQL-SQL" <pgsql-sql(at)postgresql(dot)org> |
Subject: | Re: creating an index on a function |
Date: | 2002-02-15 16:00:11 |
Message-ID: | 14110.1013788811@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
"Nick Fankhauser" <nickf(at)ontko(dot)com> writes:
> staging=# create index event_day on
> event(date_trunc('day',event_date_time));
> ERROR: parser: parse error at or near "'"
You missed the fine print that says the function must be applied to
table column name(s) only. No constants, no expressions.
You can get around this limitation by defining a custom function that
fills in whatever extra baggage you need.
My own first thought was that you could just use conversion to type
date, but that falls down. Not for syntax reasons though:
regression=# create table foo (event_date_time timestamp);
CREATE
regression=# create index event_day on foo (date(event_date_time));
ERROR: DefineIndex: index function must be marked iscachable
This raises a subtle point that you'd better think about before you go
too far in this direction: truncating a timestamp to date is not a very
well-defined operation, because it depends on the timezone setting.
Indexes on functions whose values might vary depend on who's executing
them are a recipe for disaster --- the index is almost certainly going
to wind up corrupted (out of order).
regards, tom lane
From | Date | Subject | |
---|---|---|---|
Next Message | Wei Weng | 2002-02-15 16:25:40 | create index on function - why? |
Previous Message | Brent Verner | 2002-02-15 15:42:52 | Re: creating an index on a function |