Loop through slices of 2-dimensional array in plpgsql function?
A FOR loop over array_upper(_fields,1) like you found is a simple and good option.

Even simpler for your case (for Postgres 9.1 or later): FOREACH with SLICE. The manual:


  With a positive SLICE value, FOREACH iterates through slices of the
  array rather than single elements.


Your function could look like this:

CREATE OR REPLACE FUNCTION public.mj_rubbish(_fields text[])
   RETURNS void AS
$func$
DECLARE
   m text[];
BEGIN
   FOREACH m SLICE 1 IN ARRAY _fields
   LOOP
      RAISE NOTICE '% EXECUTING fieldname: %, stats: %', now()::text, m[1], m[2];
   END LOOP;
END
$func$  LANGUAGE plpgsql;


This also works regardless of actual array indices - which do no have to start with 1 (but do by default).

Related:


Loop over array dimension in plpgsql
Step through multiple arrays in parallel with FOREACH
Normalize array subscripts for 1-dimensional array so they start with 1