Re: Arrays in PL/PGSQL - Mailing list pgsql-general

From Jan Wieck
Subject Re: Arrays in PL/PGSQL
Date
Msg-id 200010231521.KAA01518@jupiter.jw.home
Whole thread Raw
In response to Arrays in PL/PGSQL  (oberpwd@anubis.network.com (Wade D. Oberpriller))
List pgsql-general
Wade D. Oberpriller wrote:
> Hello,
>
> Does PL/PGSQL support arrays? Or is their a mechanism to select a set of
> records from a table and iterate over all of them.
>
> For example:
>
> DECLARE recs AS RECORDS; //??
> BEGIN
> SELECT INTO recs * FROM mytable WHERE myfield = 'myvalue';
> for i in 1 .. NumRecs loop
>    ...
> end loop;
>
> Is there a way to do something like this??

    Do it with one record as:

        DECLARE rec record;
        BEGIN
        FOR rec IN SELECT * FROM mytable WHERE myfield = 'myvalue' LOOP
            ...
        END LOOP;

    And BTW, this syntax is documented in the user manual :-)


Jan

--

#======================================================================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me.                                  #
#================================================== JanWieck@Yahoo.com #



pgsql-general by date:

Previous
From: Jan Wieck
Date:
Subject: Re: Re: [HACKERS] My new job
Next
From: Jan Wieck
Date:
Subject: Re: Postgres Global Variables