2017-10-05 45 views
0

有沒有辦法從PL/Python函數中訪問PostgreSQL函數?從PL/Python函數中訪問PostgreSQL函數

當我在PL/pgSQL中寫作時,我可以給他們打電話。例如,我可以在PL/pgSQL中編寫char_length('Bob'),並使用內置的PostgreSQL函數char_length。當我嘗試PL/Python時,char_length的錯誤是未定義的。有沒有可以訪問內置函數的名稱空間? plpy.functions.whatever或類似的東西?

我在PostgreSQL 9.5.9上使用plpython3u。

create or replace function py_test(str text) 
    returns int 
    language plpython3u 
as $$ 
    res = plpy.execute("select char_length('{}')".format(str)) 
    return res[0]["char_length"] 
$$; 

select py_test('abc'); 

py_test 
--------- 
     3 
(1 row) 

閱讀文檔:

回答