title: Returning set of rows from plpgsql function.
body: <p>I would like to return table from plpgsql function.</p>
  
  <p>Here is my code.</p>
  
  <pre><code>    CREATE FUNCTION test() RETURNS my_table AS
      $BODY$DECLARE
          q4 my_table;
      BEGIN
          q4 := SELECT * FROM my_table;
          RETURN q4;
      END;$BODY$
      LANGUAGE sql;
  </code></pre>
  
  <p>I am getting following error:</p>
  
  <pre><code>    Error: ERROR:  syntax error at or near "SELECT"
      LINE 5:  q4 := SELECT * FROM my_table;
  </code></pre>
  
  <p>I started from this questions/tutorials.
  <a href="https://dba.stackexchange.com/questions/35721/declare-variable-of-table-type-in-pl-pgsql">https://dba.stackexchange.com/questions/35721/declare-variable-of-table-type-in-pl-pgsql</a> &amp;&amp; 
  <a href="http://postgres.cz/wiki/PL/pgSQL_%28en%29" rel="nofollow noreferrer">http://postgres.cz/wiki/PL/pgSQL_%28en%29</a></p>
  
  <p>The idea is that I need to assign this query to a variable. This is only small part of function that I would like to create. </p>
  
  <p>The second problem will be how to iterate through that set and make some mathematical operations and assigning value to some field of that table.
  However firstly I would like to solve this problem. </p>