1.3. Command Execution Functions

Once a connection to a database server has been successfully established, the functions described here are used to perform SQL queries and commands.

1.3.1. Main Routines

The PGresult structure encapsulates the result returned by the backend. libpq application programmers should be careful to maintain the PGresult abstraction. Use the accessor functions below to get at the contents of PGresult. Avoid directly referencing the fields of the PGresult structure because they are subject to change in the future. (The definition of struct PGresult is not even provided in libpq-fe.h. If you have old code that accesses PGresult fields directly, you can keep using it by including libpq-int.h too, but you are encouraged to fix the code soon.)

1.3.2. Escaping strings for inclusion in SQL queries

PQ-escape-string escapes a string for use within an SQL query.

(PQescapeString from)

If you want to include strings that have been received from a source that is not trustworthy (for example, because a random user entered them), you cannot directly include them in SQL queries for security reasons. Instead, you have to quote special characters that are otherwise interpreted by the SQL parser.

PQ-escape-string performs this operation. The from points to the string that is to be escaped. A call to PQ-escape-string returns an escaped version of the from string to the to buffer, replacing special characters so that they cannot cause any harm. The single quotes that must surround PostgreSQL string literals are not part of the result string.

1.3.4. Retrieving SELECT Result Information

1.3.5. Retrieving SELECT Result Values

1.3.6. Retrieving Non-SELECT Result Information