proposal - plpgsql - FOR over unbound cursor

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: proposal - plpgsql - FOR over unbound cursor
Date: 2020-05-18 15:33:07
Message-ID: CAFj8pRDQKG-9C4R2yCpthrgFje9aiocahASJJCu6wb-jnuEWkQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi

Last week I played with dbms_sql extension and some patterns of usage
cursor in PL/SQL and PL/pgSQL. I found fact, so iteration over cursor (FOR
statement) doesn't support unbound cursors. I think so this limit is not
necessary. This statement can open portal for bound cursor or can iterate
over before opened portal. When portal was opened inside FOR statement,
then it is closed inside this statement.

Implementation is simple, usage is simple too:

CREATE OR REPLACE FUNCTION public.forc02()
RETURNS void
LANGUAGE plpgsql
AS $function$
declare
c refcursor;
r record;
begin
open c for select * from generate_series(1,20) g(v);

for r in c
loop
raise notice 'cycle body one %', r.v;
exit when r.v >= 6;
end loop;

for r in c
loop
raise notice 'cycle body two %', r.v;
end loop;

close c;
end
$function$

Comments, notes?

Regards

Pavel

Attachment Content-Type Size
plpgsql-for-over-unbound-cursor.patch text/x-patch 6.5 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Bruce Momjian 2020-05-18 15:39:34 Re: factorial function/phase out postfix operators?
Previous Message Paul Guo 2020-05-18 15:12:32 Re: Two fsync related performance issues?