title: Return a query from a function?
body: <p>I am using PostgreSQL 8.4 and I want to create a function that returns a query with many rows.<br>
  The following function does <strong>not</strong> work:</p>
  
  <pre><code>create function get_names(varchar) returns setof record AS $$
  declare
      tname alias for $1;
      res setof record;
  begin
      select * into res from mytable where name = tname;
      return res;
  end;
  $$ LANGUAGE plpgsql;
  </code></pre>
  
  <p>The type <code>record</code> only allows single row.</p>
  
  <p>How to return an entire query? I want to use functions as query templates.</p>