Re: creating an index on a function
От | Tom Lane |
---|---|
Тема | Re: creating an index on a function |
Дата | |
Msg-id | 14110.1013788811@sss.pgh.pa.us обсуждение исходный текст |
Ответ на | creating an index on a function ("Nick Fankhauser" <nickf@ontko.com>) |
Ответы |
Re: creating an index on a function
|
Список | pgsql-sql |
"Nick Fankhauser" <nickf@ontko.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
В списке pgsql-sql по дате отправления: