Исходный код СУБД RuDB — свободной СУБД с открытым исходным кодом на базе PostgreSQL
rudb
3 days ago bd039d1e92813358c5c5a1e346b49074baf513f2
src/pl/plpython/sql/plpython_setof.sql
@@ -107,3 +107,20 @@
SELECT get_user_records2();
SELECT * FROM get_user_records2();
-- Test partial execution of a set-returning function
SELECT get_user_records2() LIMIT 2;
SELECT * FROM get_user_records2() LIMIT 2;
-- A set-returning function that is invalidated mid-iteration must run to
-- completion using its original definition (bug #19480).
CREATE OR REPLACE FUNCTION self_invalidating_srf(x int) RETURNS SETOF int AS $$
for i in range(3):
    if i == 1:
        plpy.execute("CREATE OR REPLACE FUNCTION self_invalidating_srf(x int) "
                     "RETURNS SETOF int LANGUAGE plpython3u AS 'return [-1]'")
    yield x + i
$$ LANGUAGE plpython3u;
SELECT self_invalidating_srf(10); -- expect 10,11,12 (original definition)
SELECT self_invalidating_srf(10); -- expect -1 (replacement now in effect)