[prev in list] [next in list] [prev in thread] [next in thread] 

List:       postgresql-sql
Subject:    Re: [SQL] creating an index on a function
From:       Brent Verner <brent () rcfile ! org>
Date:       2002-02-15 15:42:52
[Download RAW message or body]

[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

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic