To answer my own question, I adapted How to use pqxx::stateless_cursor class from libpqxx? try { work W(*Conn); pqxx::stateless_cursor<pqxx::cursor_base::read_only, pqxx::cursor_base::owned> cursor(W, sql[sqlLoad], "mycursor", false); /* Assume you know total number of records returned */ for (size_t idx = 0; idx < countRecords; idx += 100000) { /* Fetch 100,000 records at a time */ result r = cursor.retrieve(idx, idx + 100000); for (int rownum = 0; rownum < r.size(); ++rownum) { const result::tuple row = r[rownum]; vid1 = row[0].as<int>(); vid2 = row[1].as<int>(); vid3 = row[2].as<int>(); ............. } } } catch (const std::exception &e) { std::cerr << e.what() << std::endl; } -- View this message in context: http://postgresql.1045698.n5.nabble.com/C-Postgres-libpqxx-huge-query-tp5802330p5802392.html Sent from the PostgreSQL - general mailing list archive at Nabble.com. -- Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general