How do I resolve Postgresql error, "PL/Perl function must return reference to hash or array"? The follow code used to work in Postgresql 8.4.11 with perl v5.10.1:

=# select * From testfunction();
      testfunction      
------------------------
 http://www.google.com/


However, after doing a dump and load into Postgresql 9.1.3 with perl v5.14.2 I get:

ERROR:  PL/Perl function must return reference to hash or array
CONTEXT:  PL/Perl function "testfunction"


For reference, here is the function:

CREATE OR REPLACE FUNCTION testfunction(OUT text) AS $$
  use URI;
  return URI-&gt;new('http://www.google.com/')-&gt;canonical;
$$ LANGUAGE plperlu;


Again, the version of perl changed from v5.10.1 to v5.14.2; however, the return from Data::Peek is the same across both versions:

$ perl -MData::Peek -MURI -e'DPeek(
    URI-&gt;new(q[http://www.google.com])-&gt;canonical
);'


Output on both versions of perl:

\PVMG("http://www.google.com/"\0)
Short answer, coerce what you return to a string, should work fine in 8.4 and 9.1:

return URI-&gt;new('http://www.google.com/')-&gt;canonical().'';


See http://archives.postgresql.org/pgsql-bugs/2012-05/msg00096.php for my full response.