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

From David G. Johnston
Subject Re: Is there public API to fetch errcode?
Date
Msg-id CAKFQuwZ0twxnwfaMq-6ZuK3iPR9ny=YV=r8p8Dz08MGi7HPiuA@mail.gmail.com
Whole thread Raw
In response to Re: Is there public API to fetch errcode?  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: Is there public API to fetch errcode?
List pgsql-hackers
On Sun, Oct 12, 2025 at 1:27 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
Sergey Fukanchik <s.fukanchik@postgrespro.ru> writes:
> Does libpq have an API to extract this code?

PQresultErrorField(res, PG_DIAG_SQLSTATE) should do, no?


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

PGconn *PQconnectdb(const char *conninfo);
ConnStatusType PQstatus(const PGconn *conn);
// Connection_Bad
char *PQerrorMessage(const PGconn *conn);
// Obtains the error message; but there seems to be no equivalent of PQresultErrorField (e.g. PQconnErrorField) to obtain the SQLState field component thereof

David J.

pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: Is there public API to fetch errcode?
Next
From: Bram Hagens
Date:
Subject: Implementing IF NOT EXISTS clause for all CREATE TYPE variants