Re: Is there public API to fetch errcode? - Mailing list pgsql-hackers

From Tom Lane
Subject Re: Is there public API to fetch errcode?
Date
Msg-id 30345.1760292202@sss.pgh.pa.us
Whole thread Raw
In response to Re: Is there public API to fetch errcode?  ("David G. Johnston" <david.g.johnston@gmail.com>)
Responses Re: Is there public API to fetch errcode?
List pgsql-hackers
"David G. Johnston" <david.g.johnston@gmail.com> writes:
> On Sun, Oct 12, 2025 at 1:27 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> PQresultErrorField(res, PG_DIAG_SQLSTATE) should do, no?

> I believe the call flow is the following - no "res"/result is ever
> constructed:

Hmm ... no, we do construct a PGresult containing the error (including
SQLSTATE), because pqGetErrorNotice3 is what's used to read the
server's error response.  But it looks like for a connection-time
failure, PQconnectPoll clears it before returning.

In principle maybe we could keep that around, allowing the application
to do PQgetResult from the failed connection object.  Seems like it'd
be a bit of a mess though.  Also, given all the logic that's there
to retry different server addresses etc, it's not clear which failure
result to preserve.  We sidestep that question so far as the textual
PQerrorMessage output is concerned by concatenating all the failures,
but that's not workable for PGresults.

            regards, tom lane



pgsql-hackers by date:

Previous
From: Alexander Lakhin
Date:
Subject: Re: Potential deadlock in pgaio_io_wait()
Next
From: Tom Lane
Date:
Subject: Re: Implementing IF NOT EXISTS clause for all CREATE TYPE variants