调用存储过程
下面的例子展示了如何调用存储过程:
sql_procedure = " CREATE OR REPLACE PROCEDURE pro_test(a integer,inout b integer) LANGUAGE plpgsql AS $procedure$
begin
b := a+b;
end
$procedure$;"
cur.execute(sql_procedure)
cur.execute("call pro_test(1,5)")
result = cur.fetchone()
下面的例子展示了如何调用函数:
sql_function = "CREATE OR REPLACE FUNCTION func_test (a int,out b int) RETURNS int AS
$body$
begin
b := a+2;
return ;
end;
$body$ LANGUAGE 'plpgsql';"
cur.execute(sql_function)
cur.execute("select func_test(1)")
result = cur.fetchone()