Re: Index on a function(field)

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Gabriel Fernandez <gabi(at)unica(dot)edu>
Cc: PostgreSQL-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: Index on a function(field)
Date: 2001-05-11 19:45:19
Message-ID: 6656.989610319@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Gabriel Fernandez <gabi(at)unica(dot)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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2001-05-11 19:51:59 Re: name truncation problem in 7.0.0
Previous Message webb sprague 2001-05-11 19:40:06 WAL logs eating my diskspace!!