Postgres:更详细的错误消息:我缺少表名

gue*_*tli 2 postgresql

我看到这条消息:

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

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

我缺少表名。

a_h*_*ame 6

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>
Run Code Online (Sandbox Code Playgroud)

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

或者,这可以VERBOSITY通过使用 meta 命令无需设置即可获得\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>
Run Code Online (Sandbox Code Playgroud)

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