title: INSERT while LOOPing
body: <p>i'd like to insert some records into a table while looping. Records are passed as a varchar tab to a function ie.:</p>
  
  <pre><code>create function a(tab varchar[]) RETURNS void AS
  $$
  DECLARE 
    b varchar(20);
  BEGIN
    FOREACH b IN ARRAY tab
     LOOP
        INSERT INTO....;
     END LOOP;
    RETURN;
  END;
  $$
  LANGUAGE plpgsql;
  </code></pre>
  
  <p>However, when executing there is the error:</p>
  
  <pre><code>ERROR:  syntax error at or near "FOREACH"
  LINE 1: FOREACH  $1  IN ARRAY tab LOOP INSERT INTO x (c, ...
  QUERY:  FOREACH  $1  IN ARRAY tab LOOP INSERT INTO x (c) VALUES ( $1)
  CONTEXT:  SQL statement in PL/PgSQL function " near line ...
  
  ********** ERROR **********
  
  ERROR: syntax error at or near "FOREACH"
  </code></pre>
  
  <p>Does anybody know why and how to fix this?</p>