Re: array iteration?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: bench(at)silentmedia(dot)com
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: array iteration?
Date: 2003-11-23 18:26:55
Message-ID: 28367.1069612015@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Ben <bench(at)silentmedia(dot)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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Gaetano Mendola 2003-11-23 19:33:12 Re: First generic/redhatish RPM's uploaded to ftp.postgresql.org.
Previous Message Tino Wildenhain 2003-11-23 18:19:05 Re: retrieve statement from catalogs