title: Return rows matching elements of input array in plpgsql function
body: <p>I would like to create a PostgreSQL function that does something like the following:</p>
  
  <pre><code>CREATE FUNCTION avg_purchases( IN last_names text[] DEFAULT '{}' )
    RETURNS TABLE(last_name text[], avg_purchase_size double precision)
  AS
  $BODY$
  DECLARE
    qry text;
  BEGIN
  qry := 'SELECT last_name, AVG(purchase_size) 
            FROM purchases
            WHERE last_name = ANY($1)
            GROUP BY last_name'
  RETURN QUERY EXECUTE qry USING last_names;
  END;
  $BODY$
  </code></pre>
  
  <p>But I see two problems here:</p>
  
  <ol>
  <li>It is not clear to me that array type is the most useful type of input.</li>
  <li><p>This is currently returning zero rows when I do:</p>
  
  <pre><code>SELECT avg_purchases($${'Brown','Smith','Jones'}$$);
  </code></pre></li>
  </ol>
  
  <p>What am I missing?</p>