如何获取Postgresql过程警告消息? [英] How to get Postgresql procedure warning messages?

查看:115
本文介绍了如何获取Postgresql过程警告消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在运行存储过程时,该过程会引发警告消息.

While running a stored procedure, the procedure can raise warning messages.

是否可以使用Postgresql驱动程序获取这些消息( https://github.com/lib/pq )在Golang中?

Is there any way to get these messages using Postgresql driver(https://github.com/lib/pq) in Golang ?

推荐答案

答案似乎是否定的.

在我的测试中,Postgres服务器似乎未发送带有结果的警告.即使这样做,返回错误以及sql.Result充其量也将造成混乱,并且需要进行lib/pq修改.在函数 did 中引发错误会返回错误,但(显然)没有结果.

In my tests the Postgres server did not appear to send the warning with the results. Even if it did, returning an error along with the sql.Result would be confusing at best and would require lib/pq modifications. Raising an error in the function did return an error, but (obviously) no result.

如果这是关键要求(并且您的功能可以支持它),则可以考虑使用通知渠道.请记住,这会将您的代码绑定到Postgres.

If this is a critical requirement (and your function can support it) you might consider using a notification channel. Bear in mind that this would tie your code to Postgres.

-

这是我使用的功能:

CREATE OR REPLACE function fugo() RETURNS bool as $$ BEGIN RAISE WARNING 'My function notice.' USING errcode = '01000'; return TRUE; END;$$ language 'plpgsql';

CREATE OR REPLACE function fugo() RETURNS bool as $$ BEGIN RAISE WARNING 'My function notice.' USING errcode = '01000'; return TRUE; END;$$ language 'plpgsql';

这篇关于如何获取Postgresql过程警告消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆