Re: libpq: PQfnumber overload for not null-terminated strings - Mailing list pgsql-hackers

From Ivan Trofimov
Subject Re: libpq: PQfnumber overload for not null-terminated strings
Date
Msg-id 0a5c227a-7dd5-6b8b-870b-c2867712659e@yandex.ru
Whole thread Raw
In response to Re: libpq: PQfnumber overload for not null-terminated strings  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: libpq: PQfnumber overload for not null-terminated strings
List pgsql-hackers
Thanks for the quick reply.

> If you need counted strings
> for PQfnumber, wouldn't you need them for every single other
> string-based API in libpq as well?

No, not really.

Thing is, out of all the functions listed in "34.3.2. Retrieving Query 
Result Information" and "34.3.3. Retrieving Other Result Information" 
PQfnumber is the only (well, technically also PQprint) one that takes a 
string as an input.

As far as I know PQfnumber is the only portable way to implement "give 
me the the value at this row with this 'column_name'", which is an 
essential feature for any kind of client-side parsing.
Right now as a library writer in a higher-level language I'm forced to 
either
* Sacrifice performance to ensure 'column_name' is null-terminated 
(that's what some bindings in Rust do)
* Sacrifice interface quality by requiring a null-terminated string, 
which is not necessary idiomatic (that's what we do)
* Sacrifice usability by requiring a user to guarantee that the 
'string_view' provided is null-terminated (that's what libpqxx does, for 
example)

I don't think it's _that_ big of a deal, but could it be QoL improvement 
nice enough to be worth of a tiny addition into libpq interface?



pgsql-hackers by date:

Previous
From: Jacob Champion
Date:
Subject: Re: Refactor SASL exchange in preparation for OAuth Bearer
Next
From: Matthias van de Meent
Date:
Subject: Re: Detoasting optionally to make Explain-Analyze less misleading