I have been trying to insert bulk data using copy from stdin but it isn't working. Can anyone tell me what I am doing wrong:
// Redirecting file input to stdin
std::ifstream in("infile.csv");
std::streambuf *cinbuf = std::cin.rdbuf(); // save old buffer
std::cin.rdbuf(in.rdbuf()); // redirect std::cin to in
std::string copyQuery("COPY tableName (col1,col2) FROM STDIN DELIMITER ',' CSV HEADER");
//Database connection
std::string conninfo("host=ip port=5432 dbname=tdb user=tdbuser password=tdbpsswd);
pqxx::connection conn(conninfo);
pqxx::work transaction(conn);
pqxx::result res = transaction.exec(copyQuery);
transaction.commit();
std::cin.rdbuf(cinbuf); // reset to standard input again
I don't find the data which I try to insert inside the table.