Thread: creating index using function

creating index using function

From
Matthew Engelbert
Date:
I would like to create an index on table ecn_sales, based on the day of year
value of a timestamp column tv_time.   However, I'm getting an error:

CREATE INDEX ecn_sales_index_day on ecn_sales (extract(DOY FROM tv_time));
ERROR:  syntax error at or near "(" at character 55

Any help would be appreciated.  Thanks.

- Matt

Re: creating index using function

From
Tom Lane
Date:
Matthew Engelbert <mje1975@yahoo.com> writes:
> CREATE INDEX ecn_sales_index_day on ecn_sales (extract(DOY FROM tv_time));
> ERROR:  syntax error at or near "(" at character 55

Assuming you're using 7.4, put an extra pair of parens there:

CREATE INDEX ecn_sales_index_day on ecn_sales ((extract(DOY FROM tv_time)));

In earlier PG versions you'll need a wrapper function around the extract
call.  It looks like a function, but it isn't quite one because of the
weird syntax.

            regards, tom lane