2017-07-16 64 views

回答

3

plv8語言是可信的,因此無法從文件系統加載任何內容。但是,您可以從數據庫加載模塊。

創建一個包含模塊源代碼的表格並使用selecteval()加載它。一個簡單的例子來說明這個想法:

create table js_modules (
    name text primary key, 
    source text 
); 

insert into js_modules values 
('test', 'function test() { return "this is a test"; }'); 

負荷js_modules在功能模塊:

create or replace function my_function() 
returns text language plv8 as $$ 
// load module 'test' from the table js_modules 
    var res = plv8.execute("select source from js_modules where name = 'test'"); 
    eval(res[0].source); 
// now the function test() is defined 
    return test(); 
$$; 

select my_function(); 

CREATE FUNCTION 
    my_function 
---------------- 
this is a test 
(1 row) 

你可以找到一個優雅的require()功能在這個職位更復雜的例子:A Deep Dive into PL/v8.

0

我有兩個提示指向在NO方向:

  1. You can use PLV8 in Amazon RDS PosgreSQL。 RDS不允許任何不是可信的語言。由於PostgreSQL文檔中解釋說:

    可信

    TRUSTED指定的語言不授予訪問數據的用戶本來不會。

    如果PLV8可以使用庫,這些會(最有可能),允許進行操作,如通過HTTP下載數據,或者檢查文件系統,這將違反此限制(也可能是,把RDS系統的黑客攻擊風險)。

  2. 介紹PLV8 - The PostgreSQL web side通過Lucio Grenzi。

    幻燈片#10:

    PLV8:受信任的語言

        [...]

    • 沒有辦法從文件系統
    • 加載外部處理模塊

可能的替代方法

我已經使用了PLPERLuu意思不可信)語言。使用該語言,您可以使用use庫。您的庫應該位於PostgreSQL正在使用的PERL安裝的標準位置(如CREATE LANGUAGE所定義的那樣)。