Accessing array elements in a FOR PL/pgsql loop - Mailing list pgsql-general

From Igor Katson
Subject Accessing array elements in a FOR PL/pgsql loop
Date
Msg-id 499D3633.2030702@gmail.com
Whole thread Raw
Responses Re: Accessing array elements in a FOR PL/pgsql loop  ("A. Kretschmer" <andreas.kretschmer@schollglas.com>)
List pgsql-general
For each element in the array, I need to make some operation with plpgsql.
I usually use the syntax:

DECLARE
  array_len int;
BEGIN
  array_len := array_upper(i_array, 1);
  FOR i IN 1 .. array_len
  LOOP
     SOME OPERATION (i_array[i])
  END LOOP;

But I don't like that. Is there any built-in way to do that without
using the length, i.e like in python, e.g.
  for element in array:
    ....
This example does not work in Postgres.

I think I need a built-in function to make a column from an array, like
in the backwards operation SELECT ARRAY(column)

pgsql-general by date:

Previous
From: Thomas Kellerer
Date:
Subject: Re: postgres wish list
Next
From: Scott Marlowe
Date:
Subject: Re: When adding millions of rows at once, getting out of disk space errors