Thread: C++ Trigger Framework
Hello all, this is my first time posting here (I first posted on the IRC but didn't get any response), so let me know if there's a different procedure for asking questions.
I'm interested in creating a Postgres extension that would enable developers to write triggers in (modern) C++. Does anyone know if there is already some sort of translation wrapper between the native Postgres C API's and C++? Or if there's already a project that allows for writing triggers in C++ with ease?
I see that https://github.com/clkao/plv8js-clkao/blob/master/plv8_type.cc does implement an abstraction of sorts, but it's specific to v8 types and is not genericized as a way of interacting with Postgres C API's from C++ from any C++ code.
Can you imagine any potential technical challenges I may encounter (e.g. massaging postgres' custom allocator to work with C++'s new and delete operators, or unresolvable compiler incompatibilities)?
Thanks for any input :-)
On Tue, Feb 22, 2022 at 04:02:39PM +0200, Shmuel Kamensky wrote: > I'm interested in creating a Postgres extension that would enable > developers to write triggers in (modern) C++. Does anyone know if there is > already some sort of translation wrapper between the native Postgres C > API's and C++? Or if there's already a project that allows for writing > triggers in C++ with ease? > I see that https://github.com/clkao/plv8js-clkao/blob/master/plv8_type.cc > does implement an abstraction of sorts, but it's specific to v8 types and > is not genericized as a way of interacting with Postgres C API's from C++ > from *an*y C++ code. > > Can you imagine any potential technical challenges I may encounter (e.g. > massaging postgres' custom allocator to work with C++'s new and delete > operators, or unresolvable compiler incompatibilities)? This might answer your questions: https://www.postgresql.org/docs/devel/xfunc-c.html#EXTEND-CPP -- Nathan Bossart Amazon Web Services: https://aws.amazon.com
Hi Nathan,
Thanks for the reply. I did indeed read that document and it's a great place to get started. But it doesn't quite answer my questions. Do you personally have experience writing software in C++ that interacts with Postgres?
On Tue, Feb 22, 2022, 23:07 Nathan Bossart <nathandbossart@gmail.com> wrote:
On Tue, Feb 22, 2022 at 04:02:39PM +0200, Shmuel Kamensky wrote:
> I'm interested in creating a Postgres extension that would enable
> developers to write triggers in (modern) C++. Does anyone know if there is
> already some sort of translation wrapper between the native Postgres C
> API's and C++? Or if there's already a project that allows for writing
> triggers in C++ with ease?
> I see that https://github.com/clkao/plv8js-clkao/blob/master/plv8_type.cc
> does implement an abstraction of sorts, but it's specific to v8 types and
> is not genericized as a way of interacting with Postgres C API's from C++
> from *an*y C++ code.
>
> Can you imagine any potential technical challenges I may encounter (e.g.
> massaging postgres' custom allocator to work with C++'s new and delete
> operators, or unresolvable compiler incompatibilities)?
This might answer your questions:
https://www.postgresql.org/docs/devel/xfunc-c.html#EXTEND-CPP
--
Nathan Bossart
Amazon Web Services: https://aws.amazon.com
On Tue, Feb 22, 2022 at 11:33:05PM +0200, Shmuel Kamensky wrote: > Hi Nathan, > > Thanks for the reply. I did indeed read that document and it's a great place to > get started. But it doesn't quite answer my questions. Do you personally have > experience writing software in C++ that interacts with Postgres? As far as I know, it should just work like C. I know you can compile the backend server using a C++ compiler because we get bug reports when we break it. -- Bruce Momjian <bruce@momjian.us> https://momjian.us EDB https://enterprisedb.com If only the physical world exists, free will is an illusion.
OK, great thank you, Buce! I'll check back in with any interesting results when I have something running (probably in a few months to a year since I don't yet know C++ very well :-)).