Thanks John for your answer. The problem is how do I declare the cursor and fetch through C++ and libpq++? And if I fetch 1000 rows at a time, then how do I handle that when I reach the end and there are less than 1000 rows available? Or I need to fetch one row at a time like this http://stackoverflow.com/questions/16128142/how-to-use-pqxxstateless-cursor-class-from-libpqxx?
I have to execute an SQL query to Postgres by the following code. The query returns a huge number of rows (40M or more) and has 4 integer fields: When I use a workstation with 32Gb everything works but on a 16Gb workstation the query is very slow (due to swapping I guess). Is there any way to tell the C++ to load rows at batches, without waiting the entire dataset? With Java I never had these issues before, due to the probably better JDBC driver.