Обсуждение: Docbug, SPI_getbinval, triger example
The docs suggest that this:
/* Get number of tuples in relation */ ret = SPI_exec("select count(*) from ttest", 0);
if (ret < 0) elog(NOTICE, "trigf (fired %s): SPI_exec returned %d",
when, ret);
i = SPI_getbinval(SPI_tuptable->vals[0], SPI_tuptable->tupdesc,
1, &isnull); elog (NOTICE, "trigf(fired %s): there are %d tuples in ttest",
when, i);
When it should be:
pi = SPI_getbinval(SPI_tuptable->vals[0], SPI_tuptable->tupdesc,
1, &isnull); elog (NOTICE, "trigf(fired %s): there are %d tuples in ttest",
when, *pi);
mlw <markw@mohawksoft.com> writes:
> The docs suggest that this:
> /* Get number of tuples in relation */
> ret = SPI_exec("select count(*) from ttest", 0);
Mph. The example *used* to be right, but is not as of 7.2, because
count() now returns int8 which is pass-by-reference. Your proposed
fix isn't quite right either (you'd have noticed the difference between
*int and *int8 on a big-endian machine ;-)). Probably we should change
the example to read
i = (int) DatumGetInt64(SPI_getbinval(...));
Alternatively the example query could be changed to
ret = SPI_exec("select count(*)::int4 from ttest", 0);
so as to avoid the backend version dependency. Comments anyone?
regards, tom lane