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