Re: pattern matching with dates? - Mailing list pgsql-sql

From Richard Huxton
Subject Re: pattern matching with dates?
Date
Msg-id 4D273ACE.5070508@archonet.com
Whole thread Raw
In response to Re: pattern matching with dates?  (pasman pasmański <pasman.p@gmail.com>)
List pgsql-sql
On 07/01/11 14:15, pasman pasmański wrote:
> Sorry, but this examples not use index.

Looks like it does here (oh, and please try to post your replies at the 
bottom of the message)

> On 1/7/11, Susanne Ebrecht<susanne@2ndquadrant.com>  wrote:

>> The more proper way is:
>>    SELECT * from tab WHERE EXTRACT(YEAR FROM log_date) = 2011 and
>> EXTRACT(MONTH FROM log_date) = 1;

CREATE TABLE d_table (d date);
INSERT INTO d_table SELECT '2001-01-01'::date + generate_series(1,9999);
CREATE INDEX d_extract_idx ON d_table ( extract('day' FROM d) );
EXPLAIN ANALYSE SELECT * FROM d_table WHERE extract('day' FROM d) = 3;

That ends up doing a bitmap index scan for me.

Of course, it's entirely possible an index on year+month returns too 
many rows to be useful.

--   Richard Huxton  Archonet Ltd


pgsql-sql by date:

Previous
From: pasman pasmański
Date:
Subject: Re: pattern matching with dates?
Next
From: Russell Galyon
Date:
Subject: Re: return records with more than one occurrences