Обсуждение: [Feature request] Add a way to get the length of a PQerrorMessage in libpq
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.
=?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
Re: [Feature request] Add a way to get the length of a PQerrorMessage in libpq
От
Benoît Dufour
Дата:
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 : > =?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
=?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