Abhijit Menon-Sen <ams@wiw.org> writes:
> I'd like to add support for specifying constant parameters when creating
> a functional index, e.g. create index foo on bar (substr(baz, 1, 32));
> Is this a good idea?
I think you are thinking of it the wrong way. Rather than restricting
yourself to a single function call, replace the entire "functional
index" facility with an "expressional index" facility --- ie you can
index on the result of any scalar expression, of which a function call
is just a special case. Since you'll have to change the contents of
pg_index anyway, you may as well implement the more general solution.
The mechanisms associated with CHECK constraints already do everything
needed for this; it's just that they only allow expressions delivering
boolean results. So you shouldn't have a great deal of trouble finding
prototype code to follow.
This has been discussed before. Try searching the archives for
"expressional index" to see if there's anything useful.
regards, tom lane