Skip site navigation (1) Skip section navigation (2)

Peripheral Links

Header And Logo

PostgreSQL
| The world's most advanced open source database.

Site Navigation

Search for
  Advanced Search

Re: Loop plpgsql recordset


  • From: George Weaver <gweaver(at)shaw(dot)ca>
  • To: Furesz Peter <fureszpeter(at)srv(dot)hu>, postgres levlista <pgsql-general(at)postgresql(dot)org>
  • Subject: Re: Loop plpgsql recordset
  • Date: Fri, 26 Jan 2007 17:40:58 -0600
  • Message-id: <008e01c741a3$6ee34010$6400a8c0(at)Dell4500>

On Thursday, January 25 Furesz Peter 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;
 
Its difficult to determine what you're trying to accomplish in the loop, but you may want to refer to 37.7.4. Looping Through Query Results in http://www.postgresql.org/docs/8.2/interactive/plpgsql-control-structures.html#PLPGSQL-RECORDS-ITERATING
 
Note that DELETE FROM sulyozas_futamido; will delete ALL records in sulyozas_futamido!

Perhaps:
 
FOR v_tmp IN  SELECT * FROM sulyozas_futamido sf
    WHERE sf.termekfajta_id = a_termekfajta_id AND sf.marka_id=a_marka_id;

 LOOP
 
     DELETE FROM sulyozas_futamido WHERE (some condition related to v_tmp???)
 
    Work with old record now in v_tmp
      
END LOOP;
 
Regards,
George



Home | Main Index | Thread Index

Privacy Policy | PostgreSQL Archives hosted by Command Prompt, Inc. | Designed by tinysofa
Copyright © 1996 – 2008 PostgreSQL Global Development Group