function callback

Поиск
Список
Период
Сортировка
Искать

function callback

От:
Igor Shevchenko <igor@carcass.ath.cx>
Дата:
Hi All,

Sorry if this was answered before, I was unable to find anything in archives.

Here's a problem I'm facing:

I have a "mimetype" table with all mimetypes my app has to deal with. I'm in a 
process of adding a fulltext indexing (tsearch2) into my DB and I want to 
specify a per-mimetype conversion function which would convert corresponding 
data into a text suitable for indexing. PostgreSQL has a "regprocedure" 
datatype (an alias to OID?) which can be added as a column to my "mimetype" 
table but I can't find a way to execute a function by regprocedure from 
pl/pgsql. Is there any way to do it except writing my own "C" function ? Or 
maybe I'd better off adding a "text" field for function name and calling it 
from pl/pgsql with EXECUTE "string" ?

-- 
Best Regards,
Igor Shevchenko

Re: function callback

От:
Martijn van Oosterhout <kleptog@svana.org>
Дата:
Вложения:
On Wed, Feb 15, 2006 at 03:47:54PM +0200, Igor Shevchenko wrote:
> Here's a problem I'm facing:
> 
> I have a "mimetype" table with all mimetypes my app has to deal with. I'm in a 
> process of adding a fulltext indexing (tsearch2) into my DB and I want to 
> specify a per-mimetype conversion function which would convert corresponding 
> data into a text suitable for indexing. PostgreSQL has a "regprocedure" 
> datatype (an alias to OID?) which can be added as a column to my "mimetype" 
> table but I can't find a way to execute a function by regprocedure from 
> pl/pgsql. Is there any way to do it except writing my own "C" function ? Or 
> maybe I'd better off adding a "text" field for function name and calling it 
> from pl/pgsql with EXECUTE "string" ?

The easy answer is: not really. regprocedure is just a way to pretty
print the name of a function. PostgreSQL doesn't have the concept of a
function pointer. You'd probably be better off storing the name of the
function and building a string to EXECUTE.

If you're really desparate you could try making a postgres function
that uses OidFunctionCalln but that just opens the door to all sorts of
hacks...

Have a nice day,
-- 
Martijn van Oosterhout      http://svana.org/kleptog/
> Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a
> tool for doing 5% of the work and then sitting around waiting for someone
> else to do the other 95% so you can sue them.
FAQ