plpython does not honour max-rows - Mailing list pgsql-bugs

From Kieran McCusker
Subject plpython does not honour max-rows
Date
Msg-id CAGgUQ6H6qYScctOhktQ9HLFDDoafBKHyUgJbZ6q_dOApnzNTXg@mail.gmail.com
Whole thread Raw
Responses Re: plpython does not honour max-rows  (Daniel Gustafsson <daniel@yesql.se>)
List pgsql-bugs
Hi

I came across this when developing a sampling function using plpy.execute that needs to be able to sample zero rows. What actually happens is that zero is ignored for max-rows and all rows are returned. Test case below:-

Many thanks

Kieran

drop table if exists _test_max_rows;
create table _test_max_rows (i integer);
insert into _test_max_rows
select *
from generate_series(1, 100);

create or replace function plpython3u_execute_max_row(max_rows integer)
returns setof integer
language plpython3u
as $$
 for row in plpy.execute('select * from _test_max_rows', max_rows):
   yield row['i']
$$;
-- Correctly returns 10 rows
select * from plpython3u_execute_max_row(10);

-- Incorrectly returns all 100 rows
select * from plpython3u_execute_max_row(0)

pgsql-bugs by date:

Previous
From: Tobias Bussmann
Date:
Subject: Re: pg_basebackup: errors on macOS on directories with ".DS_Store" files
Next
From: Daniel Gustafsson
Date:
Subject: Re: pg_basebackup: errors on macOS on directories with ".DS_Store" files