Re: loop plpgsql recordset variable - Mailing list pgsql-general

From Merlin Moncure
Subject Re: loop plpgsql recordset variable
Date
Msg-id b42b73150701251228w71856896p6edf6a78109244ad@mail.gmail.com
Whole thread Raw
In response to loop plpgsql recordset variable  ("Furesz Peter" <spam@srv.hu>)
List pgsql-general
On 1/25/07, Furesz Peter <spam@srv.hu> wrote:
> How can I loop a PL/PgSQL recorset variable? The example:
>
>     DECLARE
>         v_tmp_regi RECORD;
>         v_tmp RECORD;
>     BEGIN
>       SELECT * INTO v_tmp_regi FROM sulyozas_futamido sf WHERE
> sf.termekfajta_id=
>       a_termekfajta_id AND sf.marka_id=a_marka_id;
>
>         DELETE FROM sulyozas_futamido;
>
>         FOR v_tmp IN v_tmp_regi LOOP
>             --I would like to work here with the old recordset!
>         END LOOP;
>         ^^^^^^^^^^^^^^
>        -- This is not working !!!
>
>     END;

I think what you want to do is this:
     BEGIN
       SELECT * INTO v_tmp_regi FROM sulyozas_futamido sf WHERE
sf.termekfajta_id=
       a_termekfajta_id AND sf.marka_id=a_marka_id;

         DELETE FROM sulyozas_futamido;

         FOR v_temp_regi IN SELECT * FROM sulyozas_futamido sf WHERE
sf.termekfajta_id = a_termekfajta_id AND sf.marka_id=a_marka_id LOOP

         END LOOP;

         FOR v_tmp IN v_tmp_regi LOOP
             --I would like to work here with the old recordset!
         END LOOP;
         ^^^^^^^^^^^^^^

     END;

pgsql-general by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: replication choices
Next
From: Robert Boone
Date:
Subject: Postgresql best practices