Re: INDEXng date_trunc ... - Mailing list pgsql-sql

From Brent Verner
Subject Re: INDEXng date_trunc ...
Date
Msg-id 20011122102905.A34094@rcfile.org
Whole thread Raw
In response to INDEXng date_trunc ...  ("Marc G. Fournier" <scrappy@hub.org>)
Responses Re: INDEXng date_trunc ...  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-sql
On 22 Nov 2001 at 09:41 (-0500), Marc G. Fournier wrote:
| 
| In v7.2, how does one index a function?
| 
| CREATE INDEX hourly_stats_day
|           ON hourly_stats
|        USING btree ( DATE_TRUNC('day',runtime) ) ;
| 
| Gives me:
| 
| ERROR:  parser: parse error at or near "'"

from $htmldocs/indexes-functional.html:
 "The function in the index definition can take more than one  argument, but they must be table columns, not constants.
Functional indexes are always single-column (namely, the  function result) even if the function uses more than one
inputfield; there cannot be multicolumn indexes that  contain function calls.
 
   Tip: The restrictions mentioned in the previous paragraph       can easily be worked around by defining a custom
 function to use in the index definition that computes      any desired result internally."
 

so...

create table test( id serial, tid timestamp default now() );

create function date_part_day(timestamp) returns float8 as ' select date_part(''day'',$1);
' language SQL with(iscachable);
create index ix_test_tid on test( date_part_day(tid) );


I have /no clue whatsoever/ how well that will work.  Now, I'm curious
why we can't take a constant as an argument to an indexed function... 

hth. brent

-- 
"...curiousity and the cat."
Why do /I/ have to be that cat?                        -- dbv


pgsql-sql by date:

Previous
From: "Henshall, Stuart - WCP"
Date:
Subject: Re: ldap support
Next
From: frbn@efbs-seafrigo.fr
Date:
Subject: Re: SELECT * FROM t where p or q;