title: RETURN QUERY-Record in PostgreSQL
body: <p>I am trying to write a PostgreSQL function that inserts data in the database and then receives some data and returns it.
  Here is the code:</p>
  
  <pre><code>CREATE OR REPLACE FUNCTION newTask(projectid api.objects.projectid%TYPE, predecessortaskid api.objects.predecessortaskid%TYPE, creatoruserid api.objects.creatoruserid%TYPE, title api.objects.title%TYPE, description api.objects.description%TYPE, deadline api.objects.deadline%TYPE, creationdate api.objects.creationdate%TYPE, issingletask api.tasks.issingletask%TYPE)
    RETURNS SETOF api.v_task AS
  $$
  DECLARE
      v_objectid api.objects.objectid%TYPE;
  BEGIN
     INSERT INTO api.objects(objectid, projectid, predecessortaskid, creatoruserid, title, description, deadline, creationdate) VALUES (DEFAULT, projectid, predecessortaskid, creatoruserid, title, description, deadline, creationdate)
     RETURNING objectid INTO v_objectid;
  
     INSERT INTO api.tasks(objectid, issingletask) VALUES (v_objectid, issingletask);
     RETURN QUERY (SELECT * FROM api.v_task WHERE objectid = v_objectid);
  END;
  $$ LANGUAGE plpgsql;
  </code></pre>
  
  <p><code>objects</code> and <code>tasks</code> are both tables and <code>v_task</code> is a view, which is a join of the two. The reason why I return data that I just inserted is that there are some triggers doing work on it.</p>
  
  <p>So far so good. I use <code>RETURNS SETOF api.v_task</code> as my return type and <code>RETURN QUERY (...)</code> and therefore expect the result to look like a <code>SELECT from v_task</code> (same columns with same data types). However, what really happens is (output from pgAdmin, same result from my <code>node.js-application</code>):</p>
  
  <pre><code>SELECT newTask( CAST(NULL AS integer), CAST(NULL AS integer), 1, varchar 'a',varchar 'a', cast(NOW() as timestamp(0) without time zone), cast(NOW() as timestamp(0) without time zone), true);
  
  newtask
  api.v_task
  --------
  "(27,,,1,a,a,"2012-03-19 12:15:50","2012-03-19 12:15:50","2012-03-19 12:15:49.629997",,t)"
  </code></pre>
  
  <p>Instead of several column the output is forced into one, separated by commas.<br>
  As I am already using a special record type I can't use the <code>AS</code> keyword to specify the fields of my output.</p>