Re: INDEXng date_trunc ...

From: Brent Verner <brent(at)rcfile(dot)org>
To: "Marc G(dot) Fournier" <scrappy(at)hub(dot)org>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: INDEXng date_trunc ...
Date: 2001-11-22 15:29:05
Message-ID: 20011122102905.A34094@rcfile.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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
input field; 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

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Stephan Szabo 2001-11-22 17:01:22 Re: How are working index with date ?
Previous Message Henshall, Stuart - WCP 2001-11-22 15:20:31 Re: ldap support