title: How to return multiple rows from PL/pgSQL function?
body: <p>I have spent good amount of time trying to figure it out and I haven't been able to resolve it. So, I need your help please.</p>
  
  <p>I am trying to write a PL/pgSQL function that returns multiple rows. The function I wrote is shown below. But it is not working.</p>
  
  <pre><code>CREATE OR REPLACE FUNCTION get_object_fields()
  RETURNS SETOF RECORD
  AS 
  $$
  DECLARE result_record keyMetrics;
  BEGIN
      return QUERY SELECT department_id into result_record.visits 
      from fact_department_daily 
      where report_date='2013-06-07';
      --return result_record;
  END
  
  $$ LANGUAGE plpgsql; 
  
  SELECT * FROM get_object_fields;
  </code></pre>
  
  <p>It is returning this error:</p>
  
  <blockquote>
    <p>ERROR:  RETURN cannot have a parameter in function returning set;<br>
    use RETURN NEXT at or near "QUERY"</p>
  </blockquote>