Andrey Sychev <andrey.sychev@cifrasoft.com> writes:
> I have written C-language function that returns
> multiple composite rows.
> Generally function works as expected, but sometimes problem takes place.
> At rough guess the problem occurs when number of returning rows
> relatively large (more than 100K - 1M).
I do not think it's valid to return from your function with the SPI
context still open. Probably, it seems to accidentally sort of work
as long as you don't return enough rows to cause the outer query to
do anything interesting like spill to disk.
Probably you should re-code this to execute just once and return
a tuplestore.
regards, tom lane