Hi Postgres hackers,
ereport() can accept an error code. For example:
             ereport(FATAL,
                     (errcode(ERRCODE_TOO_MANY_CONNECTIONS),
                      errmsg("number of requested standby connections 
exceeds \"max_wal_senders\" (currently %d)",
                             max_wal_senders)));
In this case the error happens during connection initialization, outside 
of an SQL query. I.e. PGresult is not available.
I suspect that the error code is available on the client as 
PGconn->last_sqlstate however it is private and I can't find any public 
API to fetch it.
Does libpq have an API to extract this code?
---
Sergey