Re: index on to_char(created, 'YYYY') doesn't work - Mailing list pgsql-sql

From Josh Berkus
Subject Re: index on to_char(created, 'YYYY') doesn't work
Date
Msg-id web-2314974@davinci.ethosmedia.com
Whole thread Raw
In response to Re: index on to_char(created, 'YYYY') doesn't work  (Steve Crawford <scrawford@pinpointresearch.com>)
List 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 by date:

Previous
From: "Josh Berkus"
Date:
Subject: Re: query speed joining tables
Next
From: Oleg Bartunov
Date:
Subject: Re: sort by relevance