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: Is there public API to fetch errcode?
Date: 2025-10-12 16:04:40
Message-ID: 125437e5-25c8-49ad-99af-8de04b77daf6@postgrespro.ru
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi Postgres hackers,
ereport() can accept an error code. For example:
            ereport(FATAL,
                    (errcode(ERRCODE_TOO_MANY_CONNECTIONS),
                     errmsg("number of requested standby connections
exceeds \"max_wal_senders\" (currently %d)",
                            max_wal_senders)));

In this case the error happens during connection initialization, outside
of an SQL query. I.e. PGresult is not available.

I suspect that the error code is available on the client as
PGconn->last_sqlstate however it is private and I can't find any public
API to fetch it.

Does libpq have an API to extract this code?

---

Sergey

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2025-10-12 17:24:37 Re: Add LZ4 compression in pg_dump
Previous Message Arseniy Mukhin 2025-10-12 14:55:39 Re: Finalizing read stream users' flag choices