Re: index compatible date_trunc in postgres?

Поиск
Список
Период
Сортировка
От Scott Marlowe
Тема Re: index compatible date_trunc in postgres?
Дата
Msg-id dcc563d10812182152ida80ebcgab4ca7e16d11bdff@mail.gmail.com
обсуждение исходный текст
Ответ на index compatible date_trunc in postgres?  (Bryce Nesbitt <bryce2@obviously.com>)
Ответы Re: index compatible date_trunc in postgres?  (Alvaro Herrera <alvherre@commandprompt.com>)
Downgrade database and problem with sequences  ("Sebastian Rychter" <srychter@anvet.com.ar>)
Список pgsql-sql
On Thu, Dec 18, 2008 at 10:46 PM, Bryce Nesbitt <bryce2@obviously.com> wrote:
> I've got a legacy app that does 8.3 incompatible date searches like so:
> explain select count(*) from contexts where publication_date like '2006%';
> explain select count(*) from contexts where publication_date like
> '2006-09%';
>
> I've got my choice of refactoring, but all these share the same
> sequential scan limitation:
> explain select count(*) from contexts where publication_date::text LIKE
> '2006%';
> explain select count(*) from contexts where
> date_trunc('year',publication_date) = '2006-01-01';
> explain select count(*) from contexts where extract('year' from
> publication_date) = '2006';
>
> Are there any other index compatible methods, other than turning it into
> a range search?
> explain select count(*) from contexts where publication_date >=
> '2006-01-01' and publication_date < '2007-01-01';
> explain select count(*) from contexts where publication_date >=
> '2006-09-01' and publication_date < '2006-09-31 24:00:00';

You can create an index on date_trunc (on timestamp without timezone,
but not on timestamp with timezone since it's not immutable)

create index mytable_datetrunc_month on mytable (date_trunc('month',
timestampfield));


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

Предыдущее
От: Bryce Nesbitt
Дата:
Сообщение: index compatible date_trunc in postgres?
Следующее
От: Alvaro Herrera
Дата:
Сообщение: Re: index compatible date_trunc in postgres?