本文是小编为大家收集整理的关于Python2打印postgresql存储过程引发的通知的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。
问题描述
如何在Python脚本上打印Postgres的存储过程?
Postgres中存储过程的示例如下:
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,我的脚本是:
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时会显示结果.
谢谢
推荐答案
尝试使用'Notices'
打印(conn.notices)
问题描述
How can I print postgres's stored procedure on python script?
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; $$ ;
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?
I would like for each loop the result is displayed when i run python.
Thank you
推荐答案
Try using 'notices'
print(conn.notices)
http://initd.org/psycopg/docs/connection.html?highlight=notice#connection.notices
相关标签/搜索
怎么用代码把png图片转化为esp
vs2010 如何检查内存
ubuntu 可以安装的聊天工具
linux主机sn怎么查
java 生成32位随机数
必须使用Xcode的Storyboard搭建启动页
林子雨网站用户行为分析
cubeIDE printf重定向
为什么sklearn包里没有交叉验证
ibmx3650m4 u盘启动
轮播插件jquery.SuperSlide.2.1
php ci 微信支付h5
regex
vim
python-2.7
printing
python-3.x
java
multithreading
python
postgresql
stored-procedures