proposal - plpgsql - FOR over unbound cursor - Mailing list pgsql-hackers

From Pavel Stehule
Subject proposal - plpgsql - FOR over unbound cursor
Date
Msg-id CAFj8pRDQKG-9C4R2yCpthrgFje9aiocahASJJCu6wb-jnuEWkQ@mail.gmail.com
Whole thread Raw
Responses Re: proposal - plpgsql - FOR over unbound cursor
Re: proposal - plpgsql - FOR over unbound cursor
List 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

pgsql-hackers by date:

Previous
From: Paul Guo
Date:
Subject: Re: Two fsync related performance issues?
Next
From: Bruce Momjian
Date:
Subject: Re: factorial function/phase out postfix operators?