Re: Is there public API to fetch errcode? - Mailing list pgsql-hackers

From Tom Lane
Subject Re: Is there public API to fetch errcode?
Date
Msg-id 50916.1760299759@sss.pgh.pa.us
Whole thread Raw
In response to Re: Is there public API to fetch errcode?  (Sergey Fukanchik <s.fukanchik@postgrespro.ru>)
Responses Re: Is there public API to fetch errcode?
List pgsql-hackers
Sergey Fukanchik <s.fukanchik@postgrespro.ru> writes:
> sqlstate is saved into conn->last_sqlstate along with the error message 
> in pqGetErrorNotice3:
>          if (id == PG_DIAG_SQLSTATE)
>              strlcpy(conn->last_sqlstate, workBuf.data,
>                      sizeof(conn->last_sqlstate));
> is this usable? Can it be extracted somehow?

It is not exposed, and if it were you'd have the same problem of lack
of context: you don't know which connection attempt set the value,
nor whether that's the most interesting failure.

If we wanted to up our game in this area, I'd envision making it
possible to extract a PGresult or PGresult-like structure for each
connection attempt that libpq made.  It'd need to carry the connection
details (server address, encryption options, etc) as well as the
failure info.  Not a trivial project, but doubtless do-able if
someone cared to put in the effort.

Of course, that just begs the question of what an application
would do with this data if it had it.

            regards, tom lane



pgsql-hackers by date:

Previous
From: Sergey Fukanchik
Date:
Subject: Re: Is there public API to fetch errcode?
Next
From: Peter Smith
Date:
Subject: Re: [PROPOSAL] Termination of Background Workers for ALTER/DROP DATABASE