在 psql 错误消息中获取 SQLSTATE

dez*_*zso 9 postgresql client psql errors

我有以下问题。

SELECT * FROM tgvbn();
ERROR:  function tgvbn() does not exist
LINE 1: SELECT * FROM tgvbn();
                      ^
HINT:  No function matches the given name and argument types. You might need to add explicit type casts.
Run Code Online (Sandbox Code Playgroud)

由于官方文档的附录 A只说明了 error_codes 和条件名称,而没有说明实际的消息,因此只能猜测“没有函数匹配...”指的是42883 / undefined_function. 我可以设置log_error_verbosity = verbosepostgresql.conf-但会影响日志,不返回到客户端中的消息:

控制在服务器日志中为记录的每条消息写入的详细信息量。

好吧,我可以查阅日志以获取这条信息,但是有没有办法将其包含在错误消息中?

dez*_*zso 10

根据 a_horse_with_no_name 的评论,我开始四处寻找psql并找到了解决方案:

\set VERBOSITY verbose
SELECT * FROM tgvbn();

ERROR:  42883: function vfjkb() does not exist
...
Run Code Online (Sandbox Code Playgroud)

现在进入.psqlrc. 详细信息和更多选项可以在psql 文档中找到。