Re: creating an index on a function - Mailing list pgsql-sql

From Brent Verner
Subject Re: creating an index on a function
Date
Msg-id 20020215154252.GA78209@rcfile.org
Whole thread Raw
In response to creating an index on a function  ("Nick Fankhauser" <nickf@ontko.com>)
List pgsql-sql
[2002-02-15 09:26] Nick Fankhauser said:
| Good Morning everyone!
| 
| I just tried to create an index on a function with no success. My syntax
| seems to match the syntax shown in the docs for Create Index, but I get an
| error. Any thoughts would be appreciated. Here is my attempt-
| 
| First, I did a select to make sure I had the function syntax correct, and
| then tried to create the index:
| 
| 
| staging=# select count(*) from event where
| date_trunc('day',event_date_time)='07/27/2001';
|  count
| -------
|     27
| (1 row)
| 
| staging=#
| staging=# create index event_day on
| event(date_trunc('day',event_date_time));

You cannot create an index on a function with constant parameters.
This limitation may be removed in a future version, but for now
you have to create a wrapper function that doesn't require the
constant parameter
 CREATE FUNCTION date_trunc_day(TIMESTAMP) RETURNS TIMESTAMP AS '    SELECT date_trunc(''day'',$1); ' LANGUAGE 'sql';

then use this to create your function index.   create index event_day on    event(date_trunc_day(event_date_time));

hth. brent

-- 
"Develop your talent, man, and leave the world something. Records are 
really gifts from people. To think that an artist would love you enough
to share his music with anyone is a beautiful thing."  -- Duane Allman


pgsql-sql by date:

Previous
From: "Nick Fankhauser"
Date:
Subject: creating an index on a function
Next
From: Tom Lane
Date:
Subject: Re: creating an index on a function