Re: Create index on the year of a date column - Mailing list pgsql-general

From Stephan Szabo
Subject Re: Create index on the year of a date column
Date
Msg-id 20030606074315.V28541-100000@megazone23.bigpanda.com
Whole thread Raw
In response to Create index on the year of a date column  ("Nick Barr" <nick.barr@webbased.co.uk>)
List pgsql-general
On Thu, 5 Jun 2003, Nick Barr wrote:

> CREATE SEQUENCE "sm_item_id_seq" start 1 increment 1 maxvalue
> 9223372036854775807 minvalue 1 cache 1;
> CREATE TABLE "sm_item" (
>     "item_id" int4 DEFAULT nextval('"sm_item_id_seq"'::text) NOT
> NULL,
>     "item_created_date_start" date,
>     CONSTRAINT "sm_item_pkey" PRIMARY KEY ("item_id")
> ) WITHOUT OIDS;
> ------------------------------------------------------------------------
> ----
>
> And I have tried the following to create the actual index
>
> ------------------------------------------------------------------------
> ----
> create index sm_item_cdates_idx ON sm_item (extract(year from
> item_created_date_start));
> ------------------------------------------------------------------------

In 7.4, I believe you'll be allowed to say
sm_item((extract(year from item_created_date_start)))

For now, you'd need to make an immutable function that does the extract
year from $1 and use that in the index and query, although I agree with
the other response that it might just be better to index the whole value
and use range queries instead.


pgsql-general by date:

Previous
From: Joe Conway
Date:
Subject: Re: Question about serial vs. int datatypes
Next
From:
Date:
Subject: relation model vs SQL1999 conformance vs PostgreSQL