snippetsqlMinor
How can I load 'utf8' into plperl by default?
Viewed 0 times
plperlcanhowintoutf8defaultload
Problem
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
As detailed in the question above, the following stored procedure fails on the Solaris installation:
With the following error:
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:
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
And that successfully loads the
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
What is the secret to successfully loading
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, anSolution
The solution I found involes mimicing the
This successfully loads and initializes 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.Code Snippets
plperl.on_init = 'use utf8; use re; package utf8; require "utf8_heavy.pl";'Context
StackExchange Database Administrators Q#65268, answer score: 3
Revisions (0)
No revisions yet.