psql can do that using the VERBOSITY option:
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>
This was introduced in 9.6. However, I don't know how this can be used from other clients.
Alternatively this can be obtained without setting VERBOSITY by using the meta command \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>
This is apparently implemented on libpq level so it could theoretically be used from any program.