Untrusted Perl

We discussed untrusted PL/PythonU in Chapter 8, Using Unrestricted Languages. PL/Perl is also available as an untrusted language. The trusted version runs inside a security context that does not allow interaction with the environment. Just like PL/Pythonu, we can bypass the security restrictions using PL/Perlu or the untrusted version. Let's rewrite the directory listing function list_folder from Chapter 8, Listing directory contents to a Perl equivalent:

CREATE OR REPLACE FUNCTION list_folder_plperl(directory VARCHAR) RETURNS SETOF TEXT AS $$ my $d = shift; opendir(D, "$d") || elog (ERROR,'Cant open directory '.$d) ; my @list = readdir(D); closedir(D); foreach my $f (@list) { return_next($f); } return undef; $$ LANGUAGE plperlu; ...

Get PostgreSQL Server Programming - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.