title: PostgreSQL PL/pgSQL syntax error with FOREACH loop
body: <p>I'm trying to learn PL/pgSQL by writing some simple programs. To learn about FOREACH loop, I wrote the following: </p>
  
  <pre><code>CREATE OR REPLACE FUNCTION test(int[]) RETURNS void AS $$  
  DECLARE                                                     
      window INT;                                             
  BEGIN                                                       
      FOREACH window IN ARRAY $1                              
      LOOP                                                    
          EXECUTE 'SELECT $1' USING window;                   
      END LOOP;                                               
  $$ LANGUAGE plpgsql;                                        
  
  SELECT test(ARRAY [30,60]);    
  </code></pre>
  
  <p>I expect that this code snippet would first print <code>30</code> and then <code>60</code>. However, I get the following error. </p>
  
  <pre><code>psql:loop.sql:11: ERROR:  syntax error at end of input
  LINE 7:         EXECUTE 'SELECT $1' USING window;
                                                  ^
  psql:loop.sql:13: ERROR:  function test(integer[]) does not exist
  LINE 1: SELECT test(ARRAY [30,60]);
                 ^
  HINT:  No function matches the given name and argument types. You might need
   to add explicit type casts.
  </code></pre>
  
  <p>So the function definition has a syntax error, but I don't understand what the error is and how to fix it. I'd appreciate any help. Thanks! </p>