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?
---
Sergey