Re: Index on a function(field) - Mailing list pgsql-general

From Tom Lane
Subject Re: Index on a function(field)
Date
Msg-id 6656.989610319@sss.pgh.pa.us
Whole thread Raw
In response to Index on a function(field)  (Gabriel Fernandez <gabi@unica.edu>)
List pgsql-general
Gabriel Fernandez <gabi@unica.edu> writes:
> Is it possible to create an index using a function(field) sintaxis ?

Yes, but *only* on a function of one or more raw fields.

> CREATE  INDEX "i1_cdu" on "cdu" using btree ( substr(cdu_code,1,1)
> "varchar_ops" );

This doesn't work because you have some constants floating around in the
mix.

In theory you can work around this by creating a custom function, say
firstchar(varchar), that does "substr(x,1,1)", and then writing

CREATE  INDEX "i1_cdu" on "cdu" using btree ( firstchar(cdu_code) );

It's kind of a pain though...

            regards, tom lane

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: name truncation problem in 7.0.0
Next
From: larry a price
Date:
Subject: Re: Nu-B Question