0

It's possible to call C functions through CREATE FUNCTION but how can .NET functions in dll's be called from postgres?

0

2 Answers 2

1

You can define an external function using CREATE FUNCTION. This reference implies that the DLL must be a native DLL using the C calling convention and hence cannot handle managed code.

You could try to use Mono AOT or MS Native Image Generator to compile the managed code to native code, but I cannot tell if this will result in a native DLL using C calling convention. You have to try.

If this does not work, you could create an unmanged wrapper for your DLL.

UPDATE

You have to write a wrapper - C-Language Functions states that the DLL must include a magic block that will not be availiable if you compile managed code to native code.

Sign up to request clarification or add additional context in comments.

Comments

1

It looks like there is some overhead to calling C functions from PosgtreSQL, External Functions in Postgres @ Linux Gazette covers writing such a method in C. I would surmise from that that you could, if you REALLY need to, build a hosting module that loads a CLR instance and provides an entry point into your C# method that is mapped with the appropriate Postgres linking logic. This seems extremely costly.

Another approach that might be better would be to encapsulate the C# method (which I am assuming is already written) in a web service, and use a wrapper (not necessarily C, but one of the lighter-weight extension development bindings for Postgres) that will call out to the web service.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.