在 postgres 中打印运行时消息 [英] Printing run time messages in postgres

查看:93
本文介绍了在 postgres 中打印运行时消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们可以在 postgres 中使用 RAISE NOTICE 等价于 SQL Server 中的 RAISERROR 'message to display' WITH NOWAIT,或者是否有在 postgres 查询运行时打印中间消息的更好方法?请建议是否有更好的方法在 postgres 中打印运行时消息.

Can we use RAISE NOTICE in postgres as equivalent of RAISERROR 'message to display' WITH NOWAIT in SQL Server, or is there a better way to print intermediate messages while postgres queries are running? Please suggest if there is better way to print run time messages in postgres.

INSERT INTO tbl1 (col1) values (val1);
DO $$
begin
raise notice 'insert tbl1 done!';
end;
$$;
UPDATE tbl2 set col2='val2' where ...;
DO $$
begin
raise notice 'update tbl2 done!';
end;
$$;

如果此代码太糟糕而无法发表评论,我深表歉意,请提出更好的方法,谢谢

I apologize if this code is too bad to comment, pls do suggest a better way to do it, Thanks

推荐答案

是的,您可以使用 RAISE NOTICE 如下所示.你这样做是正确的.

Yes, you can use RAISE NOTICE like below. It's correct the way you are doing.

RAISE NOTICE 'i want to print % and %', var1,var2;

请参阅此处了解更多信息 https://www.postgresql.org/docs/current/static/plpgsql-errors-and-messages.html

See here for more information https://www.postgresql.org/docs/current/static/plpgsql-errors-and-messages.html

begin
INSERT INTO tbl1 (col1) values (val1);
raise notice 'insert tbl1 done!';
end;

这篇关于在 postgres 中打印运行时消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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