0

I've started using PQsetSingleRowMode to be able to have more control over the data as it is streaming after PQsendQueryParams. You need to call PQgetResult a lot more, but is it as a matter of fact guaranteed that you'll get a single record each time, and thus PQntuples returns 1?

I'm asking because I'm not sure if it's 100% safe to drop the code that checks for PQntuples and loops that many times. Also I would not mind if it were greater than 1. Or if there were a separate “fire hose mode” where you get any records that have been fully transferred over the network since the previous PQgetresult...

Laurenz Albe
  • 209,280
  • 17
  • 206
  • 263
Stijn Sanders
  • 35,982
  • 11
  • 45
  • 67

1 Answers1

1

In single row mode PQgetResult will always produce a result with at most one row. Be aware that the last PGresult * returned will be empty.

If you want the result set in chunks of more than a single row, you'd have to use cursors and FETCH.

Laurenz Albe
  • 209,280
  • 17
  • 206
  • 263
  • 1
    It's not that I _want_ my result sets be of a certain number, I would like to get _any_ records that have been transmitted since the last call rightaway. But I guess `PQgetResult` of the next row will return immediately if it's transmitted already, so I'm pleased you confirm I don't need to loop over `PGntuples` with `PQsetSingleRowMode` as it's going to be either 1 or 0. – Stijn Sanders May 18 '19 at 14:22