plpython does not honour max-rows

From: Kieran McCusker <kieran(dot)mccusker(at)gmail(dot)com>
To: pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: plpython does not honour max-rows
Date: 2023-05-02 10:30:16
Message-ID: CAGgUQ6H6qYScctOhktQ9HLFDDoafBKHyUgJbZ6q_dOApnzNTXg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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)

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Daniel Gustafsson 2023-05-02 10:34:59 Re: pg_basebackup: errors on macOS on directories with ".DS_Store" files
Previous Message Tobias Bussmann 2023-05-01 21:23:58 Re: pg_basebackup: errors on macOS on directories with ".DS_Store" files