postgresql - Postgres : More verbose error message: I am missing the table name

标签 postgresql

我看到这条消息:

IntegrityError: null value in column "date" violates not-null constraint
DETAIL:  Failing row contains (10005, null, f, TEST, MAIL).

有没有办法从 PostgreSQL 获取更详细的错误消息?

我缺少表名。

最佳答案

psql 可以使用 VERBOSITY 选项做到这一点:

psql (9.6.1)
Type "help" for help.

postgres> \set VERBOSITY verbose
postgres> insert into foobar (data) values ('x');
ERROR:  23502: null value in column "id" violates not-null constraint
DETAIL:  Failing row contains (null, x).
SCHEMA NAME:  public
TABLE NAME:  foobar
COLUMN NAME:  id
LOCATION:  ExecConstraints, execMain.c:1732
postgres>

这是在 9.6 中引入的。但是,我不知道其他客户端如何使用它。

或者,这可以在不设置 VERBOSITY 的情况下通过使用元命令 \errverbose

获得
postgres> insert into foobar (data) values ('x');
ERROR:  null value in column "id" violates not-null constraint
DETAIL:  Failing row contains (null, x).

postgres> \errverbose
ERROR:  23502: null value in column "id" violates not-null constraint
DETAIL:  Failing row contains (null, x).
SCHEMA NAME:  public
TABLE NAME:  foobar
COLUMN NAME:  id
LOCATION:  ExecConstraints, execMain.c:1732

postgres>

这显然是在 libpq 级别上实现的,因此理论上可以在任何程序中使用它。

关于postgresql - Postgres : More verbose error message: I am missing the table name,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41959752/

相关文章:

mysql - 如何将文件转换为带有外键的INSERT?

mysql - 如何处理意外的 MySQL 数据库引擎更改?

java - 在 postgresql (spring) 中设置默认模式

postgresql - 重复主键,无法访问 psql 控制台

sql - 如果值为null则Postgresql忽略过滤条件

json - 如何在 PostgreSQL 的 row_to_json 中获取列名作为 json 名称

node.js - 如何使用 jest 在 Node.js 中模拟 postgresql (pg)

postgresql - 如何在不知道日期格式的情况下将日期字符串转换为时间戳

postgresql - 使用 WSO2 DAS 的错误数据源 Postgres

ruby-on-rails - 如何处理 Postgresql 上的大量请求