Thread: can't get async mode to deliver small batches of rows

can't get async mode to deliver small batches of rows

From
Mark Harrison
Date:
I can't seem to get PG into non-blocking mode.  Here is the result
I'm getting from the code attached below.  I'm expecting to get
multiple "PQntuples=" lines, but instead I'm getting just one
with all 14M records.  I've tried putting this into a cursor
as well, but still no joy...

any clues for the clueless?

Thanks!
Mark


PQstatus=0 CONNECTION_OK=0
rc,PQsetnonblocking=0
PQisnonblocking=1
rc,PQsendQuery=1
PQresultStatus=2 PGRES_TUPLES_OK=2
PQntuples=14345041


     conn = PQconnectdb("dbname = mh");
     printf("PQstatus=%d CONNECTION_OK=%d\n", PQstatus(conn), CONNECTION_OK);

     rc = PQsetnonblocking(conn, 1);
     printf("rc,PQsetnonblocking=%d\n", rc);
     printf("PQisnonblocking=%d\n", PQisnonblocking(conn));

     rc =PQsendQuery(conn, "select * from big");
     printf("rc,PQsendQuery=%d\n", rc);

     while ((res = PQgetResult(conn)) != NULL) {

         printf("PQresultStatus=%d PGRES_TUPLES_OK=%d\n", PQresultStatus(res), PGRES_TUPLES_OK);
         printf("PQntuples=%d\n", PQntuples(res));
         PQclear(res);
     }

     PQfinish(conn);

--
Mark Harrison
Pixar Animation Studios

Re: can't get async mode to deliver small batches of rows

From
Tom Lane
Date:
Mark Harrison <mh@pixar.com> writes:
> I can't seem to get PG into non-blocking mode.

"Non-blocking" does not mean "will deliver an incomplete result".
It just means you can get control back while waiting for the complete
result (though not with the code you show...)

You probably want to think about creating a cursor and FETCHing
a few rows per query.

            regards, tom lane