Received: from mail7.nc.rr.com ([24.93.67.54]) by postgresql.org (8.11.3/8.11.4) with ESMTP id g1FFj9E98367 for ; Fri, 15 Feb 2002 10:45:09 -0500 (EST) (envelope-from brent@mutt.rcfile.org) Received: from mutt.rcfile.org ([66.57.26.120]) by mail7.nc.rr.com with Microsoft SMTPSVC(5.5.1877.687.68); Fri, 15 Feb 2002 10:42:50 -0500 Received: (from brent@localhost) by mutt.rcfile.org (8.11.6/8.11.6) id g1FFgrh78395; Fri, 15 Feb 2002 10:42:53 -0500 (EST) (envelope-from brent) Date: Fri, 15 Feb 2002 10:42:52 -0500 From: Brent Verner To: Nick Fankhauser Cc: PGSQL-SQL Subject: Re: creating an index on a function Message-ID: <20020215154252.GA78209@rcfile.org> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.3.27i X-muttrc: $Id: .muttrc,v 1.9 2002/01/02 07:04:49 brent Exp $ X-uname: FreeBSD 4.5-STABLE #17: Sat Feb 9 15:01:43 EST 2002 brent@mutt.rcfile.org:/usr/obj/usr/src/sys/MUTT X-Archive-Number: 200202/174 X-Sequence-Number: 6600 [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