title: Return type for function with array_agg()
body: <p>I'm trying to create a function that returns an array of strings, I'm able to do it without a function and returns a <code>record[]</code> type, when I try to return that type of result in the function it says that is not supported.</p>
  <pre><code>CREATE OR REPLACE FUNCTION alarmEventList(sampleid integer
                            , starttime timestamp without time zone
                            , stoptime timestamp without time zone)
    RETURNS text[] AS
  $$
  DECLARE
      result record[];
  BEGIN
      select array_agg(result)
      from (select to_char(&quot;Timestamp&quot;, 'YYYY-MM-DD HH24:MI:SS'), &quot;AlertLevel&quot;
                 , &quot;Timestamp&quot; - lag(&quot;Timestamp&quot;) over (order by &quot;Timestamp&quot;)
              from &quot;Judgements&quot;
            WHERE &quot;SampleID&quot;=sampleid and &quot;Timestamp&quot; &gt;= starttime
            and &quot;Timestamp&quot; &lt;= stoptime) as result where &quot;AlertLevel&quot; &gt;0;
      return result;
  END
  $$
  </code></pre>
  <p>Definition of table <code>Judgements</code>:</p>
  <pre><code>ID      | SampleID | AlertLevel | Timestamp               
  integer | integer  | integer    | timestamp with time zone
     1    |    11    |    1       | 2013-09-17 10:36:40
     2    |    11    |    0       | 2013-09-17 10:36:45
     3    |    11    |    2       | 2013-09-17 10:36:51
  </code></pre>
  <p>I was thinking to return a <code>text[]</code> but I don't find the way to make this query a text type or string.</p>
  <p>I want to return something like this:</p>
  <pre><code>{&quot;2013-11-21 10:36:40, 1, 10&quot;, &quot;etc...etc...&quot;}
  </code></pre>