doujiu8479
2017-02-06 14:22
浏览 44

我如何在Golang中获取Postgresql过程警告消息

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 ?

图片转代码服务由CSDN问答提供 功能建议

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

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

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dpl74687 2017-02-07 00:12
    已采纳

    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';

    打赏 评论

相关推荐 更多相似问题