I am experimenting with user defined functions in C, though I have
problem with stability.
It always crach on palloc() call, SPI_tuptable->tupdesc dereference
but not on SPI_* calls, for example.
Here is one modified example:
PGDLLIMPORT Datum test(PG_FUNCTION_ARGS)
command = "SELECT 1";
ret = SPI_exec(command, 1);
proc = SPI_processed;
* If some rows were fetched, print them via elog(INFO).
if (ret > 0 && SPI_tuptable != NULL)
TupleDesc tupdesc = SPI_tuptable->tupdesc;
SPITupleTable *tuptable = SPI_tuptable;
int i, j;
for (j = 0; j < proc; j++)
HeapTuple tuple = tuptable->vals[j];
for (i = 1, buf = 0; i <= tupdesc->natts; i++)
snprintf(buf + strlen (buf), sizeof(buf) - strlen(buf), " %s%s",
SPI_getvalue(tuple, tupdesc, i),
(i == tupdesc->natts) ? " " : " |");
elog(INFO, "EXECQ: %s", buf);
"elog(INFO,"5");" line is not executed, I have to restart crashed
server after error:
LOG: server process (PID 1628) was terminated by exception 0xC0000005
HINT: See C include file "ntstatus.h" for a description of the
LOG: terminating any other active server processes
0xC0000005 is access violation, but I can't follow why.
I am using Visual Studio 2005 SP1 compiler. Since mine PostgreSQL 8.4
server uses msvcr71.dll, not 80, maybe it's compiler incompatibility
of some kind?
pgeu-general by date
|Next:||From: Magnus Hagander||Date: 2012-05-15 19:43:24|
|Subject: Call for Papers - PostgreSQL Conference Europe 2012|
|Previous:||From: carlo migliopri||Date: 2012-03-10 17:48:38|