Re: index on to_char(created, 'YYYY') doesn't work

From: "Josh Berkus" <josh(at)agliodbs(dot)com>
To: Steve Crawford <scrawford(at)pinpointresearch(dot)com>, Andreas Joseph Krogh <andreak(at)officenet(dot)no>, Achilleus Mantzios <achill(at)matrix(dot)gatewaynet(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: index on to_char(created, 'YYYY') doesn't work
Date: 2003-01-15 18:15:55
Message-ID: web-2314974@davinci.ethosmedia.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Oleg Bartunov 2003-01-15 18:19:47 Re: [SQL] sort by relevance
Previous Message Josh Berkus 2003-01-15 17:50:22 Re: query speed joining tables