Hi, I am the author of a PostgreSQL C++ client library, taoPQ (https://github.com/taocpp/taopq), wrapping the C-API of libpq.
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 ); 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 * lo_* (large object functions) Obviously, I can take the error message from PQerrorMessage and throw a generic runtime error - but it would be so much nicer if I could use the SQLSTATE to throw the correct exception class and give users more information just like I do for PGresult*. After some research, it appears that PGconn* does have a field called last_sqlstate - it just can't be accessed. Are there any problems adding a simple accessor to libpq? Or is there some way to access it that I'm missing? Regards, Daniel