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

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Benoît Dufour <benoit(dot)dufour(at)mail(dot)com>
Cc: "pgsql-hackers(at)lists(dot)postgresql(dot)org" <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: [Feature request] Add a way to get the length of a PQerrorMessage in libpq
Date: 2025-08-14 16:24:33
Message-ID: 204959.1755188673@sss.pgh.pa.us
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

=?UTF-8?Q?Beno=C3=AEt_Dufour?= <benoit(dot)dufour(at)mail(dot)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

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Geoghegan 2025-08-14 16:56:21 Re: index prefetching
Previous Message Benoît Dufour 2025-08-14 16:14:17 Re: [Feature request] Add a way to get the length of a PQerrorMessage in libpq