Return-Path: joey
Received: by postgres.Berkeley.EDU (5.61/1.29)
	id AA11617; Wed, 8 Jul 92 11:25:31 -0700
Message-Id: <9207081825.AA11617@postgres.Berkeley.EDU>
From: joey@postgres.Berkeley.EDU
Subject: Re: C++
To: postgres@postgres.berkeley.edu
Sender: pg_adm@postgres.berkeley.edu
In-Reply-To: Your message of "Wed, 08 Jul 92 10:28:12 PDT."
             <9207081728.AA10926@postgres.Berkeley.EDU> 
Date: Wed, 08 Jul 92 11:32:48 -0700
From: joey@postgres.Berkeley.EDU
X-Mts: smtp

I think there's a way to do this, but it's awfully kludgey.  I
strongly recommend that you avoid attempting to define functions that
are not written in C or Postquel.  These are the only languages we
support.

If you really want to use C++, try doing the following:

Compile your function.  Many C++ implementations actually preprocess
your code and translate it to C.  What you have to do is find out what
your function has been (re-)named by the C++ preprocessor.  You can do
this by running 'nm -t' on your object file.  Assuming you have a C++
method declared as:

int foobar(char, float),

nm should hopefully show you some C function name that looks like foobar with
its signature, i.e. foobar_int_char_float.

This is the function you should register with Postgres, and you will
have to invoke *this* function from your Postgres queries, e.g.

define function foobar_int_char_float
 (language = "c", returntype = int4)
 arg is (char, float8) as "/tmp/cplusplus.o"

retrieve (emp.all)
   where emp.dno = dept.dno
     and emp.salary = foobar_int_char_float('a', dept.budget)

Not very pretty.


CAVEAT:  This may not work in your environment.  It may not work at
all.  Obviously this will not work for inline functions.  It may also
not work if your function calls overloaded methods.  Don't forget that
the calling syntax from Postgres is C-based, i.e. there are no default
arguments, there's no overloading, etc.

So all in all, I don't recommend it.  But it may be possible if you
really need it.

Good luck.
Joe Hellerstein
