Re: Passing arguments to and INDEX function.

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Jeffery Collins <collins(at)onyx-technologies(dot)com>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Passing arguments to and INDEX function.
Date: 2000-05-18 15:24:31
Message-ID: 23510.958663471@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Jeffery Collins <collins(at)onyx-technologies(dot)com> writes:
> So, with that prefix, is there a way to pass an argument to a
> CREATE INDEX function? If not, is this something that would be possible
> to add? If it is possible, is it desireable? If it is possible and
> desireable, where would I start if I were to add it?

It'd be a nontrivial bit of work (possibly not the best thing to do as
your first backend project ;-)). Currently the keys for an index have
a hard-wired representation in pg_index: there's a list of attribute
numbers, which are either N separate keys of a multi-column index or
the N arguments of a function, depending on whether indproc has a value
or not. There's noplace to put a constant value, unless you can squeeze
it into the int2 slot where the attribute number would go.

Rather than kluging this up still further, the right approach would be
to blow it all away in favor of a list of N arbitrary expressions to be
evaluated to produce the index key values. The expressions would be
stored as nodetrees, same as we do for column default values (for
example). Doable, I think, but not too easy. You'd have to touch a
bunch of code, not only in the backend but in programs like pg_dump.

Whether or not Jeff wants to tackle it, I think the existing TODO item
for this is badly phrased:

* Allow CREATE INDEX zman_index ON test (date_trunc( 'day', zman ) datetime_ops)
fails index can't store constant parameters

It ought to read

* Allow arbitrary expressions as index keys

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2000-05-18 15:27:06 Re: Error in manual
Previous Message Tom Lane 2000-05-18 15:05:58 Re: initdb and "exit_nicely"...