Create a simple C++ program that connects to a PostgreSQL database, reads data from a table, and calculates the average value of a specified numeric column. The program should accept command line arguments for the database connection details (host, port, user, password) and the name of the table and column to be processed.
PLAINFORMAT
#include <iostream>
#include <pqxx/pqxx>

int main(int argc, char *argv[]) {
    if (argc != 7) {
        std::cerr << "Usage: " << argv[0] << " host port user password table column" << std::endl;
        return 1;
    }

    const std::string host = argv[1];
    const int port = std::stoi(argv[2]);
    const std::string user = argv[3];
    const std::string password = argv[4];
    const std::string table = argv[5];
    const std::string column = argv[6];

    try {
        pqxx::connection conn("host=" + host + " port=" + std::to_string(port) +
                              " user=" + user + " password=" + password);

        pqxx::work txn(conn);
        pqxx::result res = txn.exec("SELECT AVG(" + txn.quote_name(column) + ") FROM " + txn.quote_name(table));

        double average = res[0][0].as<double>();
        std::cout << "Average value of column '" << column << "' in table '" << table << "': " << average << std::endl;

        txn.commit();
    } catch (const std::exception &e) {
        std::cerr << "Error: " << e.what() << std::endl;
        return 1;
    }

    return 0;
}