Re: index on to_char(created, 'YYYY') doesn't work

Поиск
Список
Период
Сортировка
От Josh Berkus
Тема Re: index on to_char(created, 'YYYY') doesn't work
Дата
Msg-id web-2314974@davinci.ethosmedia.com
обсуждение исходный текст
Ответ на Re: index on to_char(created, 'YYYY') doesn't work  (Steve Crawford <scrawford@pinpointresearch.com>)
Список pgsql-sql
Steve,

> BTW, I tried to create an index on the to_char function and had no
> luck - 
> seems like it should work but it doesn't on 7.2.3 or 7.3.1.

That's because functional indexes can't take any arguments other than
column names.   Therefore you'd need to:

CREATE FUNCTION to_year (timestamp) RETURNS varchar AS
'SELECT to_char($1, ''YYYY'');'
LANGUAGE 'sql' WITH (ISCACHABLE, ISSTRICT)
(above is 7.2.3 syntax)

Then use the to_year function in place of to_char for creating your
index.

-Josh Berkus


В списке pgsql-sql по дате отправления:

Предыдущее
От: "Josh Berkus"
Дата:
Сообщение: Re: query speed joining tables
Следующее
От: Oleg Bartunov
Дата:
Сообщение: Re: sort by relevance