postgresql_16:5.1.3.3 Retrieving Other Result Information
PostgreSQL 16 > Client Interfaces > libpq — C Library > Command Execution Functions > Retrieving Other Result Information
These functions are used to extract other information from PGresult objects.
PQcmdStatus
Returns the command status tag from the SQL command that generated the PGresult. char *PQcmdStatus(PGresult *res);
Commonly this is just the name of the command, but it might include additional data such as the number of rows processed. The caller should not free the result directly. It will be freed when the associated PGresult handle is passed to (see libpq-PQclear).
PQcmdTuples
Returns the number of rows affected by the SQL command. char *PQcmdTuples(PGresult *res);
This function returns a string containing the number of rows affected by the SQL statement that generated the PGresult. This function can only be used following the execution of a SELECT, CREATE TABLE AS, INSERT, UPDATE, DELETE, MERGE, MOVE, FETCH, or COPY statement, or an EXECUTE of a prepared query that contains an INSERT, UPDATE, DELETE, or MERGE statement. If the command that generated the PGresult was anything else, (see libpq-PQcmdTuples) returns an empty string. The caller should not free the return value directly. It will be freed when the associated PGresult handle is passed to (see libpq-PQclear).
PQoidValue
Returns the OID of the inserted row, if the SQL command was an INSERT that inserted exactly one row into a table that has OIDs, or a EXECUTE of a prepared query containing a suitable INSERT statement. Otherwise, this function returns InvalidOid. This function will also return InvalidOid if the table affected by the INSERT statement does not contain OIDs. Oid PQoidValue(const PGresult *res);
PQoidStatus
This function is deprecated in favor of (see libpq-PQoidValue) and is not thread-safe. It returns a string with the OID of the inserted row, while (see libpq-PQoidValue) returns the OID value. char *PQoidStatus(const PGresult *res);