title: How to loop through string[] in postgresql?
body: <p>In this postgressql function i created a array by spliting a string. Now i want loop on this array and do some processing on it.</p>
  
  <p>Function:</p>
  
  <pre><code>CREATE OR REPLACE FUNCTION getAllFoo() RETURNS character varying as
  $BODY$
  DECLARE
     arr_split_data text[];
     counter character varying;
  begin
  
      counter := ''; -- Init value
  
      -- split data. Add in array
      select into arr_split_data regexp_split_to_array('a,b,c,d,e,f',',');
  
      FOR r IN arr_split_data -- error
      LOOP
           counter := arr_split_data[r] || '_' || counter; -- do some processing
      END LOOP;
  
    return counter;
  END
  $BODY$
  LANGUAGE 'plpgsql';
  </code></pre>
  
  <p>But I am getting this error</p>
  
  <p><img src="https://i.stack.imgur.com/cy3hm.png" alt="error "> </p>
  
  <p>when I execute this function. Is my syntax for loop is wrong?</p>