Python2打印postgresql存储过程引发通知 [英] Python2 print postgresql stored procedure raise notice
本文介绍了Python2打印postgresql存储过程引发通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在python脚本上打印postgres的存储过程?
How can I print postgres's stored procedure on python script?
postgres中的存储过程示例如下:
Example of stored procedure in postgres is as below:
create or replace function checktime() returns void
language plpgsql
as $$
DECLARE timestart TIMESTAMP;
FOR id from rt LOOP
SELECT timeofday() into timestart;
RAISE NOTICE 'Time now : %', timestart;
END LOOP;
END;
$$
;
在python中,我的脚本是:
From python, my script is:
import psycopg2
conn = psycopg2.connect(host="", database="",
user="", password="")
print("Database Connected")
cur = conn.cursor()
rowcount = cur.rowcount
cur.callproc('rt_visits_function_gz')
# how can i display the raise notice in here?
我想为每个循环在运行python时显示结果。
I would like for each loop the result is displayed when i run python.
谢谢
推荐答案
尝试使用通知
print(conn.notices)
print(conn.notices)
http://initd.org/psycopg/docs/connection.html?highlight=notice#connection.notices
这篇关于Python2打印postgresql存储过程引发通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文