In Apache AGE, when I call the DirectFunctionCall()
function. It doesn’t get executed. I have tried putting logging statements using elog()
function in the write()
function. But, it’s of no use. The code sample is given below –
PG_FUNCTION_INFO_V1(some_function);
PG_FUNCTION_INFO_V1(write);
Datum
some_function(PG_FUNCTION_ARGS) {
.
.
.
DirectFunctionCall4(write, dest_lob, 2 * size, dest_offset, cstring_to_text(buffer));
}
The write
function mentioned here is defined below in the same file. I have checked the parameters, as well as the return type. Everything is matching correctly but still the statement is not executed.
2
Answers
Based on your code snippet, changing the order of the function info definitions should work. The dependent function should be defined after the base function.
But there is a better way to achieve the same functionality. Generally, if you want to call the same piece of code for many functions, it is advisable to make it a separate module( in this case a separate function)
The best way to deal with this case in Postgres extensions in the c code – is to not use direct function calls within the same file.
Instead, create a static helper function (
write_helper
) and make the PG functionwrite
a wrapper function that calls this function.Instead of calling the same piece of code directly from multiple functions in the same file, it is better to create a separate helper function and call that function from the other functions.This is a good practice for PostgreSQL extensions because it makes the code more modular and reusable. It also makes it easier to debug and maintain the code.
Here is an example of how to do this: