libpq

The libpq library is a C language API that provides access to the PostgreSQL back end. In fact, most of the provided client tools (like psql) use this library as their connection route to the back end.

The libpq provides many functions that can control nearly every aspect of the client/server. Although an in-depth discussion of every function is outside the scope of this chapter, the two most popular functions it provides are as follows:

  • PQconnectdb. Connects to a database.

  • PQexec. Sends and executes a query to the back end.

PQconnectdb also provides the following functions:

  • PQreset. Resets client/server communication.

  • PQfinish. Closes the database connection.

PQconnectdb and PQexec are both discussed in more detail in the following sections. ...

Get PostgreSQL Essential Reference now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.