Search code examples
postgresqllibpqlibpqxx

Get libpq runtime version (from libpqxx)


In the libpqxx reference I can read sometimes stuff that is limited to the underlying libpq version ("Requires libpq version from PostgreSQL 7.4 or better. ") like here.

Now the question(s): (1) How to obtain the libpq version used in the current program (using libpqxx)? (2) As far as I found out, libpqxx not necessarily need to be recompiled when moving forward to a new libpq release. Replacing the old libpq.dll covers (often) new technologies, like ssl compression in my case. That is why I am thinking the libpq version shall be received on runtime.


Solution

  • The libpq version is available at runtime since 9.1 through PQlibVersion:

    int PQlibVersion(void);

    The result of this function can be used to determine, at run time, if specific functionality is available in the currently loaded version of libpq. The function can be used, for example, to determine which connection options are available for PQconnectdb or if the hex bytea output added in PostgreSQL 9.0 is supported.

    The number is formed by converting the major, minor, and revision numbers into two-decimal-digit numbers and appending them together. For example, version 9.1 will be returned as 90100, and version 9.1.2 will be returned as 90102 (leading zeroes are not shown).

    libpqxx does not seem to encapsulate this functionality, so we have to cut through it to get directly at libpq.