PostgreSQL PL/Python 和 PL/Postgres 函數互相調用


create or replace function hello(name text)
    returns text
as $$
#    str = name+',你吃飯了嗎?';
#    return 'hello %s !' % str;
    return 'Hello %s!' % name
$$ language plpythonu;


create or replace function hello_invoker(name text)
    returns text
as $$
begin
    return public.hello('[plpgsql_invoker_prefix]' || name);
end;
$$ language plpgsql;

create or replace function hello_invoker_wrap(name text)
    returns text
as $$
    pyret = plpy.execute("select hello_invoker('" + name + "[python wrap suffix]') as ret")[0];
    return pyret['ret'];
$$ language plpythonu;

 

testdb=# select * from public.hello_invoker_wrap('吳xx');
                   hello_invoker_wrap                    
---------------------------------------------------------
 Hello [plpgsql_invoker_prefix]吳xx[python wrap suffix]!

 

plpy.execute返回的結果集為:

 <PLyResult status=5 nrows=1 rows=[{'ret': 'Hello [plpgsql_invoker_prefix]xxx[python wrap suffix]!'}]>
(1 行記錄)

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM