> On 18. Sep 2021, at 01:45, David G. Johnston <david.g.johns...@gmail.com> 
> wrote:
> 
> 
> 
> On Friday, September 17, 2021, Daniel Frey <d.f...@gmx.de> wrote:
> 
> 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)
> 
> 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?
> 
> I suspect the reason for the omission is that there isn’t any usable data to 
> be gotten.  Those interfaces are not SQL interfaces and thus do not have a 
> relevant last_sqlstate to report.
> 
> David J.

Are you sure or are you guessing? It appears that for PQconnectdb there are a 
couple of SQLSTATES defined which could help users. The 08 Class "Connection 
Exception" contains at least 08001, 08004, 08P01 which could be helpful for 
users. For PGputCopyData, etc. Class 22 contains a lot of states that could 
explain what went wrong (in case it's the data), other states potentially also 
apply (like when the connection is lost, etc.). Even for large data it might me 
helpful to see states that indicate if the server ran out of disk space, etc.

Maybe not all of this is currently implemented (i.e. a reasonable SQLSTATE is 
stored in last_sqlstate), but I would hope that it is in some cases.

Daniel



Reply via email to