如何获取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';