如何在Golang中获取Postgresql过程警告消息 [英] How do I get Postgresql procedure warning messages in Golang

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

问题描述



有没有办法使用Postgresql驱动程序来获取这些消息( https://github.com/lib/pq )在Golang?

解决方案

答案似乎为否。



在我的测试中,Postgres服务器似乎没有将警告与结果一起发送。即使这样做,与sql.Result一起返回一个错误最多也会造成混淆,并且需要 lib / pq 修改。如果这是一个关键需求(和你的函数),那么在函数中产生一个错误会返回一个错误,但是(显然)不会产生结果。 可以支持它),您可以考虑使用通知渠道。请记住,这会将您的代码绑定到Postgres。



-



以下是我使用的函数:
$ b

CREATE OR REPLACE函数fugo()
RETURNS bool as $$
BEGIN
RAISE WARNING'我的函数声明'USING errcode ='01000';
返回TRUE;
END; $$
语言'plpgsql';


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

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

解决方案

The answer appears to be no.

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.

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.

--

Here is the function I used:

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

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

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