Hi,
What is the best way to call C-Language function from another one?
Now I see only one method - to call SPI_execute("EXECUTE funcName(...);", false, 0).
For example:
PG_FUNCTION_INFO_V1(calculateAccount);
PG_FUNCTION_INFO_V1(calculateAccountService);
Datum calculateAccount(PG_FUNCTION_ARGS);
Datum calculateAccountService(PG_FUNCTION_ARGS);
Datum calculateAccount(PG_FUNCTION_ARGS)
{
// Arguments
int32 accountId = PG_GETARG_INT32(0);
DateADT startDate = PG_GETARG_DATEADT(1);
DateADT endDate = PG_GETARG_DATEADT(2);
char command[1000];
...
SPI_connect();
snprintf(command, sizeof(command), "execute calculateAccountService(%d,
%d);", accountId, serviceId);
SPI_execute(command, false, 0);
SPI_finish();
PG_RETURN_NULL();
}
Datum calculateAccountService(PG_FUNCTION_ARGS)
{
int32 accountId = PG_GETARG_INT32(0);
int32 serviceId = PG_GETARG_INT32(1);
...
PG_RETURN_NULL();
}
--
Best regards,
Ilya Urikh.