-
Notifications
You must be signed in to change notification settings - Fork 23
Description
It is often useful to have schema information for a fetch. That is for clients which allow the user or developer to enter arbitrary queries (to then reflect on results, e.g. to show them in a table w/ a proper column name header).
libpq provides this using the PQnfields
function to get the number of columns returned, and then PQfname
to extract the name associated with the column.
In addition libpq
provides PQntuples
which has the number of rows being returned in advance. That is also very useful (e.g. the preallocate result data structures with the proper size before fetching into them).
It's been a while since I looked at the raw protocol, but I all this information is readily available in the query response and doesn't require fetching all records.
https://www.postgresql.org/docs/11/libpq-exec.html#LIBPQ-EXEC-SELECT-INFO
The PostgresValue
, could also carry the actual PG OID type (maybe as a nice enum) similar to PQftype
.