in reply to plperl (postgreSQL perl) get url function

>  import LWP::Simple;

I'd say substitute import with use

Make sure that get is exported by default by LWP::Simple , otherwise add it to the imported list. ( Update it is exported by default)

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

Replies are listed 'Best First'.
Re^2: plperl (postgreSQL perl) get url function
by marchello (Novice) on May 27, 2019 at 22:24 UTC
    Thanks Rolf, though it does not work for me. I tried
    use LWP::Simple;
    but then I can't even compile my function, it returns error:
    ERROR: Unable to load LWP/Simple.pm into plperl at line 4. BEGIN failed--compilation aborted at line 4. CONTEXT: compilation of PL/Perl function "get"
    Please advise.

      see Trusted and Untrusted PL/Perl

      I was able to get this to work using plperlu after running CREATE EXTENSION plperlu;

      CREATE OR REPLACE FUNCTION get(character varying) RETURNS json AS $BODY$ use warnings; use strict; use LWP::Simple; my $content = get($_[0]); $content =~ s/ /%20/g; return $content; $BODY$ LANGUAGE plperlu VOLATILE COST 100;
      poj
      > ERROR: Unable to load LWP/Simple.pm into plperl at line 4.

      • make sure that LWP::Simple is available on that server
      • elaborate this libs path
      • try warn "@INC"; to see if it's already included
      • otherwise add use lib "PATH"; before trying to load LWP::Simple

      see lib for details

      I've never worked with such postgres exetensions, probably they have been deliberately disabled by your server's admin.

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

        Looks like plperl extension does not allow all this stuff like LWP::Simple. Though plperlu (perl unrestricted) extension would allow it, but it is not available in Amazon RDS. Thanks for help anyway.