Postgresql function in C++

Started by Jose Mendozaover 21 years ago2 messagesgeneral
Jump to latest
#1Jose Mendoza
unixos@prodigy.net.mx

On august 2001 Eniar wrote above this issue the following:

"On Tue, Aug 07, 2001 at 07:49:06AM -0500, Phillip J. Allen wrote:

Hi all,

I was reading Bruce Momjian book on PostgreSQL and his chapter on user
created functions stated that functions can be written in SQL, PL/PGSQL,
PL/TCL, PL/Per, and C. But I have been studying C++ for linux. So can
I create a dynamically linked object file in C++ and reference it in a
function?

The easiest way is to write C-wrappers around your C++ code.

- Einar Karttunen

"

I would like if it is possible to build a PostgreSQL function in C++. I
have a code generator to solve the problem to communicate postgresql with
other database (postgresql included).

Some little example will be enough.

Thanks

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Jose Mendoza (#1)
Re: Postgresql function in C++

Jose Mendoza <unixos@prodigy.net.mx> writes:

I would like if it is possible to build a PostgreSQL function in C++.

You can do this to the extent that you're using C++ as "a better C".
As soon as you get into any of the interesting features of the language,
like exceptions or RTTI, you're going to have problems due to lack of
library support --- libstdc++ isn't linked into the backend.

You could force it in there if you don't mind using a custom-built
server, but I'm not sure of the potential gotchas of putting libstdc++
into the backend. One thing I'm pretty sure will not work in any case
is C++ exceptions; the backend uses its own setjmp-based error recovery
and that's not going to play nicely with C++.

regards, tom lane