Re: array iteration? - Mailing list pgsql-general

From Tom Lane
Subject Re: array iteration?
Date
Msg-id 28367.1069612015@sss.pgh.pa.us
Whole thread Raw
In response to Re: array iteration?  (Ben <bench@silentmedia.com>)
Responses Re: array iteration?
List pgsql-general
Ben <bench@silentmedia.com> writes:
> On Sat, 2003-11-22 at 12:44, CSN wrote:
>> Is it possible to iterate over an array in plpgsql?

> Yep.
> http://archives.postgresql.org/pgsql-general/2003-11/msg00852.php

The cited example is pretty iffy since it assumes that the valid array
entries are all > 0.  In recent PG version you can use the array_upper
and array_lower functions instead:

    for i in array_lower(a,1) .. array_upper(a,1) loop
        -- do something with a[i]
    end loop;

            regards, tom lane

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: Invalid page header in block xxxx
Next
From: Tino Wildenhain
Date:
Subject: Re: retrieve statement from catalogs