title: Postgresql: Problem with selecting arrays in set-returning plpgsql function
body: <p>I am trying to select arrays in a set-returning function in postgres 8.4, but receiving
  the error: </p>
  
  <p><em>"array value must start with "{" or dimension information"</em>.</p>
  
  <p>This issue appears to relate to locationnodes.rs_people_c sometimes
  having an empty array. I've tried to get around that with a COALESCE statement. No luck.</p>
  
  <p><strong>function</strong>:</p>
  
  <pre><code>CREATE OR REPLACE FUNCTION fn_matview_location_slots (
      week_start  DATE
  ) RETURNS setof matview_location_slots_info AS
  $$
  DECLARE
      resulter    matview_location_slots_info%ROWTYPE;
  BEGIN
      FOR resulter IN
          SELECT
              rs_node               AS node,
              rs_date               AS dater,
              ...
              COALESCE(rs_people_c, '{}'::INTEGER[]) AS people,
              rs_location           AS location
          FROM
              locationnodes
          WHERE
              rs_date &gt;= week_start
      LOOP
          RETURN NEXT resulter;
      END LOOP;
  END; $$ LANGUAGE plpgsql;
  </code></pre>
  
  <p><strong>type</strong>:</p>
  
  <pre><code>CREATE TYPE matview_location_slots_info AS (
          node              VARCHAR,
          dater             DATE,
          ...
          people            INTEGER[],
          location          INTEGER[]
  );
  </code></pre>
  
  <p><strong>data</strong></p>
  
  <pre><code>select rs_people_c from locationnodes;
             rs_people_c
  -------------------------------------
   {}
   {}
   {731}
   {32}
   {31}
   {}
   {62}
   {540,72,69,53,37,42,201,51,58}
   {64}
  </code></pre>