Re: Functional index problems. (Was: Many joins: monthly summaries S-L--O--W) - Mailing list pgsql-novice

From Tom Lane
Subject Re: Functional index problems. (Was: Many joins: monthly summaries S-L--O--W)
Date
Msg-id 17556.1066844690@sss.pgh.pa.us
Whole thread Raw
In response to Functional index problems. (Was: Many joins: monthly summaries S-L--O--W)  (Michael Glaesmann <grzm@myrealbox.com>)
Responses Re: Functional index problems. (Was: Many joins: monthly summaries S-L--O--W)
List pgsql-novice
Michael Glaesmann <grzm@myrealbox.com> writes:
> Searching for ways to improve performance, I tried to create a index on
> the extract function, but for some reason I couldn't get it to work.
> Following the documentation for CREATE INDEX and EXTRACT, I tried

> CREATE INDEX dborders_extract_month_idx ON dborders (EXTRACT(MONTH from
> date));
> ERROR:  parser: parse error at or near "(" at character 61

You can't do that in pre-7.4 releases; the syntax of a functional index
can only be "ON table (func(col1,col2,...))" --- that is, a simple,
standard-notation function applied to one or more columns of the table.
So to do this, you'd need to create an intermediate function along
the lines of "month_trunc(date)"; and you'd have to use it in your
queries as well as in the index definition.

7.4 is more flexible though --- it will take the above as long as you
put an extra set of parentheses in there...

            regards, tom lane

pgsql-novice by date:

Previous
From: Michael Glaesmann
Date:
Subject: Functional index problems. (Was: Many joins: monthly summaries S-L--O--W)
Next
From: Josh Berkus
Date:
Subject: Re: Functional index problems. (Was: Many joins: monthly summaries S-L--O--W)