Re: Error trying to create a functional index. - Mailing list pgsql-sql

From Jochem van Dieten
Subject Re: Error trying to create a functional index.
Date
Msg-id 3C3AE1AD.30508@dev.null
Whole thread Raw
In response to Re: Error trying to create a functional index.  (CoL <col@mportal.hu>)
List pgsql-sql
CoL wrote:

> 
> sure it is, but date_trunc takes this, so what is the way to create a 
> date_trunc part or any date function index on a timestamp?
> 
> Or it's not possible?


I would tend to believe it is not directly possible. But maybe with a 
custom function:

(pseudocode, check whether Day is a reserved word)
CREATE FUNCTION Day(date) RETURNS varchar AS '
BEGIN  RETURN Cast(date_trunc('day', $1) AS varchar);
END;
' LANGUAGE 'SQL';

CREATE INDEX eventdateindex ON event (Day(eventstamp));

SELECT Day(eventstamp) FROM event;


Jochem









pgsql-sql by date:

Previous
From: Tom Lane
Date:
Subject: Re: who has lock on table/row
Next
From: "steve boyle"
Date:
Subject: Re: Result sets from functions