Re: Is there public API to fetch errcode?

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Sergey Fukanchik <s(dot)fukanchik(at)postgrespro(dot)ru>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Is there public API to fetch errcode?
Date: 2025-10-12 17:37:06
Message-ID: CAKFQuwZ0twxnwfaMq-6ZuK3iPR9ny=YV=r8p8Dz08MGi7HPiuA@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Sun, Oct 12, 2025 at 1:27 PM Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:

> Sergey Fukanchik <s(dot)fukanchik(at)postgrespro(dot)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.

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Bram Hagens 2025-10-12 17:45:11 Implementing IF NOT EXISTS clause for all CREATE TYPE variants
Previous Message Tom Lane 2025-10-12 17:27:24 Re: Is there public API to fetch errcode?