Why does the following code use 1.2GB of memory to execute? I was expecting memory usage to be relatively flat regardless of the number passed to generate_series, instead it is steadily increasing. Please - tell me I'm doing something wrong!
if (!PQsendQuery(conn, "select generate_series(1, 10000000)"))
exit(1);
int i, value;
while (res = PQgetResult(conn)) {
for (i = 0; i < PQntuples(res); i++) {
value = atoi(PQgetvalue(res, i, 0));
}
PQclear(res);
}
printf("%d\n", value);
PQfinish(conn);
I've put the full source code for this example on pastebin.