我看到这条消息:
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/