can you use libraries in PL/Perl

2019-02-21 21:53发布

I'm just curious if when writing PL/Perl functions if I can have a use My::Lib; statement, or enable pragma's and features (e.g. 'use strict; use feature 'switch';).

2条回答
Rolldiameter
2楼-- · 2019-02-21 22:24

Not when using PL/Perl. It restricts the use of require and use, so you cannot import modules. However, you can install PL/Perlu (for unrestricted mode) which allows you to load modules.

plperlu can be considered a security risk, however, as it also allows filesystem commands such as open.

查看更多
Evening l夕情丶
3楼-- · 2019-02-21 22:45

For security purposes you cannot run a use/require statement within a function under plperl, but you can under plperlu.

IF you want to use modules in a secure way, you can add plperl.on_init = 'require "myperlinit.pl";' to the postgresql.conf file, then create a perl script called myperlinit.pl in the data directory which contains your uses. This will require a restart of the database server and these modules are available to all of your functions.

If you want strict mode turned on, you can plperl.use_strict = true will add it.

Note: this script is executed once per connection when the first perl function is called, and not when the connection is created.

查看更多
登录 后发表回答