Daniel Frey <d.f...@gmx.de> writes: > In case of an error when I received a PGresult*, I can access the SQLSTATE by > calling
> PGresult* pgresult = ...; > const char* sqlstate = PQresultErrorField( pgresult, PG_DIAG_SQLSTATE ); Right ... > However, this is not possible in a couple of other cases where I don't have a > PGresult*, only the PGconn* is available: > * PQconnectdb (and variants) > * PQputCopyData > * PQputCopyEnd > * PQgetCopyData In these cases, any error you might get is probably from libpq itself, not from the server. libpq does not generate SQLSTATEs for its errors, so it's likely that last_sqlstate is not relevant at all. (Getting libpq to assign SQLSTATEs to its errors has been on the to-do list for a couple of decades. I'm not holding my breath for somebody to undertake that.) > Are there any problems adding a simple accessor to libpq? I would be strongly against that unless somebody first did the legwork to ensure it was meaningful. regards, tom lane