Cannot create perlplu function

From: Thangalin <thangalin(at)gmail(dot)com>
To: pgsql-novice(at)postgresql(dot)org
Subject: Cannot create perlplu function
Date: 2013-03-30 23:36:13
Message-ID: CAANrE7qqEPv7k7KjpYRp5Hft0tn8G3pq+sWOK4EH-T=zQoK=Pw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Hi, all.

Running PostgreSQL 9.1.8 on Xubuntu 12.04, installed from the repos.

From the shell, I have executed:

createlang plperl db_name;
createlang plperlu db_name;

As the superuser running `psql`, I have executed:

GRANT ALL ON LANGUAGE plperl TO account_name;
GRANT ALL ON LANGUAGE plperlu TO account_name;

The `pg_language` table reveals:

select lanname,lanpltrusted from pg_language where lanname like
'plperl%';

"plperl";t
"plperlu";t

When I create the following function:

CREATE OR REPLACE FUNCTION get_hostname()
RETURNS text AS
$BODY$
use Sys::Hostname;
return hostname;
$BODY$
LANGUAGE plperlu IMMUTABLE
COST 1;
ALTER FUNCTION get_hostname()
OWNER TO account_name;

I receive the following error:

ERROR: Unable to load Sys/Hostname.pm into plperl at line 2.
BEGIN failed--compilation aborted at line 2.
CONTEXT: compilation of PL/Perl function "get_hostname"

Yet the following works:

CREATE OR REPLACE FUNCTION get_hostname()
RETURNS text AS
$BODY$
return '127.0.0.1';
$BODY$
LANGUAGE plperlu IMMUTABLE
COST 1;
ALTER FUNCTION get_hostname()
OWNER TO account_name;

The following Perl script works as expected from the shell:

use Sys::Hostname;
print hostname;

I tried to run the function as an anonymous block:

DO $$
use Sys::Hostname;
print hostname;
$$ LANGUAGE plperlu;

This returned the same error as before, with this additional information:

ERROR: Unable to load Sys/Hostname.pm into plperl at line 3.
BEGIN failed--compilation aborted at line 3.
SQL state: 42601
Context: PL/Perl anonymous code block

From the [documentation][1], error 42601 is a syntax error.

I see no syntax error.

Furthermore, the function loaded fine with the superuser account when I
imported the database:

psql -d db_name -U account_name -W -f db-dump.sql > import.log 2>
error.log

I tried to simplify the code to no avail:

CREATE OR REPLACE FUNCTION get_hostname() RETURNS text AS
$$
use Sys::Hostname;
return hostname;
$$
LANGUAGE plperlu;

Same error as before.

What I don't understand is why, according to the error message, PostgreSQL
is trying to load the code into `plperl` instead of `plperlu`.

Any ideas?

[1]: http://www.postgresql.org/docs/9.1/static/errcodes-appendix.html

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Tom Lane 2013-03-31 03:16:38 Re: Cannot create perlplu function
Previous Message kobolds 2013-03-27 12:44:44 about .pgpass