You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jun 19, 2026. It is now read-only.
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.
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
PQnfieldsfunction to get the number of columns returned, and thenPQfnameto extract the name associated with the column.In addition
libpqprovidesPQntupleswhich 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 toPQftype.