Thread: SRF_RETURN_NEXT Error: rows returned by function are not all of the same row type

Hi ALL,

I need little help, in writing C function returns multiple row. (please find attached c code: show_eudc.c)

I have created table & inserted values in "temp"  as: 

create table temp(id int, value varchar);
insert into temp select x, lpad('string', 10, x::text) from generate_series(1, 10) x;

Just want to return few rows  SELECT * FROM temp using C function;

While  setting funcctx->max_calls = 1 work as expected;  

postgres=# select * from show_eudc();
NOTICE:  call_cntr : 0
 f1 |     f2
----+------------
  1 | 1111string
(1 row)

but setting funcctx->max_calls = 2;(or 4) throws error.

NOTICE:  call_cntr : 0
NOTICE:  call_cntr : 1
ERROR:  rows returned by function are not all of the same row type

I am not getting cause of error, as it working for single call, but why not for multiple call?

Do i missing something?

Thanks in Advance 


P.S. more info:

Loaded C function as:

CREATE OR REPLACE FUNCTION show_eudc(OUT f1 integer, OUT f2 varchar)
RETURNS SETOF record
AS 'MODULE_PATHNAME', 'show_eudc'
LANGUAGE C IMMUTABLE STRICT;


Regards,
Amul Sul
Attachment

Hi, Finally I fixed it :)

It has issue in sub-sequence call, it looses the result store in values[]   @line 84 .
thats why, it successfully return only single row in first call and fails in further call.

It can be fix by preserving results (i.e. values[]).

Thank you !

Regards,
Amul Sul