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

From Sergey Fukanchik
Subject Re: Is there public API to fetch errcode?
Date
Msg-id 9fca92c3-eb3d-46fd-ad3b-4b2d37c7d2dd@postgrespro.ru
Whole thread Raw
In response to Re: Is there public API to fetch errcode?  (Tom Lane <tgl@sss.pgh.pa.us>)
List 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




pgsql-hackers by date:

Previous
From: Peter Smith
Date:
Subject: Re: [PROPOSAL] Termination of Background Workers for ALTER/DROP DATABASE
Next
From: Thomas Munro
Date:
Subject: Re: IO in wrong state on riscv64