Version 54 (modified by jtv, 13 years ago) (diff)


libpqxx is the official C++ API for writing client programs that talk to the PostgreSQL database management system. (If that's too verbose, call it by its shorter name, postgres).

For those who arrived at this page through that domain name may disappear at some point in the future. Please use instead, or bookmark this page.

2006-09-01: Mailing lists down

It seems that GBorg, the site hosting our mailing lists, is down. We have no idea what's happening, but for now it means that the mailing lists (apart from the packagers list) are not operating. Please be patient!

2006-08-31: Bug with binary arguments to prepared statements

Lumir Vanek has found a painful bug in the handling of binary (bytea) parameters to prepared statements: binary data passed in this way gets truncated at the first nul byte!

The 2.6.8 release, planned for Monday 2006-09-04, fixes this problem. It also includes new tests to ensure that the bug does not come back.

2006-07-09: Fixed Visual C++ Makefiles

It seems 2.6.7 still had some problems with its Visual C++ Makefiles. If you get build errors about files with names like "../src/*.cxx" not being found, download the new Makefile for Visual C++. If you want to build and run the test suite, you may need the new test makefile as well.

2006-06-18: New release

I've just uploaded libpqxx 2.6.7. This fixes several compilation problems, and completes the new interface for escaping strings and binary strings.

The new string-escaping functions are esc() and esc_raw() respectively, to be found in the transaction classes. They replace sqlesc() and escape_binary(), which were sensitive to an encoding bug in previous libpq versions.

If you use MinGW, the new version should fix the problem where the select() function wasn't found in any available socket library.

Finding Everything

Where What
Sales Pitch Why this library should interest you
Using This Site The various services offered by this development site
Download Page Source tarballs (no binaries; those depend on your individual platform)
FAQ Frequently Asked Questions, and their answers
Online Documentation Wiki and copies of packaged documentation
Packagers Page Information for maintainers of libpqxx packages
Bug Tracker Known bugs and requests (as in View Tickets option in top button bar)
Bugs by Milestone Bugs and feature requests, but ordered by milestone
Reporting Bugs How to report a problem or request a new feature
Mailing Lists libpqxx-general and libpqxx-announce (Still hosted on the old libpqxx site)
Other Projects Other open-source development projects hosted on
Old Site Old home page for libpqxx development (now used only for the mailing lists)
Author and Contributors Who made all this?

For issues not suitable for the mailing list or bug tickets, contact the author at

Also, you may want to have a look at the other open source projects hosted on this site.

Technical Overview

This library works on top of the C-level API library, libpq. You will need libpq in order to use libpqxx.

The first thing you're likely to notice in programming with libpqxx is that unlike other libraries, it revolves entirely around transactions. Transactions are a central concept in database management systems, but they are widely underappreciated among application developers. Another well-known open source database system, MySQL, never even got around to implementing them at all in their own engine, relying on a third-party replacement engine (now owned by Oracle) to provide this functionality instead.

It may sometimes be possible to build limited applications reliably without serious use of transactions. More usually, however, applications are designed without transactions simply because the developers aren't aware of the risks they are taking, and any data loss is rare or small enough not to be noticed. That kind of design was not considered acceptable for libpqxx.

With conventional database APIs, you issue commands and queries to a database session or connection, and optionally create the occasional transaction. In libpqxx you start a transaction inside the connection first, do your SQL work using that transaction, then commit the transaction when it's complete. There are several types of transactions with various "quality of service" properties; if you don't really want to use transactions at all, one of the available transaction types is called nontransaction. This transaction type provides classic, nontransactional behaviour.

Every command or query issues a result object, which is really a smart pointer so it can be copied around without incurring much cost in terms of performance. No need to write special code to check these for success; error conditions are converted to regular C++ exceptions. Result objects can be kept around for as long as they are needed, completely separate from the connections and transactions that originated them.

GTF Contributor