| From: | Ilya Urikh <ilya(dot)urikh(at)gmail(dot)com> |
|---|---|
| To: | pgsql-novice(at)postgresql(dot)org |
| Subject: | C-Language function invocation from another one. |
| Date: | 2009-05-13 23:39:01 |
| Message-ID: | adf175f70905131639p7ec5d660le3ec6ad137d9368a@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-novice |
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.
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Tom Lane | 2009-05-13 23:44:08 | Re: C-Language function invocation from another one. |
| Previous Message | Paul Alarcon | 2009-05-13 19:53:54 | update problem |