Re: Access last_sqlstate from libpq - Mailing list pgsql-hackers

From Tom Lane
Subject Re: Access last_sqlstate from libpq
Date
Msg-id 1421674.1631932178@sss.pgh.pa.us
Whole thread Raw
In response to Access last_sqlstate from libpq  (Daniel Frey <d.frey@gmx.de>)
List pgsql-hackers
Daniel Frey <d.frey@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



pgsql-hackers by date:

Previous
From: Michael Paquier
Date:
Subject: Re: improve pg_receivewal code
Next
From: Neil Chen
Date:
Subject: Re: psql: \dl+ to list large objects privileges