pllua / pllua-deprecated

[DEPRECATED] This repository is no longer maintained. Please follow https://github.com/pllua/pllua
197 stars 16 forks source link

SRF calls not correctly reset on rescan #65

Open RhodiumToad opened 6 years ago

RhodiumToad commented 6 years ago

Given this function:

create function tf2()
  returns setof integer
  language pllua
  as $f$
    for i = 1,4 do coroutine.yield(i) end
$f$;

This query:

select * from generate_series(1,3) i, lateral (select tf2() limit i) s;

gives this result

 i | tf2 
---+-----
 1 |   1
 2 |   2
 2 |   3
 3 |   4
(4 rows)

when it should give this result:

 i | tf2 
---+-----
 1 |   1
 2 |   1
 2 |   2
 3 |   1
 3 |   2
 3 |   3
(6 rows)

The problem is that the SRF call isn't being shut down on a rescan of the enclosing exprcontext, because it didn't register a callback to do so (the standard SRF_* utility macros do it, but pllua doesn't use these).