How Do You Use C++ to Retrieve Data from a PostgreSQL Database on Ubuntu Linux?

Problem scenario:  You have C++ and Postgres installed on an Ubuntu Linux server.  How do you write C++ programs to retrieve data from Posgres databases?

Install the official C++ API for Postgresql.  These directions should work on any Debian distribution of Linux.

As root, do the following from the Linux command prompt:

apt-get -y install libpq-dev g++
cd /usr/bin/
curl > libpqxx-4.0.tar.gz
tar xvfz libpqxx-4.0.tar.gz
cd libpqxx-4.0
make install

To read more about the official API for C++ and PostgreSQL, see this GitHub link or the official site.

Leave a comment

Your email address will not be published. Required fields are marked *