3

I am attempting to solve a problem explained in another question here. On Debian 7.4 with Postgres 9.1.12, I am able to use the Perl qr operator just fine. On Solaris 5.11 with Postgres 9.2.4, however, I am not able to.

As detailed in the question above, the following stored procedure fails on the Solaris installation:

REATE FUNCTION foo(VARCHAR) RETURNS VARCHAR AS $$
    my ( $re ) = @_;
    $re = ''.qr/\b($re)\b/i;
    return $re;
$$ LANGUAGE plperl;

With the following error:

ERROR:  Unable to load utf8.pm into plperl at line 3.
BEGIN failed--compilation aborted.
CONTEXT:  PL/Perl function "foo"

It is apparent that in the Debian installation of Postgres, 'utf8' is already loaded by default. I ran the following stored procedure on both systems:

CREATE FUNCTION perl_modules() RETURNS VOID AS $$
    warn join(', ',sort keys %INC);
$$ LANGUAGE plperl;

On the Debian system:

WARNING: Carp.pm, Carp/Heavy.pm, Exporter.pm, feature.pm, overload.pm, strict.pm, unicore/Heavy.pl, unicore/To/Fold.pl, utf8.pm, utf8_heavy.pl, vars.pm, warnings.pm, warnings/register.pm at line 2.

On the Solaris system:

WARNING: Carp.pm, Carp/Heavy.pm, Exporter.pm, feature.pm, overload.pm, overloading.pm, strict.pm, vars.pm, warnings.pm, warnings/register.pm at line 2.

I tried to load the utf8 module on the Solaris system by adding this to the postgres config file:

plperl.on_init = 'use utf8; use re;'

And that successfully loads the utf8 and re modules, as shown here:

WARNING: Carp.pm, Carp/Heavy.pm, Exporter.pm, XSLoader.pm, feature.pm, overload.pm, overloading.pm, re.pm, strict.pm, utf8.pm, vars.pm, warnings.pm, warnings/register.pm at line 2.

However the foo() stored procedure still fails:

dc=# select foo('foo');
ERROR:  Attempt to reload utf8_heavy.pl aborted.
Compilation failed in require at /opt/perl-5.18.0/lib/utf8.pm line 17.
CONTEXT:  PL/Perl function "foo"

What is the secret to successfully loading utf8, and its dependencies, in this Solaris environment?

2 Answers 2

3

The solution I found involes mimicing the utf8 module's AUTOLOAD function in the plperl.on_init setting:

plperl.on_init = 'use utf8; use re; package utf8; require "utf8_heavy.pl";'

This successfully loads and initializes the utf8_heavy.pl file before dropping into Postgres's safe mode for running perl scripts.

0

Another method would be to create the function with plperlu.

This gives it access to use all the modules on the system.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.