Thread: user defined functions

user defined functions

From
"Alison Stevenson"
Date:
Hello,

As part of an ongoing project I am looking to migrate a large application from a proprietary OODBMS (that shall remain
nameless)to another database. Having read around a bit PostgreSQL looks like the best fit but I have a couple of
concernsabout the user defined functions which I wonder if anyone can address. 

(btw if this isn't the right forum for such questions I apologise and would ask some kind person to point me to the
rightlist) 

Firstly, am I correct in thinking that user-defined functions cannot be written in C++ or Java? (The FAQ gives C, SQL,
PL/pgSQL,Tcl, Perl, Python, or Ruby as the only possibilities) 
Secondly what sort of SQL interface to the user defined functions is available? For example if I defined a 'distance'
functionto compare two feature_vectors stored as BLOBs can I call  
    t1.feature_vector.distance(t2.feature_vector)
?

Thanks folks,

Alison

Alison Stevenson
IT Innovation Centre
2 Venture Road
Chilworth Science Park
Southampton SO16 7NP

Tel: +44 23 8076 0834
Fax: +44 23 8076 0833

mailto:as@it-innovation.soton.ac.uk
http://www.it-innovation.soton.ac.uk






Re: user defined functions

From
nconway@klamath.dyndns.org (Neil Conway)
Date:
On Thu, Jun 27, 2002 at 09:44:08AM +0100, Alison Stevenson wrote:
> Firstly, am I correct in thinking that user-defined functions cannot
> be written in C++ or Java? (The FAQ gives C, SQL, PL/pgSQL, Tcl,
> Perl, Python, or Ruby as the only possibilities)

UDFs can be written in Java using http://pljava.sf.net.

You can write UDFs in C++ -- as long as the single function you tell
Postgres about (the "entry point" into the C++ code) is defined with C
linkage (extern "C" { ... }).

> Secondly what sort of SQL interface to the user defined functions
> is available? For example if I defined a 'distance' function to
> compare two feature_vectors stored as BLOBs can I call
>     t1.feature_vector.distance(t2.feature_vector)

No -- you can call distance(t1.feature_vector, t2.feature_vector)
though.

Cheers,

Neil

--
Neil Conway <neilconway@rogers.com>
PGP Key ID: DB3C29FC