Reduce bothering notices in plpgsql

淺唱寂寞╮ 提交于 2019-12-11 02:05:18

问题


I have a function which uses temporary table, that must be dropped if exists.

drop table if exists t_xy;
create temp table t_xy on commit drop as select ...;

Subsequently I use this function in a view. The function is called many times while select is in progress. I like to use "raise notice" command because it is almost the only reliable way to report any variables in functions for debug purposes. The problem is I must search for them in huge amount of unwanted lines like:

NOTICE:  table "t_xy" does not exist, skipping
CONTEXT:  SQL statement "drop table if exists t_xy"
PL/pgSQL function f_pending_operations(uuid) line5 in SQL command

Is there a way to suppress such notices that haven't been generated by raise notice command, but by drop table if exists or dropping other objects? Setting 'client_min_messages' option to 'debug' makes the problem worse.


回答1:


You can silence notices to the client from any command with a local setting for client_min_messages:

SET LOCAL client_min_messages=warning;  -- "debug" would have opposite effect
DROP TABLE if exists t_xy;
RESET client_min_messages=warning;  -- may or may not be needed

Per documentation:

The effects of SET LOCAL last only till the end of the current transaction

If you don't issue RESET you effectively silence notices for the rest of the transaction.

Alternatively, you can also set client_min_messages per call from the command line:

  • How to suppress INFO messages when running psql scripts


来源:https://stackoverflow.com/questions/27588613/reduce-bothering-notices-in-plpgsql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!