PQexecf(3)
β¨ PQexecf β¨
okay bestie, we're in the libpqtypes manual and today's main character is PQexecf β she prepares your params and executes your command, all in one go, no cap π
πΈ NAME πΈ
PQexecf β Prepares parameters and executes a command.
π SYNOPSIS π
#include <libpqtypes.h>
PGresult *PQexecf(const PGconn *conn, const char *cmd, ...);
PGresult *PQexecvf(const PGconn *conn, const char *cmd, va_list ap);
int PQsendf(const PGconn *conn, const char *cmd, ...);
int PQsendvf(const PGconn *conn, const char *cmd, va_list ap);
π¦ DESCRIPTION π¦
so the way that PQexecf() works is: it executes a command that uses libpqtypes type specifiers instead of the whole $1, $2, etc... syntax. the vibe is basically combining PQputvf() and PQparamExec() into a single call. β¨
your variable argument list has to match the type specs listed inside the cmd, fr fr. and the type specifiers go exactly where you'd normally put $1, $2, etc...
PQexecvf() is literally identical to PQexecf() except it takes a va_list. same girl, different entrance.
then we have PQsendf() and PQsendvf() β they're identical to PQexecf() and PQexecvf() except they're the asynchronous versions, meaning you have to make an additional call, PQgetResult, to actually get the PGresult object. no skipping steps bestie π for more info, see the PostgreSQL Documentation: specifically the "Asynchronous Command Processing" section under "Client Interfaces | libpq - C library".
also!! a prepared type spec "@name" can be used with these functions, as long as PQspecPrepare() was called with a non-zero value for the is_stmt argument. these functions need an actual SQL statement to execute, periodt.
π RETURN VALUE π
PQexecfandPQexecvfreturnNULLon error and a validPGresulton success πPQsendfandPQsendvfreturn zero on error and a non-zero value on success β¨
on error, use PQgeterror(3) to obtain an error message. she will tell you what went wrong, don't worry π«Ά
π EXAMPLES π
π Using PQexecf
this example uses the PQexecf function to execute a query.
/* The PQexecf call is shorthand for:
*
* PGparam *param = PQparamCreate(conn);
* PQputf(param, "%int4 %int4", 1, 1);
* res = PQparamExec(conn, param, "SELECT $1 + $2", 1);
* PQparamClear(param);
*
* As you may notice, PQexecf makes life much simpler.
*/
PGresult *res = PQexecf(conn, "SELECT %int4 + %int4", 1, 1);
if(!res)
fprintf(stderr, "PQexecf failed: %s", PQgeterror());
else
PQclear(res);
/* A bit more common, this puts an int4 and a text into a generated
* PGparam and then executes 'myfunc($1, $2)'
*/
res = PQexecf(conn, "SELECT * FROM myfunc(%int4, %text)", 2, "abc");
/* Prepared type spec example. To use with execf, the final "is_stmt"
* argument must be set to a non-zero value!
*/
PQspecPrepare(conn, "account_insert", "INSERT INTO account VALUES "
"(%int8, %text, %int4)", 1);
PGint8 acc_id = 78236;
PGtext acc_name = "ABC Coders, LLC.";
PGint4 acc_biz = ACC_BIZ_TECHNOLOGY;
PQexecf(conn, "@account_insert", acc_id, acc_name, acc_biz);
πΈ AUTHOR πΈ
a contribution of eSilo, LLC. for the PostgreSQL Database Management System. written by Andrew Chernow and Merlin Moncure. iconic duo behavior honestly π
π REPORTING BUGS π
report bugs to <libpqtypes@esilo.com>. they wanna hear it, bestie π«Ά
π COPYRIGHT π
Copyright (c) 2011 eSilo, LLC. All rights reserved.
this is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. so like... use her responsibly okay π
β SEE ALSO β
PQgeterror(3), PQputvf(3), PQparamExec(3)
libpqtypes Β· 2011 Β· and that's the whole PQexecf(3) page bestie β go forth and execute some commands, you absolute legend π
β¨π¦ππ
π¦ 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