PQregisterResult(3)
π PQregisterResult(3) π
okay bestie, welcome to the libpqtypes Manual β¨ this one's PQregisterResult and she's lowkey the β¨efficientβ¨ one of the type-registration girlies.
πΈ NAME πΈ
PQregisterResult β registers sub-classes, composites and user-defined types found within a PGresult. π«Ά
β¨ SYNOPSIS β¨
#include <libpqtypes.h>
int PQregisterResult(PGconn *conn, int which, PGregisterType *types,
int count, PGresult *res);
π DESCRIPTION π
so like. PQregisterResult() registers the types it finds inside a given PGresult, and the way it does that is by not talking to the server at all, because the result data is literally already right there. no network. no round trip. she's self-sufficient, she's giving independent queen energy π
the which argument can be PQT_COMPOSITE or PQT_USERDEFINED, but not PQT_SUBCLASS. and the only reason for that is, like, sub-classes don't talk to the server, so they don't have a result set. no result set = nothing for this function to chew on. that's it, that's the whole tea β
the types argument is an array holding count types to register. and bestie, it has to be identical to whatever you handed to the originating PQregisterTypes call. like, the same array. don't get creative with it. π
the res argument is a PGresult, normally one you got by calling PQregisterTypes and then PQgetResult. but plot twist β you can roll your own result using PQmakeEmptyPGresult, PQsetResultAttrs, PQsetvalue, and then call this function. it's just a lil risky, because the result set generated by type lookup queries is internal and subject to change. so like, you've been warned, girlie π
π EXAMPLES π
π Using PQregisterResult π
this example registers two composite types asynchronously. and side note that's worth flagging: the PGresult you get from PQgetResult can be cached by your application and reused when creating new connections β which is the whole trick for avoiding repeatedly performing type lookups with the server. caching icon behavior, honestly. β¨
PGregisterType comp_types[] = {
{"myschema.simple", NULL, NULL},
{"complex", NULL, NULL}
};
/* asynchronous registration */
if (PQregisterTypes(conn, PQT_COMPOSITE, comp_types, 2, 1))
{
/* example of a typical event loop */
for(;;)
{
int n;
fd_set set;
int fd = PQsocket(conn);
struct timeval tv = {0, 500000};
FD_ZERO(&set);
FD_SET(fd, &set);
n = select(fd + 1, &set, NULL, NULL, &tv); //or kqueue,epoll,poll,etc..
if (n == -1)
{
//error
}
else if (n == 0)
{
//timeout, do other work ....
}
else
{
PGresult *res;
PQconsumeInput(conn);
if(!PQisBusy(conn))
{
/* done */
if(!(res = PQgetResult(conn)))
break;
n = PQregisterResult(conn, PQT_COMPOSITE, comp_types, 2, res);
/* This could also be cached and reused with PQregisterResult */
PQclear(res);
if (!n)
//error, consult PQgeterror()
}
}
}
}
β RETURN VALUE β
win = a non-zero value comes back π. lose = zero comes back, and PQgeterror(3) will be holding an error message for you. go read it, bestie, she's trying to tell you something π
π EXAMPLES π
None.
(yeah. that's the whole section. she said nothing and left. iconic of her honestly π )
π AUTHOR π
a contribution of eSilo, LLC. for the PostgreSQL Database Management System. written by Andrew Chernow. π«Ά
π¦ REPORTING BUGS π¦
report bugs to <libpqtypes@esilo.com>. don't be shy, they wanna hear it fr fr π
πΈ COPYRIGHT πΈ
Copyright (c) 2011 eSilo, LLC. All rights reserved.
this is free software; see the source for copying conditions. and like, there is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. no cap, zero warranty, none, nada π
π SEE ALSO π
and that's the page, bestie!! π go forth and register those types!! this was libpqtypes, version dated 2011 β stay slay, stay async, and always cache your results πβ¨π
π¦ where this page comes from
- debian bookworm: libpqtypes-dev 1.5.1-9
- ubuntu jammy: libpqtypes-dev 1.5.1-7
- ubuntu noble: libpqtypes-dev 1.5.1-9.1build1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms