[Feature request] Add a way to get the length of a PQerrorMessage in libpq

Started by Benoît Dufour7 months ago4 messages
Jump to latest
#1Benoît Dufour
benoit.dufour@mail.com

Hello hackers,

I've been using PostgreSQL for about one year, and so far I like it a
lot, way more than MySQL or MariaDB, but I still have a little feature
request for libpq.

Could you add a way to get the size of an error message in libpq?

PQerrorMessage isn't enough when you want to do exact size string
concatenation or copy of the error message.

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Benoît Dufour (#1)
Re: [Feature request] Add a way to get the length of a PQerrorMessage in libpq

=?UTF-8?Q?Beno=C3=AEt_Dufour?= <benoit.dufour@mail.com> writes:

Could you add a way to get the size of an error message in libpq?

What's wrong with applying strlen() to the result of PQerrorMessage?

regards, tom lane

#3Benoît Dufour
benoit.dufour@mail.com
In reply to: Tom Lane (#2)
Re: [Feature request] Add a way to get the length of a PQerrorMessage in libpq

It recalculates the strlen of the error message.

This is a bad behaviour for softwares that need to execute quickly.

The length of the error message should just be stored in a size_t
variable while the error message is generated instead and not recalculated.

Le 14/08/2025 à 11:53, Tom Lane a écrit :

Show quoted text

=?UTF-8?Q?Beno=C3=AEt_Dufour?= <benoit.dufour@mail.com> writes:

Could you add a way to get the size of an error message in libpq?

What's wrong with applying strlen() to the result of PQerrorMessage?

regards, tom lane

#4Tom Lane
tgl@sss.pgh.pa.us
In reply to: Benoît Dufour (#3)
Re: [Feature request] Add a way to get the length of a PQerrorMessage in libpq

=?UTF-8?Q?Beno=C3=AEt_Dufour?= <benoit.dufour@mail.com> writes:

It recalculates the strlen of the error message.
This is a bad behaviour for softwares that need to execute quickly.

If you're concerned about the cost of a strlen() in an error-handling
path, you've got your priorities wrong. Not having gotten an error
in the first place is always going to be preferable. Moreover, the
cost of that strlen() is utterly negligible in comparison to the work
the server did to detect and report the error (to say nothing of
possible network transmission costs).

regards, tom lane