On Wed, May 16, 2012 at 10:47 AM, <me@evancarroll.com> wrote:
> The following bug has been logged on the website:
>
> Bug reference: 6645
> Logged by: Evna Carroll
> Email address: me@evancarroll.com
> PostgreSQL version: 9.1.2
> Operating system: Linux
> Description:
>
> This is a cross post from dba.stackexchange.com:
> http://dba.stackexchange.com/q/17998/2639
>
> The follow code used to work in Postgresql 8.4.11 with perl v5.10.1:
> CREATE OR REPLACE FUNCTION testfunction(OUT text) AS $$
> use URI;
> return URI->new('http://www.google.com/')->canonical;
> $$ LANGUAGE plperlu;
URI->canonical() returns some kind of blessed object, you can get it
to work by coercing the result to a string first:
CREATE OR REPLACE FUNCTION testfunction(OUT text) AS $$
use URI;
return URI->new('http://www.google.com/')->canonical().'';
$$ LANGUAGE plperlu;
We tightened this up over in:
commit 7c64c9f6b767b84597d69cfa2ae03d9a9655ec75
Author: Tom Lane <tgl@sss.pgh.pa.us>
Date: Thu Oct 13 18:02:43 2011 -0400
Fix up Perl-to-Postgres datatype conversions in pl/perl.
This patch restores the pre-9.1 behavior that pl/perl functions returning
VOID ignore the result value of their last Perl statement. 9.1.0
unintentionally threw an error if the last statement returned a reference,
as reported by Amit Khandekar.
[...snip...]
In addition, ensure we throw errors for attempts to return arrays or hashes
when the function's declared result type is not an array or composite type,
respectively. Pre-9.1 versions rather uselessly returned strings like
ARRAY(0x221a9a0) or HASH(0x221aa90), while 9.1.0 threw an error for the
hash case and returned a garbage value for the array case.
[...snip...]
As noted above if you return a reference you would get a mostly
useless string like "HASH(0x...)". Post commit above it now gives you
the error "ERROR: cannot convert Perl hash to non-composite type
text" instead. That seemed better at the time because its almost
always a mistake (with what you return or your declared return type).
That being said it seems we failed to take any magic (aka string
overloads) that a blessed reference might have. Ill see about
submitting a patch for 9.3 (9.2 just entered beta). Anyone have any
thoughts on if we should backpatch a fix?