Re: Is there public API to fetch errcode?

From: Sergey Fukanchik <s(dot)fukanchik(at)postgrespro(dot)ru>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Is there public API to fetch errcode?
Date: 2025-10-12 22:39:59
Message-ID: 9fca92c3-eb3d-46fd-ad3b-4b2d37c7d2dd@postgrespro.ru
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

So the difference between conn->errorMessage and conn->last_sqlstate is
that erorrMessage is appended and last_sqstate is overwritten.

And it seems that changing this is not easy.

As to why I want this - there are several reasons for connection to be
rejected, like ERRCODE_CANNOT_CONNECT_NOW, ERRCODE_TOO_MANY_CONNECTIONS,
ERRCODE_INSUFFICIENT_PRIVILEGE, ERRCODE_DATA_CORRUPTED etc

I would like my client to behave differently based on a particular
errcode - sometimes wait and retry, sometimes choose another server,
sometimes just fail.

It would be perfect if I could simply configure libpq to do such
reactions automatically for me, but designing this properly seems to be
even harder than exposing connection sqlstate.

SQLSTATE codes are locale independent and it would help a lot if I could
use them instead of relying on localized messages.

---

Sergey

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Thomas Munro 2025-10-12 22:44:57 Re: IO in wrong state on riscv64
Previous Message Peter Smith 2025-10-12 22:28:40 Re: [PROPOSAL] Termination of Background Workers for ALTER/DROP DATABASE