title: Record returned from function has columns concatenated
body: <p>I have a table which stores account changes over time. I need to join that up with two other tables to create some records for a particular day, if those records don't already exist.</p>
  
  <p>To make things easier (I hope), I've encapsulated the query that returns the correct historical data into a function that takes in an account id, and the day.</p>
  
  <p>If I execute <code>"Select * account_servicetier_for_day(20424, '2014-08-12')"</code>, I get the expected result (all the data returned from the function in separate columns). If I use the function within another query, I get all the columns joined into one:</p>
  
  <pre><code>("2014-08-12 14:20:37",hollenbeck,691,12129,20424,69.95,"2Mb/1Mb 20GB Limit",2048,1024,20.000)
  </code></pre>
  
  <p>I'm using "PostgreSQL 9.2.4 on x86_64-slackware-linux-gnu, compiled by gcc (GCC) 4.7.1, 64-bit".</p>
  
  <p>Query:</p>
  
  <pre><code>Select
      '2014-08-12' As day, 0 As inbytes, 0 As outbytes, acct.username, acct.accountid, acct.userid,
      account_servicetier_for_day(acct.accountid, '2014-08-12')
  From account_tab acct
  Where acct.isdsl = 1
      And acct.dslservicetypeid Is Not Null
      And acct.accountid Not In (Select accountid From dailyaccounting_tab Where Day = '2014-08-12')
  Order By acct.username
  </code></pre>
  
  <p>Function:</p>
  
  <pre><code>CREATE OR REPLACE FUNCTION account_servicetier_for_day(_accountid integer, _day timestamp without time zone) RETURNS setof account_dsl_history_info AS
  $BODY$
  DECLARE _accountingrow record;
  BEGIN
    Return Query
    Select * From account_dsl_history_info
    Where accountid = _accountid And timestamp &lt;= _day + interval '1 day - 1 millisecond'
    Order By timestamp Desc 
    Limit 1;
  END;
  $BODY$ LANGUAGE plpgsql;
  </code></pre>