Updated on 2025-03-13 GMT+08:00

PQexec

Description

Commits a command to the server and waits for the result.

Prototype

PGresult* PQexec(PGconn* conn, const char* query);

Parameters

Table 1 PQexec parameters

Keyword

Description

conn

Object pointer that contains the connection information.

query

Query string to be executed.

Return Values

PGresult indicates the object pointer that contains the query result.

Precautions

The PQresultStatus function should be called to check the return value for any errors (including the value of a null pointer, in which PGRES_FATAL_ERROR will be returned). The PQerrorMessage function can be called to obtain more information about such errors.

The command string can contain multiple SQL commands separated by semicolons (;). Multiple queries sent in a PQexec call are processed in one transaction, unless there are specific BEGIN/COMMIT commands in the query string to divide the string into multiple transactions. Note that the returned PGresult structure describes only the result of the last command executed from the string. If a command fails, the string processing stops and the returned PGresult describes the error condition.

Examples

For details, see Typical Application Development Examples.