Re: creating an index on a function

From: Brent Verner <brent(at)rcfile(dot)org>
To: Nick Fankhauser <nickf(at)ontko(dot)com>
Cc: PGSQL-SQL <pgsql-sql(at)postgresql(dot)org>
Subject: Re: creating an index on a function
Date: 2002-02-15 15:42:52
Message-ID: 20020215154252.GA78209@rcfile.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Lane 2002-02-15 16:00:11 Re: creating an index on a function
Previous Message Nick Fankhauser 2002-02-15 14:26:25 creating an index on a function